Google+ Followers

Thursday, November 9, 2017

Numerical Analysis Example for Phi Equation




As an example of numerical methods using a computer to solve equations, here's an equation who's solution is the phi ratio:
$$x^2-x-1=0$$

Let's say you want to solve this equation (or more much more complex), numerically, rather than symbolically, using a computer.  Here is a simple numerical method to do this:

Method 1:  Iteration
Rewrite the equation for the variable you want to solve for: (i.e., solve for "x=")
$x=x^2-1$            (eqn. 1)
$x^2=x+1$
$x=\sqrt{x+1}$          (eqn. 2)

Note, there are choices for the form of the equation.  Not all equations converge, so it takes practice in finding the form that easily converges.  Just try them all.  Eqn. 2 above converges while I had no luck with eqn. 1.

Write an iterative loop on the computer using a seed value for "x", and use the equation to calculate the next "x" then feed the results for "x" back into the equation and repeat.  Not all equations will converge, be aware.


Here is a sample basic program to calculate phi yourself from the phi equation:

10 PRINT "Numerical Analysis Example for Phi Equaiton"
15 iterations = 0
20 Rem seed value 
30 x=2
35 Rem Resolution, adjust resolution to 1e-10 or 1e-9 for test cases
37 res=1e-16
40 Rem  Loop to solve Phi equationPhi equation
50 xnew=sqr(x+1)
60 err=abs(xnew - x)
65 x=xnew
66 iterations = iterations + 1
67 print "err=";err
70 if err>res then goto 40
80 print "Ourx=";x;"<---Our phi"
86 phi = (1+ sqr(5))/2
87 print "Phi= ";phi;"<---Actual phi"
90 print "resolution= ";res
95 print "iterations= ";iterations
100 end


Just cut and paste into this  Applesoft BASIC emulator.

There are other methods, and they're based on the same basic principle.  Such as writing the equation in a form such as:
$F(x,y,z)=Constant$
$F(x,y,z)=1$
or
$F(x,y,z)=x$ 
or
$F(x,y,z)=\pi$ 
as we have in the case of the re-written proton to electron mass ratio equation from The Oracle Precision Physics Constant Generator (TOP-PCG).  Simply focus on iterating the error towards zero.

Numerical methods are a powerful tool for investigation.  Anyone inspired can write a program with all kinds of features with numerical analysis, graphs, knobs, bells, whistles and adjustments, etc. 
The Surfer, OM-IV