I created a script for calculate some variable terms in a river, but I found some difficulties in the part i attached when i shoul solve a cubic equation.
Could help me pleaseee.
- Code: Tout sélectionner
Define lucee()=
Prgm
:Local g,k,fr,y0,q,b,s,yq,yw,ye,yr,em,ev,ef,sl
:g:=9.81
:k:=1
:Request "Portata Q=",q
:Request "Y0 moto indisturbato=",y0
:
:Request "Larghezza b=",b
:Request "Altezza Soglia s=",s
:fr:=((q^(2))/(g*b^(2)*y0^(3)))
:Disp "Fr^2 uniforme=",fr
:
:If fr<k Then
:Disp "Corrente Lenta, calcolo soglia"
:sl:=1-fr^(((2)/(3)))+fr^(2)-fr^(((4)/(3)))
:Disp "Soglia limite al=",sl
:
:If ((s)/(y0))>sl Then
:Disp "Soglia alta, Ym=Ycq, Ev=Em+s"
:yq:=root(((q^(2))/(g*b^(2))),3)
:ev:=y0+((q^(2))/(g*b^(2)*y0^(3)))+s
:Disp "Energia valle Ev=",ev
:yw:=nSolve(yw^(3)-yw^(2)*ev+((q^(2))/(2*g*b^(2)))=0,yw)
:Disp "Ymonte=",yq
:Disp "Yvalle=",yw
:
:ElseIf ((s)/(y0))<sl Then
:Disp "Soglia bassa, Yv=Y0v"
:em:=y0+((q^(2))/(g*b^(2)*y0^(3)))
:Disp "Energia monte Em=",em
:ye:=solve(ye^(3)-ye^(2)*em+((q^(2))/(2*g*b^(2)))=0,ye)
:Disp "Ymonte=",ye
:Disp "Yvalle=",y0
:EndIf
:ElseIf fr>k Then
:Disp "Corrente Veloce, soglia sempre bassa, no transizione c"
:ef:=y0+((q^(2))/(2*g*b^(2)*y0^(3)))+s
:Disp "Energia Cvel Evbassa=",ef
:yf:=solve(yf^(3)-yf^(2)*ef+((q^(2))/(2*g*b^(2)))=0,yf)
:
:Disp "Ym=Y0m=",y0
:Disp "Yv=",yf
:EndIf
:
:EndPrgm
This is the program i wrote. i have some problem during the resolution of the cubic equation yw:=nSolve(yw^(3)-yw^(2)*ev+((q^(2))/(2*g*b^(2)))=0,yw).
Do someone has some advices for find a solution.
All the advice it would be so helpful
GP