[Date Index]
[Thread Index]
[Author Index]
Re: Wrong Answer
*To*: mathgroup at smc.vnet.net
*Subject*: [mg130646] Re: Wrong Answer
*From*: Andrzej Kozlowski <akozlowski at gmail.com>
*Date*: Sun, 28 Apr 2013 01:02:20 -0400 (EDT)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*Delivered-to*: l-mathgroup@wolfram.com
*Delivered-to*: mathgroup-outx@smc.vnet.net
*Delivered-to*: mathgroup-newsendx@smc.vnet.net
*References*: <20130427030938.151746A1A@smc.vnet.net> <E9DC0958-435D-4F54-9A02-BCF756553009@mimuw.edu.pl>
Sorry, I missed the fact that you were using Mathematica 5.2. ALthough both Solve and NSolve have been considerably re-written between versions 5.2 and 9, it should not affect any issues here. Unfortunately I made a stupid mistake in the last line of my post, which lead to the suggestion that the version made a difference here. In fact:
p := (px + t vx)^4 + (py + t vy)^4 == 1
r := {px -> 0.5, py -> 0.5, vx -> 0.5, vy -> 0.5}
NSolve[p /. r, t]
{{t -> -2.68179}, {t -> -1. - 1.68179 I}, {t -> -1. +
1.68179 I}, {t -> 0.681793}}
gives the correct answer, as it should.
Andrzej Kozlowski
On 27 Apr 2013, at 09:05, Andrzej Kozlowski <akoz at mimuw.edu.pl> wrote:
> Something else is happening. You are using machine precision (approximate) input and Solve is not intended for dealing with this (NSolve is). There are two possible approaches, if you want to use Solve rather than NSolve. One is to use exact input
>
> p1 := (px + t vx)^4 + (py + t vy)^4 == 1
> r1 := {px -> 1/2, py -> 1/2, vx -> 1/2, vy -> 1/2}
>
> p1 := (px + t vx)^4 + (py + t vy)^4 == 1
> r1 := {px -> 1/2, py -> 1/2, vx -> 1/2, vy -> 1/2}
>
> Solve[p1 /. r1, t] // N
>
> {{t -> -2.68179}, {t -> -1. - 1.68179 I}, {t -> -1. +
> 1.68179 I}, {t -> 0.681793}}
>
>
> The other method to simplify the equation either by hand or using Simplify in a way that eliminates the source of numerical instability:
>
> p := (px + t vx)^4 + (py + t vy)^4 == 1
> r := {px -> 0.5, py -> 0.5, vx -> 0.5, vy -> 0.5}
>
> Solve[Simplify[p] /. r]
>
> {{t -> -2.68179}, {t -> -1. - 1.68179 I}, {t -> -1. +
> 1.68179 I}, {t -> 0.681793}}
>
>
> Finally, although NSolve is better than Solve in dealing with numerical instability, I wonder why I thought it gives the correct answer in this case:
>
> NSolve[p,t]/.r
> {{t->-1.-1.05367*10^-8 I},{t->-1.+1.05367*10^-8 =
I},{t->-1.-1.05367*10^-8 I},{t->-1.+1.05367*10^-8 I}}
>
> $Version
>
> "9.0 for Mac OS X x86 (64-bit) (January 24, 2013)"
>
>
> Are you using a different version of Mathematica?
>
>
> Andrzej Kozlowski
>
>
>
>
> On 27 Apr 2013, at 05:09, christopher arthur <chris.arthur1 at gmail.com> wrote:
>
>> Hello,
>>
>> I've discovered that Solve[] gives me the wrong answer for some
>> polynomial equations. For example, consider the following equation,
>> which should have exactly one positive, real answer for t.
>>
>> p:=(px + t vx)^4 + (py + t vy)^4==1
>> r:={px->0.5,py->0.5,vx->0.5,vy->0.5}
>> NSolve[p/.r,t]
>>
>> NSolve gives the right answers if I substitute for px,py,vx and vy
>> before solving. On the other hand, if I use Solve[] this way:
>>
>> Solve[p,t]/.r
>>
>> I get a different answer, and it's not correct.
>> Does Solve[] just malfunction with quartic polynomials or is there
>> something else happening?
>>
>> Chris
>>
>> mathematica 5.2
>>
>> Solve[p]
>>
>
**References**:
**Wrong Answer**
*From:* christopher arthur <chris.arthur1@gmail.com>
Prev by Date:
**Re: Wrong Answer**
Next by Date:
**Re: Mathematica-assisted learning was .. Re: Speak errors**
Previous by thread:
**Re: Wrong Answer**
Next by thread:
**Re: Wrong Answer**
| |