Skip to content Skip to sidebar Skip to footer

How Can I Solve A Simultaneous Equation In Python Using Sympy

I have the two following equations: 40 = Vmax*5.041667 + (Vmax**2/Amax)*sympy.exp((-Amax/Vmax)*5.041667) - (Vmax**2/Amax) 20 = Vmax*2.897628 + (Vmax**2/Amax)*sympy.exp((-Amax/Vmax)

Solution 1:

You've misunderstood how nsolve works. The third argument is an initial guess that is used to start the root-finding algorithm. Here [1, 1] will work fine as the guess:

In [26]: from sympy import symbols, Eq, nsolve, exp                                                                                                            

In [27]: Vmax, Amax = symbols('Vmax, Amax')                                                                                       

In [28]: eq1 = Eq(Vmax*5.041667 + (Vmax**2/Amax)*exp((-Amax/Vmax)*5.041667) - (Vmax**2/Amax), 40) 
    ...: eq2 = Eq(Vmax*2.897628 + (Vmax**2/Amax)*exp((-Amax/Vmax)*2.897628) - (Vmax**2/Amax), 20)                           

In [29]: nsolve([eq1, eq2], [Amax, Vmax], [1, 1])                                                                                 
Out[29]: 
⎡11.8641453843429⎤
⎢                ⎥
⎣9.41244210257784

Note that this only finds one solution starting from any particular initial guess. It is possible that that a system like this has more than one solution.

Post a Comment for "How Can I Solve A Simultaneous Equation In Python Using Sympy"