Using Solve[] Function in Mathematica 5.2 - Accessing Solutions

  • Context: Mathematica 
  • Thread starter Thread starter danago
  • Start date Start date
  • Tags Tags
    Function Mathematica
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
4 replies · 6K views
danago
Gold Member
Messages
1,118
Reaction score
4
Hey. I just started using mathematica 5.2, and having a little trouble. When using the Solve[] function, the solutions are given as lists:

{{t -> a}, {t -> 4}}

In my next step of calculations, i want to use my second solution. How can i refer to it, instead of having to type it out. Now i know that if the solution was infact 4 that it would be easier to type it, but the solutions are not always as simple.

Thanks,
Dan.
 
Last edited:
Physics news on Phys.org
the short answer is:

t /. {{t -> a}, {t -> 4}}

The solution is returned in the form of a replacement rule,the " /. " should be read as "replace". (look up the functions Rule and Replace in help). Replacement rules are extremely important.

When you encounter a puzzling expression, try the function FullForm to see what its made of so you can look up the individual parts in the extensive Built-In help.
 
Ahh yes that makes sense. Thanks for that :smile:

I now have a new question. I want to solve an equation, but the solution must lie within a restricted range of values. I assumed the following would work:

Solve[ y[t]==0, t, {t,a,b}]

However, it doesnt. I had a look at the built in help browser, and wasnt able to come up with anything. What should i do?
 
Last edited:
A simple method in two lines:

rangeQ[x_] = a ≤ x ≤ b;

Select[ t/.Solve[y[t] == 0, t] , rangeQ ]

Using a pure function in one line:

Select[ t/.Solve[y[t] == 0, t] , a ≤ # ≤ b &]

This preserves them as rules, rather then values:

Select[ Solve[y[t] == 0, t] , a ≤ Last[#] ≤ b &]

Hope that helps.
 
Try "Part" command as Part[Solve[(t - a)*(t - 4) == 0, t], 2, 1, 2]