' 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