Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

numpy (matrix solver) - python vs. matlab

 

 

First page Previous page 1 2 Next page Last page  View All Python python RSS feed   Index | Next | Previous | View Threaded


newsboost at gmail

Apr 29, 2012, 3:17 PM

Post #1 of 47 (1709 views)
Permalink
numpy (matrix solver) - python vs. matlab

Hi,

Notice cross-post, I hope you bear over with me for doing that (and I
imagine that some of you also like python in the matlab-group like
myself)...

------------------------------------------
Python vs. Matlab:
------------------------------------------

Python:
========
from numpy import matrix
from numpy import linalg
A = matrix( [[1,2,3],[11,12,13],[21,22,23]] )
print "A="
print A
print "A.I (inverse of A)="
print A.I

A.I (inverse of A)=
[[ 2.81466387e+14 -5.62932774e+14 2.81466387e+14]
[ -5.62932774e+14 1.12586555e+15 -5.62932774e+14]
[ 2.81466387e+14 -5.62932774e+14 2.81466387e+14]]


Matlab:
========
>> A=[1 2 3; 11 12 13; 21 22 23]

A =

1 2 3
11 12 13
21 22 23

>> inv(A)
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.067522e-17.

ans =

1.0e+15 *

0.3002 -0.6005 0.3002
-0.6005 1.2010 -0.6005
0.3002 -0.6005 0.3002

------------------------------------------
Python vs. Matlab:
------------------------------------------

So Matlab at least warns about "Matrix is close to singular or badly
scaled", which python (and I guess most other languages) does not...

Which is the most accurate/best, even for such a bad matrix? Is it
possible to say something about that? Looks like python has a lot more
digits but maybe that's just a random result... I mean.... Element 1,1 =
2.81e14 in Python, but something like 3e14 in Matlab and so forth -
there's a small difference in the results...

With python, I would also kindly ask about how to avoid this problem in
the future, I mean, this maybe means that I have to check the condition
number at all times before doing anything at all ? How to do that?

I hope you matlabticians like this topic, at least I myself find it
interesting and many of you probably also program in some other language
and then maybe you'll find this worthwhile to read about.
--
http://mail.python.org/mailman/listinfo/python-list


kiuhnm03.4t.yahoo.it at mail

Apr 29, 2012, 3:39 PM

Post #2 of 47 (1665 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 4/30/2012 0:17, someone wrote:
> Hi,
>
> Notice cross-post, I hope you bear over with me for doing that (and I
> imagine that some of you also like python in the matlab-group like
> myself)...
>
> ------------------------------------------
> Python vs. Matlab:
> ------------------------------------------
>
> Python:
> ========
> from numpy import matrix
> from numpy import linalg
> A = matrix( [[1,2,3],[11,12,13],[21,22,23]] )
> print "A="
> print A
> print "A.I (inverse of A)="
> print A.I
>
> A.I (inverse of A)=
> [[ 2.81466387e+14 -5.62932774e+14 2.81466387e+14]
> [ -5.62932774e+14 1.12586555e+15 -5.62932774e+14]
> [ 2.81466387e+14 -5.62932774e+14 2.81466387e+14]]
>
>
> Matlab:
> ========
> >> A=[1 2 3; 11 12 13; 21 22 23]
>
> A =
>
> 1 2 3
> 11 12 13
> 21 22 23
>
> >> inv(A)
> Warning: Matrix is close to singular or badly scaled.
> Results may be inaccurate. RCOND = 1.067522e-17.
>
> ans =
>
> 1.0e+15 *
>
> 0.3002 -0.6005 0.3002
> -0.6005 1.2010 -0.6005
> 0.3002 -0.6005 0.3002
>
> ------------------------------------------
> Python vs. Matlab:
> ------------------------------------------
>
> So Matlab at least warns about "Matrix is close to singular or badly
> scaled", which python (and I guess most other languages) does not...

A is not just close to singular: it's singular!

> Which is the most accurate/best, even for such a bad matrix? Is it
> possible to say something about that? Looks like python has a lot more
> digits but maybe that's just a random result... I mean.... Element 1,1 =
> 2.81e14 in Python, but something like 3e14 in Matlab and so forth -
> there's a small difference in the results...

Both results are *wrong*: no inverse exists.

> With python, I would also kindly ask about how to avoid this problem in
> the future, I mean, this maybe means that I have to check the condition
> number at all times before doing anything at all ? How to do that?

If cond(A) is high, you're trying to solve your problem the wrong way.
You should try to avoid matrix inversion altogether if that's the case.
For instance you shouldn't invert a matrix just to solve a linear system.

Kiuhnm
--
http://mail.python.org/mailman/listinfo/python-list


newsboost at gmail

Apr 29, 2012, 5:17 PM

Post #3 of 47 (1657 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 04/30/2012 12:39 AM, Kiuhnm wrote:

>> So Matlab at least warns about "Matrix is close to singular or badly
>> scaled", which python (and I guess most other languages) does not...
>
> A is not just close to singular: it's singular!

Ok. When do you define it to be singular, btw?

>> Which is the most accurate/best, even for such a bad matrix? Is it
>> possible to say something about that? Looks like python has a lot more
>> digits but maybe that's just a random result... I mean.... Element 1,1 =
>> 2.81e14 in Python, but something like 3e14 in Matlab and so forth -
>> there's a small difference in the results...
>
> Both results are *wrong*: no inverse exists.

What's the best solution of the two wrong ones? Best least-squares
solution or whatever?

>> With python, I would also kindly ask about how to avoid this problem in
>> the future, I mean, this maybe means that I have to check the condition
>> number at all times before doing anything at all ? How to do that?
>
> If cond(A) is high, you're trying to solve your problem the wrong way.

So you're saying that in another language (python) I should check the
condition number, before solving anything?

> You should try to avoid matrix inversion altogether if that's the case.
> For instance you shouldn't invert a matrix just to solve a linear system.

What then?

Cramer's rule?
--
http://mail.python.org/mailman/listinfo/python-list


nma at 12000

Apr 29, 2012, 5:38 PM

Post #4 of 47 (1652 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 04/29/2012 05:17 PM, someone wrote:

> I would also kindly ask about how to avoid this problem in
> the future, I mean, this maybe means that I have to check the condition
> number at all times before doing anything at all ? How to do that?
>

I hope you'll check the condition number all the time.

You could be designing a building where people will live in it.

If do not check the condition number, you'll end up with a building that
will fall down when a small wind hits it and many people will die all
because you did not bother to check the condition number when you solved
the equations you used in your design.

Also, as was said, do not use INV(A) directly to solve equations.

--Nasser
--
http://mail.python.org/mailman/listinfo/python-list


no.email at nospam

Apr 29, 2012, 5:57 PM

Post #5 of 47 (1657 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

someone <newsboost [at] gmail> writes:
>> A is not just close to singular: it's singular!
> Ok. When do you define it to be singular, btw?

Singular means the determinant is zero, i.e. the rows or columns
are not linearly independent. Let's give names to the three rows:

a = [1 2 3]; b = [11 12 13]; c = [21 22 23].

Then notice that c = 2*b - a. So c is linearly dependent on a and b.
Geometrically this means the three vectors are in the same plane,
so the matrix doesn't have an inverse.

>>> Which is the most accurate/best, even for such a bad matrix?

What are you trying to do? If you are trying to calculate stuff
with matrices, you really should know some basic linear algebra.
--
http://mail.python.org/mailman/listinfo/python-list


newsboost at gmail

Apr 29, 2012, 5:59 PM

Post #6 of 47 (1653 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 04/30/2012 02:38 AM, Nasser M. Abbasi wrote:
> On 04/29/2012 05:17 PM, someone wrote:
>
>> I would also kindly ask about how to avoid this problem in
>> the future, I mean, this maybe means that I have to check the condition
>> number at all times before doing anything at all ? How to do that?
>>
>
> I hope you'll check the condition number all the time.

So how big can it (cond-number) be before I should do something else?
And what to do then? Cramers rule or pseudoinverse or something else?

> You could be designing a building where people will live in it.
>
> If do not check the condition number, you'll end up with a building that
> will fall down when a small wind hits it and many people will die all
> because you did not bother to check the condition number when you solved
> the equations you used in your design.
>
> Also, as was said, do not use INV(A) directly to solve equations.

In Matlab I used x=A\b.

I used inv(A) in python. Should I use some kind of pseudo-inverse or
what do you suggest?



--
http://mail.python.org/mailman/listinfo/python-list


nma at 12000

Apr 29, 2012, 6:35 PM

Post #7 of 47 (1650 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 04/29/2012 07:59 PM, someone wrote:

>>
>> Also, as was said, do not use INV(A) directly to solve equations.
>
> In Matlab I used x=A\b.
>

good.

> I used inv(A) in python. Should I use some kind of pseudo-inverse or
> what do you suggest?
>

I do not use python much myself, but a quick google showed that pyhton
scipy has API for linalg, so use, which is from the documentation, the
following code example

X = scipy.linalg.solve(A, B)

But you still need to check the cond(). If it is too large, not good.
How large and all that, depends on the problem itself. But the rule of
thumb, the lower the better. Less than 100 can be good in general, but I
really can't give you a fixed number to use, as I am not an expert in
this subjects, others who know more about it might have better
recommendations.

--Nasser



--
http://mail.python.org/mailman/listinfo/python-list


nma at 12000

Apr 29, 2012, 6:50 PM

Post #8 of 47 (1653 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 04/29/2012 07:17 PM, someone wrote:

> Ok. When do you define it to be singular, btw?
>

There are things you can see right away about a matrix A being singular
without doing any computation. By just looking at it.

For example, If you see a column (or row) being a linear combination of
other column(s) (or row(s)) then this is a no no.

In your case you have

1 2 3
11 12 13
21 22 23

You can see right away that if you multiply the second row by 2, and
subtract from that one times the first row, then you obtain the third row.

Hence the third row is a linear combination of the first row and the
second row. no good.

When you get a row (or a column) being a linear combination of others
rows (or columns), then this means the matrix is singular.

--Nasser
--
http://mail.python.org/mailman/listinfo/python-list


kiuhnm03.4t.yahoo.it at mail

Apr 30, 2012, 3:37 AM

Post #9 of 47 (1656 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 4/30/2012 2:17, someone wrote:
> On 04/30/2012 12:39 AM, Kiuhnm wrote:
>
>>> So Matlab at least warns about "Matrix is close to singular or badly
>>> scaled", which python (and I guess most other languages) does not...
>>
>> A is not just close to singular: it's singular!
>
> Ok. When do you define it to be singular, btw?
>
>>> Which is the most accurate/best, even for such a bad matrix? Is it
>>> possible to say something about that? Looks like python has a lot more
>>> digits but maybe that's just a random result... I mean.... Element 1,1 =
>>> 2.81e14 in Python, but something like 3e14 in Matlab and so forth -
>>> there's a small difference in the results...
>>
>> Both results are *wrong*: no inverse exists.
>
> What's the best solution of the two wrong ones? Best least-squares
> solution or whatever?

Trust me. They're both so wrong that it doesn't matter.
Have a look at A*inv(A) and inv(A)*A and you'll see by yourself.

>>> With python, I would also kindly ask about how to avoid this problem in
>>> the future, I mean, this maybe means that I have to check the condition
>>> number at all times before doing anything at all ? How to do that?
>>
>> If cond(A) is high, you're trying to solve your problem the wrong way.
>
> So you're saying that in another language (python) I should check the
> condition number, before solving anything?

Yes, unless you already know that it will always be low by design.

>> You should try to avoid matrix inversion altogether if that's the case.
>> For instance you shouldn't invert a matrix just to solve a linear system.
>
> What then?

Look at the documentation of the library you're using.

> Cramer's rule?

Surprisingly, yes. That's an option. See
"A condensation-based application of Cramerʼs rule for solving
large-scale linear systems"
Popular linear codes are based on Gaussian elimination or some iterative
method, though.

Kiuhnm
--
http://mail.python.org/mailman/listinfo/python-list


kiuhnm03.4t.yahoo.it at mail

Apr 30, 2012, 3:48 AM

Post #10 of 47 (1644 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 4/30/2012 3:35, Nasser M. Abbasi wrote:
> But you still need to check the cond(). If it is too large, not good.
> How large and all that, depends on the problem itself. But the rule of
> thumb, the lower the better. Less than 100 can be good in general, but I
> really can't give you a fixed number to use, as I am not an expert in
> this subjects, others who know more about it might have better
> recommendations.

Alas, there's no fixed number and as if that wasn't enough, there are
many condition numbers, each one with different properties. For
instance, the Skeel condition number is scale-invariant and it's useful
when a matrix is ill-conditioned just because its rows are out of scale.

Kiuhnm
--
http://mail.python.org/mailman/listinfo/python-list


russ.paielli at gmail

Apr 30, 2012, 11:56 PM

Post #11 of 47 (1648 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On Apr 29, 5:17 pm, someone <newsbo...@gmail.com> wrote:
> On 04/30/2012 12:39 AM, Kiuhnm wrote:
>
> >> So Matlab at least warns about "Matrix is close to singular or badly
> >> scaled", which python (and I guess most other languages) does not...
>
> > A is not just close to singular: it's singular!
>
> Ok. When do you define it to be singular, btw?
>
> >> Which is the most accurate/best, even for such a bad matrix? Is it
> >> possible to say something about that? Looks like python has a lot more
> >> digits but maybe that's just a random result... I mean.... Element 1,1 =
> >> 2.81e14 in Python, but something like 3e14 in Matlab and so forth -
> >> there's a small difference in the results...
>
> > Both results are *wrong*: no inverse exists.
>
> What's the best solution of the two wrong ones? Best least-squares
> solution or whatever?
>
> >> With python, I would also kindly ask about how to avoid this problem in
> >> the future, I mean, this maybe means that I have to check the condition
> >> number at all times before doing anything at all ? How to do that?
>
> > If cond(A) is high, you're trying to solve your problem the wrong way.
>
> So you're saying that in another language (python) I should check the
> condition number, before solving anything?
>
> > You should try to avoid matrix inversion altogether if that's the case.
> > For instance you shouldn't invert a matrix just to solve a linear system.
>
> What then?
>
> Cramer's rule?

If you really want to know just about everything there is to know
about a matrix, take a look at its Singular Value Decomposition (SVD).
I've never used numpy, but I assume it can compute an SVD.
--
http://mail.python.org/mailman/listinfo/python-list


hoogendoorn.eelco at gmail

May 1, 2012, 6:26 AM

Post #12 of 47 (1648 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

There is linalg.pinv, which computes a pseudoinverse based on SVD that
works on all matrices, regardless of the rank of the matrix. It merely
approximates A*A.I = I as well as A permits though, rather than being
a true inverse, which may not exist.

Anyway, there are no general answers for this kind of thing. In all
non-textbook problems I can think of, the properties of your matrix
are highly constrained by the problem you are working on; which
additional tests are required to check for corner cases thus depends
on the problem. Often, if you have found an elegant solution to your
problem, no such corner cases exist. In that case, MATLAB is just
wasting your time with its automated checks.
--
http://mail.python.org/mailman/listinfo/python-list


newsboost at gmail

May 1, 2012, 11:43 AM

Post #13 of 47 (1644 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 04/30/2012 02:57 AM, Paul Rubin wrote:
> someone<newsboost [at] gmail> writes:
>>> A is not just close to singular: it's singular!
>> Ok. When do you define it to be singular, btw?
>
> Singular means the determinant is zero, i.e. the rows or columns
> are not linearly independent. Let's give names to the three rows:
>
> a = [1 2 3]; b = [11 12 13]; c = [21 22 23].
>
> Then notice that c = 2*b - a. So c is linearly dependent on a and b.
> Geometrically this means the three vectors are in the same plane,
> so the matrix doesn't have an inverse.

Oh, thak you very much for a good explanation.

>>>> Which is the most accurate/best, even for such a bad matrix?
>
> What are you trying to do? If you are trying to calculate stuff
> with matrices, you really should know some basic linear algebra.

Actually I know some... I just didn't think so much about, before
writing the question this as I should, I know theres also something like
singular value decomposition that I think can help solve otherwise
illposed problems, although I'm not an expert like others in this forum,
I know for sure :-)
--
http://mail.python.org/mailman/listinfo/python-list


newsboost at gmail

May 1, 2012, 11:49 AM

Post #14 of 47 (1647 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 05/01/2012 08:56 AM, Russ P. wrote:
> On Apr 29, 5:17 pm, someone<newsbo...@gmail.com> wrote:
>> On 04/30/2012 12:39 AM, Kiuhnm wrote:
>>> You should try to avoid matrix inversion altogether if that's the case.
>>> For instance you shouldn't invert a matrix just to solve a linear system.
>>
>> What then?
>>
>> Cramer's rule?
>
> If you really want to know just about everything there is to know
> about a matrix, take a look at its Singular Value Decomposition (SVD).

I know a bit about SVD - I used it for a short period of time in Matlab,
though I'm definately not an expert in it and I don't understand the
whole theory with orthogality behind making it work so elegant as it
is/does work out.

> I've never used numpy, but I assume it can compute an SVD.

I'm making my first steps now with numpy, so there's a lot I don't know
and haven't tried with numpy...


--
http://mail.python.org/mailman/listinfo/python-list


newsboost at gmail

May 1, 2012, 11:52 AM

Post #15 of 47 (1639 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote:
> On 04/29/2012 07:59 PM, someone wrote:
> I do not use python much myself, but a quick google showed that pyhton
> scipy has API for linalg, so use, which is from the documentation, the
> following code example
>
> X = scipy.linalg.solve(A, B)
>
> But you still need to check the cond(). If it is too large, not good.
> How large and all that, depends on the problem itself. But the rule of
> thumb, the lower the better. Less than 100 can be good in general, but I
> really can't give you a fixed number to use, as I am not an expert in
> this subjects, others who know more about it might have better
> recommendations.

Ok, that's a number...

Anyone wants to participate and do I hear something better than "less
than 100 can be good in general" ?

If I don't hear anything better, the limit is now 100...

What's the limit in matlab (on the condition number of the matrices), by
the way, before it comes up with a warning ???



--
http://mail.python.org/mailman/listinfo/python-list


ramit.prasad at jpmorgan

May 1, 2012, 12:04 PM

Post #16 of 47 (1645 views)
Permalink
RE: numpy (matrix solver) - python vs. matlab [In reply to]

>I'm making my first steps now with numpy, so there's a lot I don't know
>and haven't tried with numpy...

An excellent reason to subscribe to the numpy mailing list and
talk on there :)

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list


cjw at ncf

May 1, 2012, 12:59 PM

Post #17 of 47 (1643 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 01/05/2012 2:43 PM, someone wrote:
[snip]
>> a = [1 2 3]; b = [11 12 13]; c = [21 22 23].
>>
>> Then notice that c = 2*b - a. So c is linearly dependent on a and b.
>> Geometrically this means the three vectors are in the same plane,
>> so the matrix doesn't have an inverse.
>

Does it not mean that there are three parallel planes?

Consider the example in two dimensional space.

Colin W.
[snip]
--
http://mail.python.org/mailman/listinfo/python-list


russ.paielli at gmail

May 1, 2012, 1:54 PM

Post #18 of 47 (1639 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On May 1, 11:52 am, someone <newsbo...@gmail.com> wrote:
> On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote:
>
> > On 04/29/2012 07:59 PM, someone wrote:
> > I do not use python much myself, but a quick google showed that pyhton
> > scipy has API for linalg, so use, which is from the documentation, the
> > following code example
>
> > X = scipy.linalg.solve(A, B)
>
> > But you still need to check the cond(). If it is too large, not good.
> > How large and all that, depends on the problem itself. But the rule of
> > thumb, the lower the better. Less than 100 can be good in general, but I
> > really can't give you a fixed number to use, as I am not an expert in
> > this subjects, others who know more about it might have better
> > recommendations.
>
> Ok, that's a number...
>
> Anyone wants to participate and do I hear something better than "less
> than 100 can be good in general" ?
>
> If I don't hear anything better, the limit is now 100...
>
> What's the limit in matlab (on the condition number of the matrices), by
> the way, before it comes up with a warning ???

The threshold of acceptability really depends on the problem you are
trying to solve. I haven't solved linear equations for a long time,
but off hand, I would say that a condition number over 10 is
questionable.

A high condition number suggests that the selection of independent
variables for the linear function you are trying to fit is not quite
right. For a poorly conditioned matrix, your modeling function will be
very sensitive to measurement noise and other sources of error, if
applicable. If the condition number is 100, then any input on one
particular axis gets magnified 100 times more than other inputs.
Unless your inputs are very precise, that is probably not what you
want.

Or something like that.
--
http://mail.python.org/mailman/listinfo/python-list


newsboost at gmail

May 1, 2012, 2:18 PM

Post #19 of 47 (1643 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 05/01/2012 09:59 PM, Colin J. Williams wrote:
> On 01/05/2012 2:43 PM, someone wrote:
> [snip]
>>> a = [1 2 3]; b = [11 12 13]; c = [21 22 23].
>>>
>>> Then notice that c = 2*b - a. So c is linearly dependent on a and b.
>>> Geometrically this means the three vectors are in the same plane,
>>> so the matrix doesn't have an inverse.
>>
>
> Does it not mean that there are three parallel planes?
>
> Consider the example in two dimensional space.

I actually drawed it and saw it... It means that you can construct a 2D
plane and all 3 vectors are in this 2D-plane...
--
http://mail.python.org/mailman/listinfo/python-list


newsboost at gmail

May 1, 2012, 2:21 PM

Post #20 of 47 (1645 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 05/01/2012 10:54 PM, Russ P. wrote:
> On May 1, 11:52 am, someone<newsbo...@gmail.com> wrote:
>> On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote:

>> What's the limit in matlab (on the condition number of the matrices), by
>> the way, before it comes up with a warning ???
>
> The threshold of acceptability really depends on the problem you are
> trying to solve. I haven't solved linear equations for a long time,
> but off hand, I would say that a condition number over 10 is
> questionable.

Anyone knows the threshold for Matlab for warning when solving x=A\b ? I
tried "edit slash" but this seems to be internal so I cannot see what
criteria the warning is based upon...

> A high condition number suggests that the selection of independent
> variables for the linear function you are trying to fit is not quite
> right. For a poorly conditioned matrix, your modeling function will be
> very sensitive to measurement noise and other sources of error, if
> applicable. If the condition number is 100, then any input on one
> particular axis gets magnified 100 times more than other inputs.
> Unless your inputs are very precise, that is probably not what you
> want.
>
> Or something like that.

Ok. So it's like a frequency-response-function, output divided by input...
--
http://mail.python.org/mailman/listinfo/python-list


robert.kern at gmail

May 1, 2012, 2:45 PM

Post #21 of 47 (1644 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 5/1/12 10:21 PM, someone wrote:
> On 05/01/2012 10:54 PM, Russ P. wrote:
>> On May 1, 11:52 am, someone<newsbo...@gmail.com> wrote:
>>> On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote:
>
>>> What's the limit in matlab (on the condition number of the matrices), by
>>> the way, before it comes up with a warning ???
>>
>> The threshold of acceptability really depends on the problem you are
>> trying to solve. I haven't solved linear equations for a long time,
>> but off hand, I would say that a condition number over 10 is
>> questionable.
>
> Anyone knows the threshold for Matlab for warning when solving x=A\b ? I tried
> "edit slash" but this seems to be internal so I cannot see what criteria the
> warning is based upon...

The documentation for that operator is here:

http://www.mathworks.co.uk/help/techdoc/ref/mldivide.html

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


kiuhnm03.4t.yahoo.it at mail

May 1, 2012, 3:04 PM

Post #22 of 47 (1651 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 5/1/2012 21:59, Colin J. Williams wrote:
> On 01/05/2012 2:43 PM, someone wrote:
> [snip]
>>> a = [1 2 3]; b = [11 12 13]; c = [21 22 23].
>>>
>>> Then notice that c = 2*b - a. So c is linearly dependent on a and b.
>>> Geometrically this means the three vectors are in the same plane,
>>> so the matrix doesn't have an inverse.
>>
>
> Does it not mean that there are three parallel planes?

They're not parallel because our matrix has rank 2, not 1.

Anyway, have a look at this:
http://en.wikipedia.org/wiki/Parallelepiped#Volume
It follows that our matrix A whose rows are a, b and c represents a
parallelepiped. If our vectors are collinear or coplanar, the
parallelepiped is degenerate, i.e. has volume 0. The converse is also true.

Kiuhnm
--
http://mail.python.org/mailman/listinfo/python-list


no.email at nospam

May 1, 2012, 4:05 PM

Post #23 of 47 (1650 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

someone <newsboost [at] gmail> writes:
> Actually I know some... I just didn't think so much about, before
> writing the question this as I should, I know theres also something
> like singular value decomposition that I think can help solve
> otherwise illposed problems,

You will probably get better advice if you are able to describe what
problem (ill-posed or otherwise) you are actually trying to solve. SVD
just separates out the orthogonal and scaling parts of the
transformation induced by a matrix. Whether that is of any use to you
is unclear since you don't say what you're trying to do.
--
http://mail.python.org/mailman/listinfo/python-list


russ.paielli at gmail

May 1, 2012, 4:38 PM

Post #24 of 47 (1644 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On May 1, 4:05 pm, Paul Rubin <no.em...@nospam.invalid> wrote:
> someone <newsbo...@gmail.com> writes:
> > Actually I know some... I just didn't think so much about, before
> > writing the question this as I should, I know theres also something
> > like singular value decomposition that I think can help solve
> > otherwise illposed problems,
>
> You will probably get better advice if you are able to describe what
> problem (ill-posed or otherwise) you are actually trying to solve.  SVD
> just separates out the orthogonal and scaling parts of the
> transformation induced by a matrix.  Whether that is of any use to you
> is unclear since you don't say what you're trying to do.

I agree with the first sentence, but I take slight issue with the word
"just" in the second. The "orthogonal" part of the transformation is
non-distorting, but the "scaling" part essentially distorts the space.
At least that's how I think about it. The larger the ratio between the
largest and smallest singular value, the more distortion there is. SVD
may or may not be the best choice for the final algorithm, but it is
useful for visualizing the transformation you are applying. It can
provide clues about the quality of the selection of independent
variables, state variables, or inputs.
--
http://mail.python.org/mailman/listinfo/python-list


newsboost at gmail

May 1, 2012, 11:00 PM

Post #25 of 47 (1642 views)
Permalink
Re: numpy (matrix solver) - python vs. matlab [In reply to]

On 05/02/2012 01:05 AM, Paul Rubin wrote:
> someone<newsboost [at] gmail> writes:
>> Actually I know some... I just didn't think so much about, before
>> writing the question this as I should, I know theres also something
>> like singular value decomposition that I think can help solve
>> otherwise illposed problems,
>
> You will probably get better advice if you are able to describe what
> problem (ill-posed or otherwise) you are actually trying to solve. SVD

I don't understand what else I should write. I gave the singular matrix
and that's it. Nothing more is to say about this problem, except it
would be nice to learn some things for future use (for instance
understanding SVD more - perhaps someone geometrically can explain SVD,
that'll be really nice, I hope)...

> just separates out the orthogonal and scaling parts of the
> transformation induced by a matrix. Whether that is of any use to you
> is unclear since you don't say what you're trying to do.

Still, I dont think I completely understand SVD. SVD (at least in
Matlab) returns 3 matrices, one is a diagonal matrix I think. I think I
would better understand it with geometric examples, if one would be so
kind to maybe write something about that... I can plot 3D vectors in
matlab, very easily so maybe I better understand SVD if I hear/read the
geometric explanation (references to textbook/similar is also appreciated).
--
http://mail.python.org/mailman/listinfo/python-list

First page Previous page 1 2 Next page Last page  View All Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.