Mathematica Using Solve[] Function in Mathematica 5.2 - Accessing Solutions

AI Thread Summary
The discussion focuses on using the Solve[] function in Mathematica 5.2, specifically how to access solutions presented as lists of replacement rules. To refer to a specific solution, users can use the replacement operator " /. " to extract values from the list. For solving equations within a restricted range, users can define a range condition and apply the Select function to filter solutions accordingly. Additionally, the Part command can be utilized to access specific elements from the solution set. Understanding these functions enhances the ability to manipulate and utilize solutions effectively in Mathematica.
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]
 

Similar threads

Back
Top