[英]System of equations in sympy with symbolic output
Is it possible to solve a system of equations(linear or non linear) with sympy where the output is symbolic? 是否可以用符号来解决一个方程组(线性或非线性),其中输出是符号的?
Example: 例:
1. f_m = a0 + a1*(-dx) + a2*(-dx)^2
2. f_c = a0
3. f_p = a0 + a1*(dx) + a2*(dx)^2
Solve for a2. 解决a2。
By the Mathematica command 通过Mathematica命令
Solve the solution is 解决方案是
a2 = (1/2)*(f_m - 2*f_c + f_p).
This is a fundamental operation in Sympy, you should study the documention. 这是Sympy的基本操作,你应该研究一下这个文档。 Just to get you started:
只是为了让你开始:
import sympy as sp
f_m, f_c, f_p = sp.var('f_m, f_c, f_p')
a0, a1, a2 = sp.var('a0:3')
dx = sp.var('dx')
eq1 = sp.Eq(f_m, a0 + a1*(-dx) + a2*(-dx)**2)
eq2 = sp.Eq(f_c, a0)
eq3 = sp.Eq(f_p, a0 + a1*(dx) + a2*(dx)**2 )
sp.linsolve([eq1, eq2, eq3], (a0, a1, a2))
# sp.solve([eq1, eq2, eq3], (a0, a1, a2)) # also works
{(f_c, (-f_m + f_p)/(2*dx), (-2*f_c + f_m + f_p)/(2*dx**2))}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.