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.

This question already has an answer here:

I would like to define a function based on the output of the following DSolve call:

DSolve[{b Varx^2 - 2 b Varx x'[t] + b x'[t]^2 + m x''[t] == 0, x[0] == x0, x'[0] == V0x}, x[t], t]

I've tried to do the following:

x[t_] := DSolve[{b Varx^2 - 2 b Varx x'[t] + b x'[t]^2 + m x''[t] == 0, x[0] == x0, x'[0] == V0x}, x[t], t]

It showed the message: $RecursionLimit::reclim: Recursion depth of 256 exceeded., so I believe I'm not doing it the right.

Any ideas?

share|improve this question
    
+1 just for posting the question Nbr 9000 –  belisarius Jul 22 '13 at 22:16
1  
@belisarius ...!#@*(&@#^% –  rm -rf Jul 22 '13 at 22:22
1  
@rm-rf Do you need some help? –  belisarius Jul 22 '13 at 23:00
    
Specifically, you need the answer Using the result of functions that return replacement rules in the linked question. –  rm -rf Jul 23 '13 at 14:32
    
Also see: mathematica.stackexchange.com/q/9035/5 –  rm -rf Jul 23 '13 at 14:33
add comment

marked as duplicate by Kuba, Sjoerd C. de Vries, m_goldberg, rm -rf Jul 23 '13 at 14:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

You did not give numerical values for some of the parameters, so I made up some. For some, you might not get solutions, or get complex solution, so that is something you can look into since I do not know the physics of the problem.

Clear[x, t, b, varx, m, v0x];
y[t_] = x[t] /. First@DSolve[{b varx^2 - 2 b varx x'[t] + b x'[t]^2 + m x''[t] == 0,
      x[0] == x0, x'[0] == v0x}, x[t], t]

gives

(b t varx - m Log[m/(v0x - varx)] + m Log[b t - m/(-v0x + varx)])/b

Then you can use the function y[t]

parms = {b -> 1, varx -> 2, m -> 1, x0 -> 1, v0x -> 0};
Plot[y[t] /. parms, {t, 0, 1}]

enter image description here

D[y[t] /. parms, t]    
Out[48]= 2 + 1/(-(1/2) + t)

etc...

share|improve this answer
add comment

Following Nasser's answer, here is a minor variation:

 x[tt_, {b_, varx_, m_, x0_, v0x_}] := Module[{}, 
   x[t_, {b, varx, m, x0, v0x}] = 
     Block[{x, t}, 
       x[t] /. First@
         DSolve[{b varx^2 - 2 b varx x'[t] + b x'[t]^2 + m x''[t] == 0, 
           x[0] == x0, x'[0] == v0x}, x[t], t]
     ];
   x[tt, {b, varx, m, x0, v0x}]
 ]

Then you can evaluate it by:

parms = {1, 2, 1, 1, 0};

x[4, parms]

Plot[x[t, parms], {t, 0, 1}]

etc. Note that ODE is computed just once for each parameter vector.

share|improve this answer
add comment

Here is one more approach for the record.

x[t_] = 
  DSolve[{b Varx^2 - 2 b Varx x'[t] + b x'[t]^2 + m x''[t] == 0,
     x[0] == x0, x'[0] == V0x}, x[t], t][[1, 1, 2]]

(b t Varx + b x0 - m Log[m/(V0x - Varx)] + m Log[b t - m/(-V0x + Varx)])/b

Module[{xx}, 
 xx[t_] = With[{b = 1, Varx = 2, m = 1, x0 = 1, V0x = 0}, Evaluate@x[t]]; 
 Plot[xx[t], {t, 0, 1/2}]]

plot.png

I believe this approach has the advantage of being both efficient and easy to understand. I note that using Part to extract the solution expression is what the V9 predictive interface suggests.

share|improve this answer
add comment

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