Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to get a function as output form DSolve. For Example :

sol = DSolve[{Q''[t] + 40 Q'[t] + 625 Q[t] == 100*Cos[10*t], Q[0] == 0, Q'[0] == 0}, Q[t], t]

I want to use Q[t] as a function to use in an another equation.

share|improve this question
    
Related: mathematica.stackexchange.com/q/6664/121 –  Mr.Wizard Jul 24 '12 at 13:32
    
Almost the same question: How to use results of NDsolve for further solving of ODEs? –  Jens Jul 24 '12 at 17:40
add comment

1 Answer

up vote 5 down vote accepted

It's not too hard:

dsaad[t_] = Q[t] /. First @ DSolve[{Q''[t] + 40 Q'[t] + 625 Q[t] == 100*Cos[10*t],
                                   Q[0] == 0, Q'[0] == 0}, Q, t]

Notes:

  1. I instructed DSolve[] to return the pure function Q (through the second argument) instead of the function itself to ease the replacement.

  2. I used Set[] (=) instead of SetDelayed[] (:=), so that the replacement is done at once before the definition takes place.


Another possibility is to use DifferentialRoot[] instead:

dsaad[x_] := DifferentialRoot[Function[{Q, t},
               {Q''[t] + 40 Q'[t] + 625 Q[t] == 100*Cos[10*t], Q[0] == 0, Q'[0] == 0}]][x]
share|improve this answer
    
I understand all of it but I didn't get the "First". What does it? –  DSaad Jul 24 '12 at 14:28
    
@DSaad The First is meant to extract the solution as it is returned by Mathematica as a List of List. –  PlatoManiac Jul 24 '12 at 15:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.