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

NSolve problem

6 views
Skip to first unread message

Enrique Zeleny

unread,
Aug 4, 2005, 2:21:59 AM8/4/05
to

Hi
I f I try to solve these equations

Solve[{2 x + 3 y == 8 + I 7,
3 x + y == 5 + 7 I, -2 I x + (1 + 3 I) y == 3 + 5 I}]

the result is

{{x -> 1 + 2*I, y -> 2 + I}}

but if I have

Solve[{2 x + 3 y == 8 + I 7,
3 x + y == 4.99999999999999 + 7 I, -2 I x + (1 + 3 I) y == 3 + 5 I}]

gives

\!\(\*FormBox[
RowBox[{\(RowReduce::"luc"\), \(\(:\)\(\ \)\), "\<\"Result for \
\\!\\(TraditionalForm\\`RowReduce\\) of badly conditioned matrix \
\\!\\(TraditionalForm\\`\\((\[NoBreak] \\(\[LeftSkeleton] 1 \
\[RightSkeleton]\\) \[NoBreak])\\)\\) may contain significant numerical \
errors. \\!\\(\\*ButtonBox[\\\"More\\\",
ButtonStyle->\\\"RefGuideLinkText\\\
\", ButtonFrame->None, ButtonData:>\\\"General::luc\\\"]\\)\"\>"}], \
TraditionalForm]\)


{}


I need only an aproximate result, say 5 digits of precission, how can I
override the NSolve behavior?


Thanks in advance

Jens-Peer Kuska

unread,
Aug 5, 2005, 1:47:01 AM8/5/05
to
Hi,

you have 3 equations and two unknowns ?? This can
only
have a solution, when one of the 3 equations is
linear
depend on one of the others.
For exact numbers Mathematica can find the linear
depend equation
for inexact numbers you will get problems with the
precision.

In your case it may be the best to remove one of
the
equations
Solve[{2 x + 3 y == 8 + I 7.,
-2 I x + (1 + 3 I) y == 3 + 5 I}, {x, y}]

Regards

Jens

"Enrique Zeleny" <eze...@fcfm.buap.mx> schrieb im
Newsbeitrag news:dcsc67$q0k$1...@smc.vnet.net...

Andrzej Kozlowski

unread,
Aug 5, 2005, 1:48:32 AM8/5/05
to

The message that you get tells you that the matrix is "badly
condition", which means that using MachinePrecision reals is
unreliable and you need to use high precision arithmetic. But, since
your system is actually overdetermined (you have a spurious
equation), even if you increase the precision your equations will
become inconsistent, and you will get an empty set of solutions (but
no message):

Solve[SetPrecision[{2*x + 3*y == 8 + I*7,
3*x + y == 4.99999999999999 + 7*I,
-2*I*x + (1 + 3*I)*y == 3 + 5*I}, 50]]


{}


There are a number of ways to deal with your problem. The most
obvious one is to just use Solve with exact input and only afterwards
apply N

N[Solve[{2*x + 3*y == 8 + I*7, 3*x + y == 5 + 7*I,
-2*I*x + (1 + 3*I)*y == 3 + 5*I}],5]


{{x -> 1.0000 + 2.0000 I, y -> 2.0000 + 1.0000 I}}


Another approach is to simply drop one of the equations:


NSolve[Drop[{2*x + 3*y == 8 + I*7,
3*x + y == 4.99999999999999 + 7*I,
-2*I*x + (1 + 3*I)*y == 3 + 5*I}, -1]]


{{x -> 0.9999999999999958 + 2.*I,
y -> 2.0000000000000027 + 1.*I}}

(Note that I used NSolve this time).


Another possibility, which you could use with a larger number of
variables and equations is to first find a GroebnerBasis for your
system and then solve the resulting new system:


NSolve[GroebnerBasis[{2*x + 3*y == 8 + I*7,
3*x + y == 5 + 7*I, -2*I*x + (1 + 3*I)*y ==
3 + 5*I} /. Equal -> Subtract, {x, y}] == 0,
{x, y}]


{{x -> 1. + 2.*I, y -> 2. + 1.*I}}


Also, note that N[Solve[eqns]] and NSolve[eqns] use different
algorithms and will not always return the same answer.

Also, if you really want 5 digits of precision you have to request it
as above or as in:

N[Solve[GroebnerBasis[{2*x + 3*y == 8 + I*7,
3*x + y == 5 + 7*I, -2*I*x + (1 + 3*I)*y ==
3 + 5*I} /. Equal -> Subtract, {x, y}] == 0,
{x, y}], 5]


{{y -> 2.0000 + 1.0000 I, x -> 1.0000 + 2.0000 I}}

Andrzej Kozlowski

Andrzej Kozlowski

unread,
Aug 5, 2005, 1:52:20 AM8/5/05
to
On second thoughts I might have misunderstood you somewhat, although
you certainly do not explain your problem clearly. It is possible
that you mean something different. Perhaps what you actually have to
begin with is a system of equations:

eqn = {2*x + 3*y == 8 + I*7, 3*x + y ==


4.99999999999999 + 7*I, -2*I*x + (1 + 3*I)*y ==
3 + 5*I}


{2 x + 3 y == 8 + 7 I, 3 x + y == 5. + 7 I,
(1 + 3 I) y - 2 I x == 3 + 5 I}


This system is inconsistent even if you use high precision arithmetic:


Solve[SetPrecision[eqn,50],{x,y}]

{}

In this particular case just rationalising the equations will give
you the answer:

In[3]:=
N[Solve[Rationalize[eqn],{x,y}],5]

Out[3]=


{{x -> 1.0000 + 2.0000 I, y -> 2.0000 + 1.0000 I}}

However, you may have an inconsistent system like this:

eq1 = {2*x + 3*y == 8 + I*7, 3*x + y == 4.9 + 7*I, -2*I*
x + (1 + 3*I)*y == 3 + 5*I};

for which rationalising will still return an empty set:


Solve[Rationalize[eqn1],{x,y}]

{}

You might however want to find a set of "solutions" for a nearby
system and treat them as solutions to your inconsistent system. This
is a more complex problem, but it can be sometimes solved by several
methods. One of them consists of peturbing slighly one of the
equations by a parameter and solving the new system:


eq2 = {2*x + 3*y == 8 + I*7, 3*x + y ==
4.9 + 7*I + epsilon, -2*I*x + (1 + 3*I)*y ==
3 + 5*I};


Solve[Rationalize[eqn1], {x, y, epsilon}]


1
{{x -> 1 + 2 I, y -> 2 + I, epsilon -> --}}
10

This shows that with one ho to find a "nearby" system which has a
solution. Of course there are going to be lots of other such systems.

Andrzej Kozlowski

Bob Hanlon

unread,
Aug 5, 2005, 1:50:03 AM8/5/05
to
Solve[Rationalize[{2 x+3 y==8+I 7,3
x+y==4.99999999999999+7 I,-2 I x+(1+3 I) y==3+5 I}]]

{{x -> 1 + 2*I, y -> 2 + I}}


Bob Hanlon

mike_in_e...@yahoo.co.uk

unread,
Aug 5, 2005, 1:57:42 AM8/5/05
to
Hi

Your system of equations has more equations than unkowns (I believe the
term for such a system is over-determined). In such a situation it is
rare for a solution to exist at all. If a solution does exist then one
of the equations is a linear combination of some of the others and so
is reduntant.

In your case the final equation -2 I x + (1 + 3 I) y == 3 + 5 I is a
linear combination of the other two and so you can discard it.

Solve[{2 x + 3 y == 8 + I 7, 3 x + y == 5 + 7 I}]

gives the same solution you had before

{{x -> 1 + 2*I, y -> 2 + I}}

Solve[{2 x + 3 y == 8 + I 7, 3 x + y == 4.9999 + 7 I}]

gives

{{x -> 0.999957142857143 + 2.*I, y -> 2.000028571428571 +
1.0000000000000002*I}}

HTH
Mike

Wonseok Shin

unread,
Aug 5, 2005, 2:09:17 AM8/5/05
to

The set of equations is composed of three equations of two unknowns.
Therefore it is basically a linearly dependent set of equations. You
can see that (3/7 + 11/7*I) * (1st equation) + (-2/7 -12/7*I) * (2nd
equation) = (3rd equation). It means solving three equations is
equivalent to solving first two equations.

If you change the RHS of second equation as you did 5 --> 4.999999, you
can't generate the 3rd equation with a combination of 1st and 2nd
equation any more, so Mathematica gives no solution.

If you want only approximate solutions, the best way is to use N[expr,
n], where 'n' means 'n-digit precision.'

Try the following:
N[Solve[{2 x + 3 y == 8 + I 7,
3 x + y == 5 + 7 I, -2 I x + (1 + 3 I) y == 3 + 5 I}], 5]

--
Wonseok Shin
wss...@gmail.com

Paul Abbott

unread,
Aug 16, 2005, 4:52:48 AM8/16/05
to
In article <dcsc67$q0k$1...@smc.vnet.net>,
Enrique Zeleny <eze...@fcfm.buap.mx> wrote:

> I f I try to solve these equations
>
> Solve[{2 x + 3 y == 8 + I 7,
> 3 x + y == 5 + 7 I, -2 I x + (1 + 3 I) y == 3 + 5 I}]
>
> the result is
>
> {{x -> 1 + 2*I, y -> 2 + I}}
>
> but if I have
>
> Solve[{2 x + 3 y == 8 + I 7,
> 3 x + y == 4.99999999999999 + 7 I, -2 I x + (1 + 3 I) y == 3 + 5 I}]

Others have explained the answer returned by Mathematica. Here is
another approach, suitable since you have linear equations.

[1] Load the LinearAlgebra stubs:

<< LinearAlgebra`

[2] Determine the matrix A, and right-hand side b:

{A, b} = LinearEquationsToMatrices[


{2*x + 3*y == 8 + I*7,

3*x + y == 4.99999999999999 + 7*I,
(1 + 3*I)*y - 2*I*x == 3 + 5*I}, {x, y}]

[3] Solve using LinearSolve:

LinearSolve[A,b]

Cheers,
Paul

--
Paul Abbott Phone: +61 8 6488 2734
School of Physics, M013 Fax: +61 8 6488 1014
The University of Western Australia (CRICOS Provider No 00126G)
AUSTRALIA http://physics.uwa.edu.au/~paul
http://InternationalMathematicaSymposium.org/IMS2005/

Paul Abbott

unread,
Aug 16, 2005, 4:53:35 AM8/16/05
to
In article <dcsc67$q0k$1...@smc.vnet.net>,
Enrique Zeleny <eze...@fcfm.buap.mx> wrote:

> I f I try to solve these equations
>
> Solve[{2 x + 3 y == 8 + I 7,
> 3 x + y == 5 + 7 I, -2 I x + (1 + 3 I) y == 3 + 5 I}]
>
> the result is
>
> {{x -> 1 + 2*I, y -> 2 + I}}
>
> but if I have
>
> Solve[{2 x + 3 y == 8 + I 7,
> 3 x + y == 4.99999999999999 + 7 I, -2 I x + (1 + 3 I) y == 3 + 5 I}]

Further to my previous posting, here is another approach:

pinv = PseudoInverse[{{2, 3}, {3, 1}, {-2 I, 1 + 3 I}}]

pinv . {8 + 7 I, 4.99999999999999 + 7 I, 3 + 5 I}

0 new messages