Click to See Complete Forum and Search --> : trouble with ax^3bx^2cxd=0
phanbachloc
Jun 17th, 2002, 11:07 PM
:D i'm making program that will solve ax^3+bx^2+cx+d=0 :
dim a,b,c,d,x
a=inputbox("enter a")
b
c
d
'b,c,d is coded like a'
for x=-1000 to 1000 step 0.1
s=ax^3+bx^2+cx+d
if s=0 then msgbox"x is ok:&x"
next
x
.;) i use " for .... step " but when i run program it's not so .ex:0.1 is 0.09999999.please help me
wy125
Jun 18th, 2002, 09:02 AM
I think the problem that you're having has to do with the precision of the numbers stored in memory. Try using doubles and see what happens.
That aside, the approach that you're taking to finding a root isn't the best way. If you happened to find one it would be pure luck. It's better to get a good first guess and proceed from there. There are many methods of finding roots, one of these is Newtons method, which uses derivatives to provide good guesses to 'zero' in on the root of an equation.
I wrote a program that computes the all roots of a cubic equation. However, it's not very elegant since it uses a 'standard' solution from a textbook. That's like writing a program that uses the quadratic formula to find the roots of a 2nd-order polynomial.
Guv, submitted a program that finds the roots for an nth-degree polynomial. It was very nice. Take a look around and see if you can find it.
DavidHooper
Jun 19th, 2002, 12:31 PM
Suppose you have
s=x^3+2x^2+7x+3
and you want to find value(s) of x for which s=0. Say, for the purposes of argument, that an exact value of x is 0.1234. Your program is only accurate to 0.1 from the look of it, so it will never find this exact root.
Look at the bottom of this (http://209.120.143.185/showthread.php?threadid=157872&highlight=root) thread for Guv's program. The thread also contains better methods you might find useful. Post back if you still need help.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.