solve cubic polynomial for dummies? [message #88423] |
Wed, 23 April 2014 14:26  |
mga1
Messages: 2 Registered: April 2014
|
Junior Member |
|
|
Hi all
I have a cubic polynomial:
'-1.9441*x^3+2.8777*x^2-2.2023*x+1'
and a series of y values:
Y = [0.556076778, 0.459954297, 0.404784134, 0.540789788, 0.7493244, 0.814803237, 1, 0.296016879, 0.434675619, 0.612691897]
How would I solve this for x in each case?
Cheers,
Mat
|
|
|
Re: solve cubic polynomial for dummies? [message #88425 is a reply to message #88423] |
Wed, 23 April 2014 16:39   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
You could use the exact formula for a cubic ( e.g. http://idlastro.gsfc.nasa.gov/ftp/contrib/freudenreich/cuber oot.pro ) but it is probably easier to use the general root finder FZ_ROOTS in a little program like cube solve.pro below
coeff = [-1.94410 , 2.87770 , -2.02300 , 1.00000 ]
Y = [0.556076778, 0.459954297, 0.404784134, 0.540789788, 0.7493244, 0.814803237, 1, 0.296016879, 0.434675619, 0.612691897]
pro cubesolve,coeff,y
foreach val,y do begin
c = coeff
c[0] = coeff[0]-val
roots = fz_roots(c,/double)
print,roots
endforeach
return
end
There are 3 roots to a cubic but likely you are only interested in the real root.
On Wednesday, April 23, 2014 5:26:50 PM UTC-4, mg...@students.waikato.ac.nz wrote:
> Hi all
>
>
>
> I have a cubic polynomial:
>
>
>
> '-1.9441*x^3+2.8777*x^2-2.2023*x+1'
>
>
>
> and a series of y values:
>
>
>
> Y = [0.556076778, 0.459954297, 0.404784134, 0.540789788, 0.7493244, 0.814803237, 1, 0.296016879, 0.434675619, 0.612691897]
>
>
>
> How would I solve this for x in each case?
>
>
>
> Cheers,
>
>
>
> Mat
|
|
|
Re: solve cubic polynomial for dummies? [message #88437 is a reply to message #88425] |
Thu, 24 April 2014 13:30  |
mga1
Messages: 2 Registered: April 2014
|
Junior Member |
|
|
Fantastic thanks. Final code used posted below. Ended up using cuberoot but fz_roots worked also:
pro cubesolve,coeff,y
coeff = [1.00000, -2.02300, 2.87770, -1.94410]
Y = [0, 0.95]
N_values=n_elements(y)
for i=0, N_values-1 do begin
val=y[i]
; c = coeff
; c[0] = coeff[0]-val
; roots = fz_roots(c,/double)
; print,roots
x = CUBEROOT([1.00000-val, -2.02300, 2.87770, -1.94410])
print, x
endfor
end
|
|
|