[SciPy-user] Fsolve- giving different answer while in loop

Jeevan Baretto jeevan.baretto@gmail....
Sun Apr 6 05:13:42 CDT 2008


Hi,
I was using the scipy.optimize.fsolve module.
I feel I found a bug in that fsolve module. I shall attach the code. When I
solve the equation separately with input values of x and y it gives me 201
as the result. While I input the arrays x and y which has the previous
values in it, it gives me a different answer.

To make things clear I have x as
[298.0,
 571.3,
 580.3,
 585.8,
 589.9,
 593.0,
 595.6502,
 598.18101,
 600.34314,
 602.21445,
 603.86372,
 605.42646,
 606.91392,
 608.28402,
 609.56121,
 610.77252,
 611.92214,
 613.01943,
 614.13321,
 615.16644,
 616.16372,
 617.1371,
 618.08782,
 619.01824,
 619.93076,
 620.79804,
 621.73607,
 622.58504,
 623.45065,
 624.3112,
 625.16966,
 626.0283,
 626.89099,
 627.76315,
 628.64615,
 629.54137,
 630.45473,
 631.341,
 632.28681,
 633.267,
 634.28634,
 635.3525,
 636.55254,
 637.69639,
 639.05644,
 640.55579,
 642.27081,
 644.54286,
 647.81437,
 657.77397]


and y as

[298.0,
 576.51903,
 585.51341,
 591.20359,
 595.332,
 598.55687,
 601.28444,
 603.73461,
 605.84835,
 607.79922,
 609.48345,
 611.32751,
 612.84132,
 614.23754,
 615.54028,
 616.77623,
 617.95329,
 619.07467,
 620.20759,
 621.26395,
 622.28363,
 623.27789,
 624.25009,
 625.20078,
 626.13659,
 627.02366,
 627.98247,
 628.8532,
 629.74054,
 630.61663,
 631.4766,
 632.36279,
 633.24062,
 634.14565,
 635.05868,
 635.9553,
 636.92742,
 637.77739,
 638.78596,
 639.74769,
 640.77499,
 641.88289,
 643.07579,
 644.24899,
 645.57804,
 647.20167,
 648.98315,
 651.25973,
 654.57302,
 662.9283]


And my function is

root(T0=298,r=0.008314,B1=20,B2=30):


        Ei=[]
        def T1(i):
            return x[i]
        def T2(i):
            return y[i]
        print T1(38),T2(38)
        for i in range(1):
            i=38
            O=(fsolve(lambda
Ei:(((T0*exp(-Ei/r/T0)-Ei/r*(exp(-Ei/r/T0)/Ei/r/T0*((Ei/r/T0)**2+4.03648*(Ei/r/T0)+1.15198)/((Ei/r/T0)**2+5.03637*Ei/r/T0+4.1969))-T1(i)*exp(-Ei/r/T1(i))+Ei/r*(exp(-Ei/r/T1(i))/Ei/r/T1(i)*(((Ei/r/T1(i))**2+4.03648*Ei/r/T1(i)+1.15198)/((Ei/r/T1(i))**2+5.03637*Ei/r/T1(i)+4.1969))))/B1)
-
((exp(-Ei/r/T0)*T0-Ei/r*(exp(-Ei/(r*T0))/Ei/(r*T0)*(((Ei/(r*T0))**2+4.0364*Ei/(r*T0)+1.15198)/((Ei/(r*T0))**2+5.03637*Ei/(r*T0)+4.1969)))
-exp(-Ei/r/T2(i))*T2(i)+(exp(-Ei/(r*T2(i)))/Ei/(r*T2(i))*(((Ei/(r*T2(i)))**2+4.0364*Ei/(r*T2(i))+1.15198)/((Ei/(r*T2(i)))**2+5.03637*Ei/(r*T2(i))+4.1969))))/B2))**2,150,maxfev=10000))
              Ei.append(O)

        return Ei

Now for say the x[38] and y[38] I evaluate the function for Ei separately on
the console using fsolve and I get 201 as the answer. But when I use it in
the loop, like above I get a different answer for x[38] and y[38], i.e.
Ei[38] is not 201 !!

Hope you have got what I wanted to tell.

Please let me know if you can fix this bug..


Thanks in advance,
Jeevan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080406/049cba87/attachment.html 


More information about the SciPy-user mailing list