Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Solve question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57495] Re: Solve question
  • From: <wwolfe18 at comcast.net>
  • Date: Sun, 29 May 2005 21:00:12 -0400 (EDT)
  • References: <d79eqp$lcl$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Sterritt, Lanny" <lanny.sterritt at lmco.com> wrote in message 
news:d79eqp$lcl$1 at smc.vnet.net...
> When the Solve command is used to obtain the value of a variable in an 
> equation, something like  {x -> value}  is returned.  How does one get 
> Mathematica  to automatically apply this value to following  expressions 
> in a notebook?
>
> L.W.Sterritt

For linear equations.

Here is one way:
Solve[2x == 6,x]
{x->3}
x=x/.%[[1]]
x now has the value 3.

To do this in one step:

x = Solve[2x == 6,x][[1,1,2]]
or
x = x/.Solve[2x == 6,x][[1]]

For equations with multiple roots picking out the root you want 
automatically
is difficult. You may need to see all the roots before you assign one to x.

Solve[x^2==4,x]
{{x->-2},{x->2}}
x = x/.%[[1]]
This will set x equal to -2. Replace [[1]] with [[2]] to set x = 2.

Another approach is to name the output of Solve:
sol = Solve[x^2==4,x]
{{x->-2},{x->2}}
x = sol[[1,1,2] sets x = -2
x = sol[[2,1,2] sets x = 2

To do it all in one step:
x = Solve[x^2==4,x][[1,1,2] or x = Solve[x^2==4,x][[2,1,2]

I'm sure there are other ways to do this as well. Experiment with % and 
Part.

Warren Wolfe




  • Prev by Date: Re: global fit
  • Next by Date: Related quastions. Question 2
  • Previous by thread: Re: Solve question
  • Next by thread: sorting complex number?