# 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 == x0, x' == 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 == x0, x' == 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?

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 == x0, x' == 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= 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 == x0, x' == 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.