Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica 5.2

  1. Apr 28, 2007 #1


    User Avatar
    Gold Member

    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.

    Last edited: Apr 28, 2007
  2. jcsd
  3. Apr 28, 2007 #2
    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.
  4. Apr 29, 2007 #3


    User Avatar
    Gold Member

    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: Apr 29, 2007
  5. Apr 29, 2007 #4
    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.
  6. Apr 30, 2007 #5
    Try "Part" command as Part[Solve[(t - a)*(t - 4) == 0, t], 2, 1, 2]
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Mathematica Date
Mathematica Cannot do the integral of the Hyper-geometric function? Mar 11, 2018
Mathematica Cannot Plot This Function in Mathematica Feb 26, 2018
Mathematica While Loop in Mathematica Feb 25, 2018
Mathematica Mathematica Real Part Feb 24, 2018
Mathematica Polynomial expansion from Python to Mathematica Feb 20, 2018