THE PUZZLET PAGE


PUZZLET 82 - THE SOLUTION



' Puzzlet #082.
' The equation 9.87x - 6.54^x - 3.21 = 0
' has  the unusual property of using all
' the digits once and once only,  and in
' descending order.  To 4 decimal places
' of accuracy, what value of x satisfies
' this equation?
' By Dave Ellis.

def p, r: float
' p = f(root), r = f'(root) because
' the algorithm uses Newton's Method
def oldRoot, root: float
def flag, itCount: int

openconsole
color 14, 1
print "Roots:": print

root = 0.5: 'Trying root 0.5 then 1.5
do
    flag = 0: 'solution indicator
    itCount = 0: 'counts iterations
    do
        itCount = itCount + 1
        oldRoot = root
        p = 9.87*root - 6.54^root - 3.21
        r = 9.87 - (6.54^root)*log(6.54)
        root = root - p/r
        if abs(root - oldRoot) < .00001
            flag = -1
        endif
    until flag = -1 | itCount > 20
    color 11, 1
    print using ("#.####", root),
    color 14, 1
    print " found in ", itCount, "iterations"
    root = root + 1.0
until root > 2.0

print: print "That's all, folks!"
printprint "Press any key to exit ... ",
dountil inkey$ <> ""
closeconsole
end


PROGRAM NOTES

The simplest way to tackle this problem is to use Newton's method. This has appeared in previous Puzzlets, so I don't propose to give a detailed description of its operation here. If you want to read more about it, use the Archives page to view Puzzlet #005.

One important point, however: you can see by inspection that the result is going to be near unity (just substitute 1 for x in the equation to try it out). So I chose to take two starting roots just either side of 1 and run the program twice.  The code shows this as root = 0.5 and then root = 1.5.


One thing that might exercise your memory is the second term of the equation: 6.54x. You'll have to find the first derivative of this when applying Newton's method. If you check the code, you'll see that this derivative is as shown inset.
  
Formula

Graph
       
The inset graph shows the function's curve. You can see where the two results lie on the zero y axis.

When I zoomed into the graph, it shows the two values as 0.7085 and 1.0414.



The inset screen shot shows the result of running the code above.  As you can see, this is in accordance with the graph values.
   
             
Roots:

0.7085 found in 5 iterations
1.0414 found in 7 iterations

That's all, folks!

Press a key ...




Site design/maintenance: Dave Ellis E-mail me!
Last Updated: March 28th, 2004.