Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: NSolve output
Replies: 7   Last Post: Jan 18, 2013 12:50 AM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Trichy V. Krishnan Posts: 8 Registered: 11/22/12
Re: NSolve output
Posted: Jan 18, 2013 12:50 AM
 Plain Text Reply

I am sorry; you are right. It also works. It took a few seconds and I sort of thought it just stopped working. Thanks again.

trichy

-----Original Message-----
From: Bob Hanlon [mailto:hanlonr357@gmail.com]
Sent: Thursday, January 17, 2013 12:14 PM
Subject: Re: NSolve output

All work on my system with Mathematica v8

\$Version

"8.0 for Mac OS X x86 (64-bit) (October 5, 2011)"

Clear[s1, s2];

dpi1s1 = Rationalize[
0.3125 - 0.0645 s1^2 + 0.0083205 s1^3 + 0.125 s2^2 +
s1 (-0.26 + (-0.03225 + 0.0645 s2) s2), 0];

dpi2s2 = Rationalize[
0.3125 + s2 (-2.4375 + (-0.25 + 0.0645 s1) s1 + (-0.375 + 0.5 s2) s2), 0];

The easiest way is to just add the constraints

soln1 = NSolve[{dpi1s1 == 0, dpi2s2 == 0, 0 < s1 < 1, 0 < s2 < 1}, {s1,
s2}][[1]]

{s1 -> 0.986758, s2 -> 0.117545}

soln2 = Solve[{dpi1s1 == 0, dpi2s2 == 0, 0 < s1 < 1, 0 < s2 < 1}, {s1,
s2}][[1]] // N

{s1 -> 0.986758, s2 -> 0.117545}

soln3 = Reduce[{dpi1s1 == 0, dpi2s2 == 0, 0 < s1 < 1, 0 < s2 < 1}, {s1, s2},
Backsubstitution -> True] // N // ToRules

{s1 -> 0.986758, s2 -> 0.117545}

Alternatively,

soln4 = Select[NSolve[{dpi1s1 == 0, dpi2s2 == 0}, {s1, s2}],
And @@ Thread[0 < {s1, s2} < 1] /. # &][[1]]

{s1 -> 0.986758, s2 -> 0.117545}

soln5 = Cases[
NSolve[{dpi1s1 == 0, dpi2s2 == 0}, {s1,
s2}], _?(And @@ Thread[0 < {s1, s2} < 1] /. # &)][[1]]

{s1 -> 0.986758, s2 -> 0.117545}

Bob Hanlon

On Wed, Jan 16, 2013 at 1:35 AM, Trichy V. Krishnan <biztvk@nus.edu.sg> wrote:
> Just for your information...
>
> The following didn't work (I am using version 8):
> soln1 = NSolve[{dpi1s1 == 0, dpi2s2 == 0, 0 < s1 < 1, 0 < s2 < 1},
> {s1, s2}][[1]]
>
> The following works well.
> soln4 = Select[NSolve[{dpi1s1 == 0, dpi2s2 == 0}, {s1, s2}], And @@
> Thread[0 < {s1, s2} < 1] /. # &][[1]]
>
> Thanks a lot again.
>
> trichy
>
>
>
> -----Original Message-----
> From: Trichy V. Krishnan [mailto:biztvk@nus.edu.sg]
> Sent: Tuesday, January 15, 2013 12:29 PM
> To: mathgroup@smc.vnet.net
> Subject: Re: NSolve output
>
> Wow... thanks.
>
> trichy
>
> -----Original Message-----
> From: Bob Hanlon [mailto:hanlonr357@gmail.com]
> Sent: Tuesday, January 15, 2013 4:43 AM
> To: Trichy V. Krishnan
> Cc: mathgroup@smc.vnet.net
> Subject: Re: NSolve output
>
> Clear[s1, s2];
>
> dpi1s1 = Rationalize[
> 0.3125 - 0.0645 s1^2 + 0.0083205 s1^3 + 0.125 s2^2 +
> s1 (-0.26 + (-0.03225 + 0.0645 s2) s2), 0];
>
> dpi2s2 = Rationalize[
> 0.3125 + s2 (-2.4375 + (-0.25 + 0.0645 s1) s1 +
> (-0.375 + 0.5 s2) s2), 0];
>
> The easiest way is to just add the constraints
>
> soln1 = NSolve[
> {dpi1s1 == 0, dpi2s2 == 0, 0 < s1 < 1, 0 < s2 < 1},
> {s1, s2}][[1]]
>
> {s1 -> 0.986758, s2 -> 0.117545}
>
> soln2 = Solve[
> {dpi1s1 == 0, dpi2s2 == 0, 0 < s1 < 1, 0 < s2 < 1},
> {s1, s2}][[1]] // N
>
> {s1 -> 0.986758, s2 -> 0.117545}
>
> soln3 = Reduce[
> {dpi1s1 == 0, dpi2s2 == 0, 0 < s1 < 1, 0 < s2 < 1},
> {s1, s2},
> Backsubstitution -> True] // N // ToRules
>
> {s1 -> 0.986758, s2 -> 0.117545}
>
> Alternatively,
>
> soln4 = Select[NSolve[
> {dpi1s1 == 0, dpi2s2 == 0}, {s1, s2}],
> And @@ Thread[0 < {s1, s2} < 1] /. # &][[1]]
>
> {s1 -> 0.986758, s2 -> 0.117545}
>
> soln5 = Cases[NSolve[
> {dpi1s1 == 0, dpi2s2 == 0}, {s1, s2}],
> _?(And @@ Thread[0 < {s1, s2} < 1] /. # &)][[1]]
>
> {s1 -> 0.986758, s2 -> 0.117545}
>
>
> Bob Hanlon
>
>
> On Mon, Jan 14, 2013 at 1:34 PM, Trichy V. Krishnan
> <biztvk@nus.edu.sg> wro= =
> te:

>> Hi:
>>
>> I have a simultaneous set of equations in two variables, namely, s1
>> and s=

> 2. See below.
>>
>> s1 =.; s2 =.; dpi1s1 =.; dpi2s2 =.;
>> dpi1s1 = 0.3125 - 0.0645 s1^2 + 0.0083205 s1^3 + 0.125 s2^2 +
>> s1 (-0.26 + (-0.03225 + 0.0645 s2) s2);
>> dpi2s2 = 0.3125 +
>> s2 (-2.4375 + (-0.25 + 0.0645 s1) s1 + (-0.375 + 0.5 s2) s2);
>>
>>
>> NSolve yields 7 pairs but I want to pick the pair(s) where both s1
>> and s2=

> are in (0, 1) domain. I am using a laborious method as follow, but
> can I g= = et this in one step? Thanks.

>>
>> trichy
>>
>> soln = NSolve[dpi1s1 == 0 && dpi2s2 == 0, {s1, s2}, Reals]; li=

s=
> =
> t =

>> {s1, s2} /. soln;
>> list1 = {{0, 0}};
>> Do[If[list[[i, 1]] > 0,
>> If[list[[i, 1]] < 1, If[list[[i, 2]] > 0, If[list[[i, 2]] < 1,
>> list1[[1, 1]] = list[[i, 1] ]]]]], {i, Length[list]}];
>> Do[If[list[[i, 1]] > 0,
>> If[list[[i, 1]] < 1, If[list[[i, 2]] > 0, If[list[[i, 2]] < 1,
>> list1[[1, 2]] = list[[i, 2] ]]]]], {i, Length[list]}];
>> s1 = list1[[1, 1]]; s2 = list1[[1, 2]]; {s1, s2}
>>
>>
>>
>>
>>
>>
>> -----Original Message-----
>> From: Bob Hanlon [mailto:hanlonr357@gmail.com]
>> Sent: Monday, January 14, 2013 1:01 PM
>> To: mathgroup@smc.vnet.net
>> Subject: Re: NSolve output
>>
>> \$Version
>>
>> "9.0 for Mac OS X x86 (64-bit) (November 20, 2012)"
>>
>> a = x z + 2 x y + 2 y z;
>> v = x y z;
>>
>> a2 = a /. x -> 2 z;
>> v2 = v /. x -> 2 z;
>>
>> NSolve[{a2 == 60, v2 == 40, x == 2 z, x > 0}, {x, y, z}]
>>
>> {{x -> 5.1156, y -> 3.05701, z -> 2.5578}, {x -> 7.46083,
>> y -> 1.43719, z -> 3.73042}}
>>
>>
>> Solve[{a2 == 60, v2 == 40, x == 2 z, x > 0},
>> {x, y, z}, Reals] // N
>>
>> {{x -> 5.1156, y -> 3.05701, z -> 2.5578}, {x -> 7.46083,
>> y -> 1.43719, z -> 3.73042}}
>>
>>
>> {Reduce[{a2 == 60, v2 == 40, x == 2 z, x > 0},
>> {x, y, z},
>> Backsubstitution -> True] // N // ToRules}
>>
>> {{x -> 5.1156, y -> 3.05701, z -> 2.5578}, {x -> 7.46083,
>> y -> 1.43719, z -> 3.73042}}
>>
>>
>> Bob Hanlon
>>
>>
>> On Sat, Jan 12, 2013 at 9:53 PM, Berthold Hamburger
>> <b-hamburger@artinso.=

> com> wrote:
>>> Hello,
>>>
>>> I want to solve two simple equations with NSOLVE to calculate the
>>> dimensions of a rectangular box that is open on top. The length of
>>> the box is twice the width and the volume and area of the box are
>>> respectively 40 cubic feet and 60 square feet.
>>>
>>> I defined the area and volume:
>>> a = xz + 2xy + 2yz
>>> v = xyz
>>>
>>> then substituted x with 2z:
>>>
>>> a2 = a /. x->2z
>>> v2 = v /. x->2z
>>>
>>>
>>>
>>> a2 = 6 y z + 2 z^2
>>> v2 = 2 y z^2
>>>
>>> solved with NSolve:
>>> step1 = NSolve[{a2 == 60, v2 == 40}, {y, z}, Reals] [[1,2]] /=

/=
> =
> Column

>>>
>>> which returns the results
>>> {y->3.05701,z->2.5578}
>>>
>>> I would like to get an output that returns values for all 3
>>> variables x,y,z as in
>>>
>>> {x->5.1156,y->3.05701,z->2.5578}
>>>
>>> but somehow cannot find a way to do it
>>>
>>> What would be the correct way for doing that?
>>>
>>> Regards
>>>
>>> Berthold Hamburger
>>>

>>
>
>

Date Subject Author
1/14/13 Bob Hanlon
1/14/13 Trichy V. Krishnan
1/14/13 Bob Hanlon
1/14/13 Trichy V. Krishnan
1/16/13 Trichy V. Krishnan
1/16/13 Bob Hanlon
1/18/13 Trichy V. Krishnan

© The Math Forum at NCTM 1994-2018. All Rights Reserved.