comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » solve cubic polynomial for dummies?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
solve cubic polynomial for dummies? [message #88423] Wed, 23 April 2014 14:26 Go to next message
mga1 is currently offline  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 Go to previous messageGo to next message
wlandsman is currently offline  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 Go to previous message
mga1 is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Upload a file on a website
Next Topic: H5D_Read on compound type (GDL)

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:44:51 PDT 2025

Total time taken to generate the page: 0.00675 seconds