MathGroup Archive 2005

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

Search the Archive

Re: Solve question

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

"Sterritt, Lanny" <lanny.sterritt at> wrote in message 
news:d79eqp$lcl$1 at
> 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 now has the value 3.

To do this in one step:

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

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

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 = 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 

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?