Re: [sympy] unable to solve system with more equations than unknowns?

46 views
Skip to first unread message

Chris Smith

unread,
Jul 5, 2012, 9:48:08 PM7/5/12
to sy...@googlegroups.com
On Thu, Jul 5, 2012 at 5:56 PM, Andrew <zxwa...@gmail.com> wrote:
> Hi, I am very new to sympy and python, so pardon my simple question
>
> I have a matrix right here like this (4 equations, 3 unknowns)
> mat1=
> [ 0, 15.0, 10.0, 700.0]
> [ 1, 1, 1, 100.0]
> [ 0, 10.0, 5.0, 200.0]
> [-5.0, 0, 0, 0]
>
> and a list of unknowns
> unknown=[y0,y1,y2]
>

Which columns do those variables correspond to? If you multiply the
matrix by a length-4 column vector of variables and pass this to solve
it gives

>>> v = var('a:d')
>>> v
(a, b, c, d)
>>> v = Matrix([list(v)]).T
>>> e=m*v
>>> solve(e)
{c: -160.0*d, b: 60.0*d, a: 0}

And the determinant of the matrix is 0:

>>> m.det()
0

So it looks like there are infinite solutions. I don't spend much time
working with the individual solver routines, so I'm not sure how you
should pass the variables, but perhaps you can start by reading the
docstring (help(solve_linear_system)) where you will see that you
should be passing an augmented system. I don't think you are doing
that.

/c

Aaron Meurer

unread,
Jul 6, 2012, 3:55:39 PM7/6/12
to sy...@googlegroups.com
On Thu, Jul 5, 2012 at 7:48 PM, Chris Smith <smi...@gmail.com> wrote:
> On Thu, Jul 5, 2012 at 5:56 PM, Andrew <zxwa...@gmail.com> wrote:
>> Hi, I am very new to sympy and python, so pardon my simple question
>>
>> I have a matrix right here like this (4 equations, 3 unknowns)
>> mat1=
>> [ 0, 15.0, 10.0, 700.0]
>> [ 1, 1, 1, 100.0]
>> [ 0, 10.0, 5.0, 200.0]
>> [-5.0, 0, 0, 0]
>>
>> and a list of unknowns
>> unknown=[y0,y1,y2]
>>
>
> Which columns do those variables correspond to? If you multiply the
> matrix by a length-4 column vector of variables and pass this to solve
> it gives

I think the way solve_linear_system is supposed to work is that the
last column represents the right hand side of the equation. So a row
[1, 2, 3, 4] would represent 1*x1 + 2*x2 + 3*x3 = 4. In other words,
it's an augmented matrix.

>
>>>> v = var('a:d')
>>>> v
> (a, b, c, d)
>>>> v = Matrix([list(v)]).T
>>>> e=m*v
>>>> solve(e)
> {c: -160.0*d, b: 60.0*d, a: 0}
>
> And the determinant of the matrix is 0:
>
>>>> m.det()
> 0

I don't think that the determinant has anything to do with it.

The row [1, 1, 1, 100] clearly corresponds to the solution given.

The problem seems to have something to do with using floats. If you
do mat1 = mat1.applyfunc(Integer), you get the correct solution. The
problem also exists when using mat1.rref(). This is clearly a bug.
Can you report it at code.google.com/p/sympy/issues/list?

Aaron Meurer

>
> So it looks like there are infinite solutions. I don't spend much time
> working with the individual solver routines, so I'm not sure how you
> should pass the variables, but perhaps you can start by reading the
> docstring (help(solve_linear_system)) where you will see that you
> should be passing an augmented system. I don't think you are doing
> that.
>
> /c
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>

Andrew

unread,
Jul 8, 2012, 6:12:57 PM7/8/12
to sy...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages