Post Reply 
Mathematician Finds Easier Way to Solve Quadratic Equations
05-09-2024, 02:34 PM
Post: #61
RE: Mathematician Finds Easier Way to Solve Quadratic Equations
(05-08-2024 04:22 PM)Albert Chan Wrote:  I was comparing absolute value, going for the big root.
This is *exactly* the same as your cos/asin trig formula.
(05-04-2024 07:37 PM)Gerson W. Barbosa Wrote:  \(x_{1}=\left({\cos\left({\arcsin{\frac{\sqrt{q}}{-\frac{p}{2}}}}\right)+1}\right)\times-\frac{p}{2}\)

Replace cos(asin(z)) = √(1-z²), we have KISS version, only 1 square root!

Code:
00 { 28-Byte Prgm }
01▸LBL "Q"
02 X<> ST Z         ;   a   b   c
03 STO÷ ST Z        
04 STO+ ST X
05 +/-              
06 ÷                ;   m   q
07 ENTER            
08 X↑2              ; m^2   m   q
09 RCL- ST Z        ; m^2-q m   q
10 RCL÷ ST L
11 SQRT
12 RCL× ST Y        
13 +                ; x1    q
14 STO÷ ST Y        ; x1    x2
15 END

As you said, KISS is not simple.

Q(1,0,1) stops with a “Divide by 0” message (as does my program using COS/ASIN).
Both Q42S (24 bytes) and QFree42 (28 bytes) return the proper 0 ± i answer.
Find all posts by this user
Quote this message in a reply
05-10-2024, 05:11 PM (This post was last modified: 05-10-2024 08:04 PM by Albert Chan.)
Post: #62
RE: Mathematician Finds Easier Way to Solve Quadratic Equations
(05-09-2024 02:34 PM)Gerson W. Barbosa Wrote:  As you said, KISS is not simple.

Q(1,0,1) stops with a “Divide by 0” message (as does my program using COS/ASIN).

x^2 + p*x + q = 0
x = m ± √Δ                          // m = -p/2, Δ = m^2 - q

x1 = m + m * √(Δ/m^2)      // big root, m^2≠0

For Free42, SIGN(0) = 1, SIGN(0+0i) = (0+0i)
I needed a nice transition, SIGN(0+0i) = SIGN(0) = 1 too

s = SIGN(m), or 1 if |m|=0

x1 = m + s * √(Δ/s^2)        // big root, m=0 OK too

Code:
00 { 36-Byte Prgm }
01▸LBL "Q"
02 X<> ST Z         ;   a   b   c         
03 STO÷ ST Z        
04 STO+ ST X 
05 +/-              
06 ÷                ;   m   q
07 ENTER            
08 ABS              ;  |m|  m   q
09 X≠0?             
10 X<> ST L         
11 SIGN             ;   s   m   q    
12 RCL ST Y         
13 X↑2              
14 RCL- ST T        ;   Δ   s   m   q
15 RCL÷ ST Y        
16 RCL÷ ST Y        
17 SQRT             
18 ×                
19 +                ;  x1   q   q   q
20 STO÷ ST Y        ;  x1  x2   q   q
21 END
Find all posts by this user
Quote this message in a reply
05-12-2024, 08:10 PM (This post was last modified: 05-12-2024 10:33 PM by Thomas Klemm.)
Post: #63
RE: Mathematician Finds Easier Way to Solve Quadratic Equations
Double Angle Formulae

We start with the double angle formula for the sine:

\(
\begin{align}
\sin(2 \alpha)
&= \frac{2 \sin(\alpha) \cos(\alpha)}{1} \\
\\
&= \frac{2 \sin(\alpha) \cos(\alpha)}{\cos(\alpha)^2 + \sin(\alpha)^2} \\
\\
&= \frac{2 \tan(\alpha)}{1 + \tan(\alpha)^2} \\
\end{align}
\)

And similarly for the tangent:

\(
\begin{align}
\tan(2 \alpha)
&= \frac{\sin(2 \alpha)}{\cos(2 \alpha)} \\
\\
&= \frac{2 \sin(\alpha) \cos(\alpha)}{\cos(\alpha)^2 - \sin(\alpha)^2} \\
\\
&= \frac{2 \tan(\alpha)}{1 - \tan(\alpha)^2} \\
\end{align}
\)

Therefore both can be calculated using \(t := \tan(\alpha)\):

\(
\begin{align}
\sin(2 \alpha) &= \frac{2 t}{1 + t^2} \\
\\
\tan(2 \alpha) &= \frac{2 t}{1 - t^2} \\
\end{align}
\)

Solving the Quadratic Equation using \(\sin^{-1}\)

The first formula allows us to solve the following quadratic equation:

\(
t^2 - 2r \; t + 1 = 0
\)

We set \(r := \frac{1}{\sin(2 \alpha)}\) and rearrange the equation:

\(
\begin{align}
\frac{1}{r} = \frac{2 t}{1 + t^2} \\
\\
1 + t^2 = 2t \; r \\
\\
t^2 - 2r \; t + 1 = 0 \\
\end{align}
\)

So how can we use this to solve the quadratic equation: \(x^2 + px + q = 0\) ?
We assume \(q > 0\) so we can substitute: \(x = \sqrt{q} \; t\)
With this we get:

\(
\begin{align}
x^2 + px + q &= 0 \\
q t^2 + \sqrt{q} pt + q &= 0 \\
t^2 + \frac{p}{\sqrt{q}} t + 1 &= 0 \\
\end{align}
\)

We just have to set:

\(
\begin{align}
-2r &= \frac{p}{\sqrt{q}} \\
r &= - \frac{p}{2\sqrt{q}} \\
\end{align}
\)

But now we only have to stick everything together:

\(
\begin{align}
x
&= \sqrt{q} \; t \\
\\
&= \sqrt{q} \; \tan(\alpha) \\
\\
&= \sqrt{q} \; \tan\left(\frac{1}{2}\sin^{-1}\left(\sin(2 \alpha)\right)\right) \\
\\
&= \sqrt{q} \; \tan\left(\frac{1}{2}\sin^{-1}\left(\frac{1}{r}\right)\right) \\
\\
&= \sqrt{q} \; \tan\left(\frac{1}{2}\sin^{-1}\left(- \frac{2\sqrt{q}}{p}\right)\right) \\
\end{align}
\)

Geometric Interpretation using the First Formula

There's a nice geometric interpretation of the first formula using the inscribed angle theorem:

[Image: attachment.php?aid=13545]

I've already posted a similar picture in the previous post #36.

We were solving: \(x^2 - cx + h^2 = 0\)
Thus we'd end up with:

\(
\begin{align}
r
&= \frac{c}{2} \\
&= \frac{-p}{2} \\
\\
h^2 &= q \\
h &= \sqrt{q} \\
\\
\sin(2 \alpha)
&= \frac{h}{r} \\
&= -\frac{2 \sqrt{q}}{p} \\
\end{align}
\)

Solving the Quadratic Equation using \(\tan^{-1}\)

The second formula allows us to solve the following quadratic equation:

\(
t^2 + 2r \; t - 1 = 0
\)

We set \(r := \frac{1}{\tan(2 \alpha)}\) and rearrange the equation:

\(
\begin{align}
\frac{1}{r} = \frac{2 t}{1 - t^2} \\
\\
1 - t^2 = 2t \; r \\
\\
t^2 + 2r \; t - 1 = 0 \\
\end{align}
\)

So how can we use this to solve the quadratic equation: \(x^2 + px + q = 0\) ?
We assume \(q < 0\) so we can substitute: \(x = \sqrt{-q} \; t\)
With this we get:

\(
\begin{align}
x^2 + px + q &= 0 \\
-q t^2 + \sqrt{-q} pt + q &= 0 \\
t^2 + \frac{p}{\sqrt{-q}} t - 1 &= 0 \\
\end{align}
\)

We just have to set:

\(
\begin{align}
2r &= \frac{p}{\sqrt{-q}} \\
r &= \frac{p}{2\sqrt{-q}} \\
\end{align}
\)

But now we only have to stick everything together:

\(
\begin{align}
x
&= \sqrt{-q} \; t \\
\\
&= \sqrt{-q} \; \tan(\alpha) \\
\\
&= \sqrt{-q} \; \tan\left(\frac{1}{2}\tan^{-1}\left(\tan(2 \alpha)\right)\right) \\
\\
&= \sqrt{-q} \; \tan\left(\frac{1}{2}\tan^{-1}\left(\frac{1}{r}\right)\right) \\
\\
&= \sqrt{-q} \; \tan\left(\frac{1}{2}\tan^{-1}\left(\frac{2\sqrt{-q}}{p}\right)\right) \\
\end{align}
\)

Double Angle Formulae for Hyperbolic Functions

We get similar double angle formulae for the hyperbolic sine and hyperbolic tangent:

\(
\begin{align}
\sinh(2 \alpha) &= \frac{2 \tanh(\alpha)}{1 - \tanh(\alpha)^2} \\
\\
\tanh(2 \alpha) &= \frac{2 \tanh(\alpha)}{1 + \tanh(\alpha)^2} \\
\end{align}
\)

The astute reader may notice the change of the sign.
A similar calculation leads to the following formulae:

\(
\begin{align}
x &= \sqrt{-q} \; \tanh\left(\frac{1}{2}\sinh^{-1}\left(\frac{2\sqrt{-q}}{p}\right)\right) \\
\\
x &= \sqrt{q} \; \tanh\left(\frac{1}{2}\tanh^{-1}\left(- \frac{2\sqrt{q}}{p}\right)\right) \\
\end{align}
\)

Programs for the HP-42S

These programs are all similar. They calculate only one of the solutions.
If you want to use them with calculators that don't support complex numbers you may want to select the one that fits the sign of \(q\).

q > 0 using sin-1:
Code:
00 { 20-Byte Prgm }
01▸LBL "Q"
02 SQRT
03 ÷
04 LASTX
05 X<>Y
06 -2
07 X<>Y
08 ÷
09 ASIN
10 2
11 ÷
12 TAN
13 ×
14 END

\(x^2 - 5x + 6 = 0\)

-5 ENTER 6 XEQ "Q"

2


q < 0 using tan-1:
Code:
00 { 20-Byte Prgm }
01▸LBL "Q"
02 +/-
03 SQRT
04 ÷
05 LASTX
06 X<>Y
07 2
08 X<>Y
09 ÷
10 ATAN
11 2
12 ÷
13 TAN
14 ×
15 END

\(x^2 + x - 6 = 0\)

1 ENTER -6 XEQ "Q"

2


q > 0 using tanh-1:
Code:
00 { 20-Byte Prgm }
01▸LBL "Q"
02 SQRT
03 ÷
04 LASTX
05 X<>Y
06 -2
07 X<>Y
08 ÷
09 ATANH
10 2
11 ÷
12 TANH
13 ×
14 END

\(x^2 - 5x + 6 = 0\)

-5 ENTER 6 XEQ "Q"

2


q < 0 using sinh-1:
Code:
00 { 20-Byte Prgm }
01▸LBL "Q"
02 +/-
03 SQRT
04 ÷
05 LASTX
06 X<>Y
07 2
08 X<>Y
09 ÷
10 ASINH
11 2
12 ÷
13 TANH
14 ×
15 END

\(x^2 + x - 6 = 0\)

1 ENTER -6 XEQ "Q"

2


References


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
05-12-2024, 10:37 PM
Post: #64
RE: Mathematician Finds Easier Way to Solve Quadratic Equations
(05-12-2024 08:10 PM)Thomas Klemm Wrote:  \(
x = \sqrt{q} \; \tanh\left(\frac{1}{2}\tanh^{-1}\left(- \frac{2\sqrt{q}}{p}\right)\right)
\)

From any 1 formula, we can derived the other 3

tanh(2x) = 2*tanh(x) / (1 + tanh(x)^2)
sin(2x)   = 2*tan(x)   / (1 + tan(x)^2)

These have the same form, we get:

\(
x = \sqrt{q} \; \tan\left(\frac{1}{2}\sin^{-1}\left(- \frac{2\sqrt{q}}{p}\right)\right)
\)

Let z = GM/AM = √(q)/(-p/2), we "slide" ±i to the left, next to z

x = √(-q) * ±i * tan(asin(z)/2)        // √(q) = ±i * √(-q), sign to get LHS=RHS
   = √(-q) * tanh(±i * asin(z)/2)
   = √(-q) * tanh(asinh(±i*z)/2)      // ±i * √(q) = (±i)^2 * √(-q) = - √(-q)

\(
x = \sqrt{-q} \; \tanh\left(\frac{1}{2}\sinh^{-1}\left(\frac{2\sqrt{-q}}{p}\right)\right)
\)

Similarly, from quoted tanh/atanh formula, to tan/atan:

\(
x = \sqrt{-q} \; \tan\left(\frac{1}{2}\tan^{-1}\left(\frac{2\sqrt{-q}}{p}\right)\right)
\)
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)