Home > other >  Python solution of nonlinear equations
Python solution of nonlinear equations

Time:10-18

Nonsense not much said, the code
Method 1:

The from sympy import *

T=symbols (' T ')
Eq=eq (10, 20 * * * exp (- 12000/T)/(0.01 + 10 * * 14 * exp (- 12000/T)) - 18700 * (T - 300))
20 # eq=[10 * * * exp (- 12000/T)/(0.01 + 10 * * 14 * exp (- 12000/T)) - 18700 * (T - 300)] # to such results as well as
Result=nonlinsolve (eq, T)
Print (result)

Program is running, the return is a ConditionSet object, that can't work out the equation,

Method 2:
The import numpy as np
The from scipy. Optimize the import fsolve

Def f (T) :
Return 10 * * * 20 np. J exp (- 12000/T)/(0.01 + 10 * * 14 * np. J exp (- 12000/T)) - 18700 * (T - 300)

Result=fsolve (f, [300])
Print (result)

Operation result error
Minpack. Error: the Result from the function call is not a proper array of floats.

Methods 3
The import math
The from scipy. Optimize the import fsolve

Def f (T) :
Return 10 * * * 20 math. J exp (- 12000/T)/(0.01 + 10 * * 14 * math. J exp (- 12000/T)) - 18700 * (T - 300)
Result=fsolve (f, [300])
Print (result)

3 kinds of methods to solve a root [303.3], but there are three equation root, if the "result=fsolve (f, [300])" this sentence into "result=fsolve (f, [320])", get the second root [323.7]; If "result=fsolve (f, [300])" this sentence into "result=fsolve (f, [360])", you can get the third root [349.4],

If the "result=fsolve (f, [300])" this sentence into "result=fsolve (f, [300320360])", will be an error
TypeError: only the size - 1 the arrays can be converted to a Python scalars

Dear bosses, how do you put the three root one-time solve?
  • Related