Re: HP15C MiniChallenge: My Original Solution & Comments Message #34 Posted by Valentin Albillo on 28 Aug 2006, 6:40 p.m., in response to message #1 by Valentin Albillo
Hi all,
As always, I'm delighted with the extreme ingenuity displayed by the many excellent contributions posted, thanks a lot for your continued interest and appreciation. My original solution is the following 9step routine which fulfills all given requirements:
01 LBL A
02 2
03 /
04 ASINH
05 3
06 /
07 SINH
08 2
09 *
which needs no RTN instruction (as endofprogrammemory performs and implied RTN), but does need the label, else the routine wouldn't perform as stated in the given examples (GSB A, ...). Also, there's no need to include a SF 8 instruction to set complex mode, because the only way the routine can receive a complex A parameter as argument in the Xregister is for the calculator to already be in complex mode at entry.
This simple routine makes use of the fact that cubic equations of the given type, which are usually solved in closed form by a complicated radicalbased formula including cube roots and square roots, can also be computed using trigonometric functions, either of the usual circular variety (SIN, COS, ASIN, ACOS, ...) or the hyperbolic variety (SINH, COSH, ASINH, ACOSH, ...) depending on the argument.
Usually one or the other kind will be used in order to keep all computations within the domain of real numbers, but it isn't actually necessary if your model allows for complex arguments, because circular and hyperbolic trigonometrics are intimately related, the ones becoming the others when the arguments change from real to complex, and vice versa. Thus, sticking with just circular or just hyperbolic for all possible cases will do, provided you can deal with complex arguments.
In this case, the root x is given by the short expression:
x = 2 * Sinh(ArcSinh(A/2)/3)
which is valid for any given numeric value of A which is legal for the HP15C, from 9.999999999E99 to +9.999999999E99 in the real domain, and also for complex values of A. That's not the case when using radicalbased formulas, which might overflow/underflow, can make it difficult to select the adequate value among the three possible values for the two required cube roots if dealing with complex arguments, and may require storing and recalling complex values to and from registers, which is somewhat cumbersome in the HP15C.
That's also not the case for SOLVEbased routines, which can't deal with complex values of the A parameter, may take a long time to converge, and may fail to converge altogether. Besides, this trigonometric approach is much faster than either the radical or the SOLVEbased ones.
Let's try my original routine for a complex parameter, A = 1 + 2i:
1, ENTER, 2, I, GSB A > x = 0.4716050820 + 0.6060784194i
Let's check the result:
ENTER, ENTER, ENTER, *, 3, +, * > x = 1.000000000 + 2.000000000i
and you many see that it holds. This trigonometric approach can be extended to more general cubic equations, i.e.:
x^{3} + p*x + q = 0
where we have:
x = 2*Sqrt(p/3)*Cos(ArcCos(3*q/(2*p)*Sqrt(3/p))/3)
where the trigonometrics must be able to accept arbitrary values as arguments (i.e., greater than 1 for ArcCos, or even complex), or else you may reformulate it in terms of hyperbolics and keep everything real and in range. As an example, for the equation:
x^{3}  6*x  2 = 0
the above trigonometric formula quickly gives¨x = 2.601679132. This approach can also be extended to certain equations of higher degrees: even though the general 5^{th}degree equation (aka quintic) does require elliptic trigonometric functions, there are some families of 5^{th}degree equations which are amenable to this circular or hyperbolic trigonometric treatment, i.e. the quintic:
16*x^{5}  180*x^{3} + 405*x  136 = 0
has five real roots given by the trigonometric expression:
x = 3* Sin[1/5*(ArcASin(136/243) + 0*Pi, +2*Pi, +4*Pi)]
as seen in my article HP12C Tried & Tricky Trigonometrics, freely available online from my calculator web page.
Certainly, you'll agree with me that cubic equations having very simple closedform solutions in terms of hyperbolic functions (instead of the ungainly Cardano formulas featured everywhere, in particular for cubic equations having just one real root, where all arguments are real), is quite elegant and highly unexpected, and rarely taught anywhere.
Next time that someone asks you what hyperbolic functions are useful for, you can confidently reply: "to solve cubic equations easily and quickly" and let him/her utterly perplexed. :)
Best regards from V.
