# How to define a function based on the output of DSolve? [duplicate]

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?

-

## marked as duplicate by Kuba, Sjoerd C. de Vries, m_goldberg, R. M.♦Jul 23 '13 at 14:32

+1 just for posting the question Nbr 9000 – Dr. belisarius Jul 22 '13 at 22:16
@belisarius ...!#@*(&@#^% – R. M. Jul 22 '13 at 22:22
@rm-rf Do you need some help? – Dr. 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. – R. M. Jul 23 '13 at 14:32
– R. M. Jul 23 '13 at 14:33

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}]


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


etc...

-

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.

-