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.

Below first case which gives particular solutions of an OED correctly:

ClearAll[soln];                            (* case 1 *)
soln[a_?NumericQ] := 
soln[a] = 
DSolve[{y''[t] + y[t] == Sin[t], y[0] == a, y'[0] == 0}, y[t], 
 t];     
res1  =  Grid[
Partition[ 
Table [soln[i][[1, 1, 2]], {i, 0, 2, 1}] // FullSimplify , 1], 
 Frame -> All] 

As the OED is manipulated elsewhere in my notebook I need to rewrite the above code using an assignment for the equation:

 ClearAll[solp];                                       (* case 2 *)
 eqd := {y''[t] + y[t] == Sin[t], y[0] == a, y'[0] == 0};
 solp[a_?NumericQ] := solp[a] = DSolve[eqd, y[t], t];     
 res2  =  
 Grid[Partition[ 
 Table [solp[i][[1, 1, 2]], {i, 0, 2, 1}] // FullSimplify , 1], 
 Frame -> All]

However this time I only get the general solution with the particular solutions left unevaluated for the arbitray value "a". What's wrong here?

I checked that it is possible to use an assignement for the equation given to DSolve but after rewriting the first case like that:

solq = DSolve[eqd, y[t], t] ;                 (* case 3 *)
res3  =  Grid[
Partition[ 
Table [solq[[1, 1, 2]] /. a -> i, {i, 0, 2, 1}] // FullSimplify , 
1], Frame -> All]   
res3 == res1 

Why is it OK here and not in case 2? Thanks

share|improve this question

1 Answer 1

This may be a better way to do it:

ClearAll[solp];
(*case 2*)
eqd[a_] := {y''[t] + y[t] == Sin[t], y[0] == a, y'[0] == 0};
solp[a_?NumericQ] := solp[a] = DSolve[eqd[a], y[t], t];
res2 = Grid[
  Partition[Table[solp[i][[1, 1, 2]], {i, 0, 2, 1}] // FullSimplify, 
   1], Frame -> All]
share|improve this answer

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.