Solve a non linear equation
I need to know how to solve this equation for k. I know it is 4.91571, but I need to see the steps taken to get there. Here it is:
0.61 = k(1.0625)^(1/k) - k
Where ^ means "raised to".
Just to show that it works:
0.61 = 4.91571(1.0625)^(1/4.91571) - 4.91571
0.61 = 4.91571(1.1024) - 4.91571
0.61 = 4.97671 - 4.91571
0.61 = 0.61
Everywhere you have 0.61, I think it should read 0.061.
A simple way to solve such intractable equations is by iteration. Write your equation as
f(k) = k(1.0625)^(1/k) - k - 0.061 = 0
Then there are various "trial-and-error" numerical methods that take 1 or 2 guesses as to the root of f(k)=0, and attempt to produce a value close to a true root. In general there may be more than one root, or there may be no roots, or the method may fail to find a root. The chances of success are improved if the guesses are close to the root sought. In your problem, the secant method (which is fast but prone to failure) easily gives the answer 4.91571. See the program below. Other methods worth knowing about are interval-halving, regula falsi, and Brent's root-finding algorithm.
'----------------------A complete FB2 program------------- COMPILE 0,_dimmedvarsOnly LOCAL FN Func!(x!) ' function whose root is sought DIM fofx! fofx! = x!*((1.0625)^(1.0/x!)) - x! - 0.061 END FN = fofx! LOCAL FN RootSecant!(guess1!,guess2!,tol!,maxit, ifailPtr&) ' root of FN Func!(x) by secant method ; modified from Numerical Recipes DIM x1!, epsm!, fa!, fb!, dx!, root!, j epsm! = 0.0000002 ' approx. f.p. precision x1! = guess1!: root!= guess2! IF (x1! - root! = 0.0) THEN root! = x1!*(1.0 + epsm!) + epsm! fb! = FN Func!(x1!) fa! = FN Func!(root!) IF (ABS(fb!) < ABS(fa!)) THEN SWAP x1!,root!: SWAP fb!,fa! POKE WORD ifailPtr&, _noErr FOR j = 1 TO maxit LONG IF (fa! - fb! = 0.0) PRINT "Divide by zero in FN RootSecant at " STR$(root!) POKE WORD ifailPtr&, 1 EXIT FN END IF dx! = (x1! - root!) * fa! / (fa! - fb!) x1! = root!: fb! = fa! root! = root! + dx! fa! = FN Func!(root!) LONG IF (ABS(dx!) <= (2.0*epsm!*ABS(root!) + 0.5*tol!)) OR (fa! = 0.0) EXIT FN ' converged END IF NEXT POKE WORD ifailPtr&, 2 PRINT "FN RootSecant failed to converge at " STR$(root!) END FN = root! WINDOW 1 DIM x1!, x2!, answer!, ifail x1! = 0.0: x2! = 7 ' two guesses answer! = FN RootSecant!(x1!,x2!,0.000001,100, @ifail) PRINT "error code " ifail PRINT answer! DO: HANDLEEVENTS: UNTIL FN BUTTON '------------------------------------------------------Most non-linear equations, even in one variable, cannot be solved analytically. So numerical root-finding methods make a big chapter in books on numerical methods. It sounds as though you would enjoy "Numerical Recipes" by Press WH, Teukolsky SA, Vettering WT, & Flannery BP, as one of the better books.