THE PUZZLET PAGE

PUZZLET 069 - THE SOLUTION


' Puzzlet #069
' Subtracting the sum of the edges and the
' total area of a cube from its volume
' leaves 2.216.  What is the length of the
' cube's side to an accuracy of six places
' of decimals?
' By Dave Ellis.

def count, flag: int
def side, value, diffValue: double
openconsole
print "Calculating ...": print

side = 10.0: 'first approximation
count = 0:  'iteration counter

' use Newton-Raephson method
do
count = count + 1
    'substitute side's value in equation
    value = side^3 - 6*side^2 - 12*side - 2.216
    if abs(value) < .000001
        flag = -1
    endif
    'find value of first differential
    diffValue = 3*side^2 - 12*side - 12
    side = side - value/diffValue
until flag |(count > 100)
' if count > 100, this is diverging rather
' than converging, and will not lead to a
' solution with this intital value.

if (count < 100) & (side > 0)
    print "Side length is: ",
    print using ("#.######", side)
    print: print "Found in ", count, "iterations."
else
    print "No solution found with the chosen ",
    print "initial value."
endif   

print: print "Press a key to exit... ",
do: until inkey$ <> ""
closeconsole
end

    
PROGRAM NOTES


This Puzzlet is really just asking for the solution of a cubic equation.  The volume of the cube is side3,  its area is 6*side2, and the number of edges 12.  The equation is therefore:

formula

Newton's method is deployed to solve it, which was introduced and described in Puzzlet 5. Please refer back in the archives if you want to refresh your memory.

Protection against divergence is included. If you'd like to know more on how to do this automatically, please e-mail me at the address below.


When you run the program, it generates the inset screen. 

There are quite a lot of iterations, caused by working to 6 places of decimals and a rather rough initial value.


Calculating ...

Side length is: 7.614221

Found in 34 iterations.

Press any key to exit ...




Site design/maintenance: Dave Ellis E-mail me!
Last Updated: February 22nd, 2004.