MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NSolve problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59303] Re: [mg59283] NSolve problem
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Fri, 5 Aug 2005 01:21:30 -0400 (EDT)
  • References: <200508040608.CAA26496@smc.vnet.net> <C80CFBB8-61B4-47C0-9450-A9D60CEDE091@mimuw.edu.pl>
  • Sender: owner-wri-mathgroup at wolfram.com

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





On 4 Aug 2005, at 11:00, Andrzej Kozlowski wrote:

>
> 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
>
>
>
>
> On 4 Aug 2005, at 08:08, Enrique Zeleny wrote:
>
>
>>
>>
>> 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
>>
>>
>>
>
>


  • References:
  • Prev by Date: Re: Default defaults?
  • Next by Date: Re: pairs and subsets challenge
  • Previous by thread: NSolve problem
  • Next by thread: Re: NSolve problem