sympy 解四元一次方程

 

from sympy import *

 

 

x = Symbol('x')

 

 

y = Symbol('y')

 

 

z = Symbol('z')

 

 

t = Symbol('t')

 

solve([Eq(4*(x-y-z),t),Eq(2*(3*y-z-x),t),Eq(7*z-x-y,t),Eq(x+y+z,72)],[x,y,z,t])

 

{x: 39, y: 21, z: 12, t: 24}

 

 

 

也可以这样定义

 

>>> var('a b c')

(a, b, c)

>>> solve([Eq(a+b,4),Eq(a-b,1)],[a,b])

{a: 5/2, b: 3/2}

 

 

就是写法太费近了,有机会我也来搞个語法生成器,来简化語法,呵呵,这方面从未搞过还挺想试试的

reference:
你也可以使用matlab,mathimatic之类的
怎么有人看没人回?你要是问mathematica,输入
Solve[{x-(y-x)/2==-2,(z-y)/3+(x-y)/2==4,(y-z)/3-z/4==-2},{x,y,z}]
然后,按Shift+Enter。
你要是问matlab,应该贴在matlab论坛。在这里可以简单说一下:
建一个新文件,写上下面几行:
syms x y z
eq1=x - (y - x)/2 + 2;
eq2=(z - y)/3 + (x - y)/2 - 4;
eq3=(y - z)/3 - z/4 + 2;
[x,y,z]=solve(eq1,eq2,eq3,'x','y','z')
保存为m文件,比如abc.m,回到matlab窗口,键入abc回车,应该可以看到结果了。
SymPy is an open source Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python and does not require any external libraries.
sudo apt-get install python-setuptools
sudo easy_install sympy

你可能感兴趣的:(sympy 解四元一次方程)