Question: Problem with conditions in if statement

Hi, I'm having troubles with the conditions in an if statement.  My program is basically a for loop which assigns random values to some parameters, then some numbers are calculated, and finally there is an 'if' that checks if these numbers are positive.  However, when checking some of the output parameters I find that for some of them the conditions are not satisfied, i.e. the 'if' is not doing its job.  Here's a simplified version of the code.  Thanks for any help.

>for i to 1000 do

r:=(rand(-10000..10000))/(1000); s:=(rand(1..10000))/(1000);

a30:=r(); a21:=r(); a12:=r(); a03:=r(); b03:=r(); a20:=r(); a11:=r(); a02:=(a11^2)/(4*a20); b02:=(2*a02^2)/(a11); a10:=s(); a01:=r(); b01:=(a01*a11)/(2*a20);

TrS1:=a10+b01; detS1:=a10*b01-a01^2;

eig1[1]:=evalf((TrS1+sqrt(TrS1^2-4*detS1))/2); eig1[2]:=evalf((TrS1-sqrt(TrS1^2-4*detS1))/2);

if (0<eig1[1] and 0<eig1[2]) then

solalpha:=simplify(fnormal([solve((a21/3)*x^3+a12*x^2+3*a03*x+b03=0,x)]));

if Im(solalpha[1])=0 then alpha:=solalpha[1] elif Im(solalpha[2])=0 then alpha:=solalpha[2] elif Im(solalpha[3])=0 then alpha:=solalpha[3] else alpha:=solalpha[1] end if;

TrS30:=3*a30*alpha^2+2*a21*alpha+a12+a12*alpha^2+6*a03*alpha+3*b03; detS30:=(3*a30*alpha^2+2*a21*alpha+a12)*(a12*alpha^2+6*a03*alpha+3*b03)-(a21*alpha^2+2*a12*alpha+3*a03)^2;

eig30[1]:=evalf((TrS30+sqrt(TrS30^2-4*detS30))/2); eig30[2]:=evalf((TrS30-sqrt(TrS30^2-4*detS30))/2);

if (0<eig30[1] and 0<eig30[2]) then fprintf(file,"%g %g %g %g %g %g %g %g %g %g %g %g\n",a30,a21,a12,a03,b03,a20,a11,a02,b02,a10,a01,b01) end if:

end if:

end do:

Please Wait...