Maybe I'm misunderstanding, but it seems you look at solve(a,b) as a function to return the solution of the linear symbolic equation: a * x = b (whose solution is: x = b / a), with x scalar. Instead, solve(a,b) gives the numerical solution of the linear system a * x = b, with x and b 1d-arrays and a 2d-array. For examples, something like: 2 * x1 + 3 * x2 = 4 4 * x1 + 5 * x2 = 6 where x = [x1, x2], b = [4, 6] and a = [[2, 3], [4, 5]]. solve(a,b) returns [-1, 2]. If from the file you import a string with the symbolic representation of you equation, and you want to solve it symbolically, stay with simpy. hth, L. On 11/6/07, Eduardo Rodrigues <elr1979@gmail.com> wrote:
If I want to solve an equation with linalg.solve I must know the equation, right?
From help: "solve(a, b) Return the solution of a*x = b"
But if I don't know - or if I don't want to look - the equation for x, how can I solve it? I will import equations from a file.
[]'s.
----- Original Message ----- *From:* Michael Nandris <mnandris@btinternet.com> *To:* SciPy Users List <scipy-user@scipy.org> *Sent:* Tuesday, November 06, 2007 10:42 AM *Subject:* Re: [SciPy-user] Solve
These examples for solving equations are in *scipy_tutorial.pdf*
from scipy import mat, linalg
""" Solves three simultaneous equations: x + 3y + 5z = 10 2x + 5y + z = 8 2x + 3y + 8z =3 """
XYparameters = mat('[1 3 5; 2 5 1; 2 3 8]') constants = mat('[10; 8; 3]') print linalg.solve( XYparameters, constants ) # array([[-9.28], # [ 5.16], # [ 0.76]])
""" Solves two simultaneous equations: 5x + 2y - 9 = 0 3x + 4y - 4 = 0 """
XYparameters = mat('[5 2; 3 4]') constants = mat('[9; 4]') print linalg.solve( XYparameters, constants ) # should print (2,-0.5)
*Eduardo Rodrigues <elr1979@gmail.com>* wrote:
Hi, I am starting in Python. I usually use Maple and I am with a problem to do the same project in Python. I would like to solve an equation like x+y+1=0 for x. In Maple I use "solve(x+y+1=0,x);". Do exist a similar command in Python/NumPy/SciPy? Regards, Eduardo.
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
------------------------------
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user