Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem with numerical values in Solve/NSolve

0 views
Skip to first unread message

Jacob Grose

unread,
Jan 12, 2006, 3:27:25 AM1/12/06
to
Hello,

I writing a physics simulation and I need to solve a system of 41 equations. However, I am having problems even with a more simple 5x5 matrix. The problem is as follows: If I symbolically solve the matrix m1:

\!\(\*
TagBox[
RowBox[{"(", "\[NoBreak]", GridBox[{
{\(\(-a\) - b - c\), "0", "f", "h", "l"},
{"0", \(\(-c\) - d - e\), "g", "k", "m"},
{"a", "c", \(\(-f\) - g\), "0", "0"},
{"b", "d", "0", \(\(-h\) - k\), "0"},
{"c", "e", "0", "0", \(\(-l\) - m\)}
}], "\[NoBreak]", ")"}],
Function[ BoxForm`e$,
MatrixForm[ BoxForm`e$]]]\)

Using the code:

variables = Array[p, 5];
evec = Simplify[Solve[m1.variables \[Equal] Table[0, {i, 1, 5}], Array[p, 4]]]

I get a result. However, if I try to solve for a matrix (m) of the same form but with values substituted for the variables:

\!\(\*
TagBox[
RowBox[{"(", "\[NoBreak]", GridBox[{
{\(-1.870413280501348`*^10\),
"0", "1.7479373054791087`*^8", "
7.607967609656633`*^9", "2.5605854781972427`*^7"},
{"0
", \(-1.2870235495030115`*^10\), "206293.3885126606`", \
"8.754725514677356`*^7", "1.3554510956434595`*^10"},
{"1.747937063721231`*^10", "2.062933885126606`*^7
", \(-1.7500002393642354`*^8\), "0", "0"},
{"1.2247621677975328`*^9", "8.754722967399057`*^9", "0", \
\(-7.695514864803407`*^9\), "0"},
{"0.0036402209477187386`", "4.094883188779791`*^9", "0", "0", \
\(-1.3580116811216568`*^10\)}
}], "\[NoBreak]", ")"}],
Function[ BoxForm`e$,
MatrixForm[ BoxForm`e$]]]\)

Using the same code:

variables = Array[p, 5];
evec = Simplify[Solve[m.variables \[Equal] Table[0, {i, 1, 5}], Array[p, 4]]]

mathematica returns: {}.

I tried using Nsolve instead of solve, as well as setting $MaxExtraPrecision = 5000, but it didn't help. Any ideas?

Thanks,
Jacob

Peter Pein

unread,
Jan 13, 2006, 4:51:08 AM1/13/06
to
Hello Jacob,

you might want to try

NullSpace[m1]
-->
{{0.010011241314340086, 0.00003981968052280508, 0.9999485428023668,
0.0016386167927237756, 0.00001200703518667599}}

Peter

Jacob Grose schrieb:

dh

unread,
Jan 13, 2006, 4:54:09 AM1/13/06
to
Hello Jacob,
the problem you face is that the variables in the equation and in Solve
are not identical.
Either you solve for all variables like:

variables = Array[p, 5];

evec = Simplify[Solve[m.variables == Table[0, {i, 1, 5}], variables]]

or you have to tell Mathematica to eliminate the unwanted variable:


variables = Array[p, 5];

evec = Simplify[Solve[m2.variables == Table[0, {i, 1, 5}], Array[p,
4],p[5]]]

Daniel

Jacob Grose

unread,
Jan 13, 2006, 5:05:19 AM1/13/06
to
As a number of people suggested to me via e-mail, using NullSpace solves my problem.

Thanks to all,
Jacob

Jean-Marc Gulliet

unread,
Jan 13, 2006, 5:14:35 AM1/13/06
to
Hi Jacob,

According to Mathematica online documentation, "Solve gives {} if there
are no possible solutions to the equations."

Since some elements of m1 depend on the values of the others, have you
checked that the matrix m satisfies these requirements?

For example,

In[1]:=
m1 = {{-a - b - c, 0, f, h, l}, {0, -c - d - e, g, k, m},
{a, c, -f - g, 0, 0}, {b, d, 0, -h - k, 0}, {c, e, 0, 0, -l - m}};

In[2]:=
m2 = m1 /. {a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7, h -> 8,
i -> 9, j -> 10, k -> 11, l -> 12, m -> 13}

Out[2]=
{{-6, 0, 6, 8, 12}, {0, -12, 7, 11, 13}, {1, 3, -13, 0, 0},
{2, 4, 0, -19, 0}, {3, 5, 0, 0, -25}}

In[3]:=


variables = Array[p, 5];

evec = Simplify[Solve[m2 . variables == Table[0, {i, 1, 5}], Array[p, 4]]]

Out[4]=
{{p[1] -> (1535*p[5])/367, p[2] -> (914*p[5])/367, p[3] -> (329*p[5])/367,
p[4] -> (354*p[5])/367}}

In[5]:=
m3 = m2 /. -25 -> 25

Out[5]=
{{-6, 0, 6, 8, 12}, {0, -12, 7, 11, 13}, {1, 3, -13, 0, 0},
{2, 4, 0, -19, 0}, {3, 5, 0, 0, 25}}

In[6]:=


variables = Array[p, 5];

evec = Simplify[Solve[m3 . variables == Table[0, {i, 1, 5}], Array[p, 4]]]

Out[7]=
{}

Best regards,
/J.M.

Bob Hanlon

unread,
Jan 13, 2006, 5:15:36 AM1/13/06
to
m1={{-a-b-c,0,f,h,l},{0,-c-d-e,g,k,m},
{a,c,-f-g,0,0},{b,d,0,-h-k,0},{c,e,0,0,-l-m}};

variables=Array[p,5];
eqn=Thread[m1.variables==0];
evec=Simplify[Flatten[Solve[eqn,Most[variables]]]];

And@@Simplify[eqn/.evec]

True

m2=Rationalize[{
{-1.870413280501348*^10,0,1.7479373054791087*^8,
7.607967609656633*^9,2.5605854781972427*^7},
{0,-1.2870235495030115*^10,206293.3885126606,
8.754725514677356*^7,1.3554510956434595*^10},
{1.747937063721231*^10,2.062933885126606*^7,
-1.7500002393642354*^8,0,0},
{1.2247621677975328*^9,8.754722967399057*^9,
0,-7.695514864803408*^9,0},
{0.0036402209477187386,4.094883188779791*^9,
0,0,-1.3580116811216568*^10}},
0];

Reduce[Thread[m2.variables==0],Most[variables]]

p[5] == 0 && p[1] == 0 && p[2] == 0 && p[3] == 0 && p[4] == 0


Bob Hanlon

Valeri Astanoff

unread,
Jan 13, 2006, 5:22:48 AM1/13/06
to
Jacob,

Seems to me that column totals should be zero for both matrices
and it's not true for the numerical matrix first column.

hth

Valeri

0 new messages