I want to numerically solve a differential equation and use the resulting interpolating function for further calculations:
a = 5;
s = First@NDSolve[{f''[x] == a, f'[0] == 0, f[0] == 0}, f[x], {x, 0, 1}];
g[x_] = D[f[x] /. s, x];
g[0.5]
(Obviously this is not my actual code but a minimal example that shows my problem.) The code like this correctly displays the result 2.5.
However, if I put the same code inside a module:
test[var_] := Module[{a, s, g}, a = 5;
s = First@NDSolve[{f''[x] == a, f'[0] == 0, f[0] == 0}, f[x], {x, 0, 1}];
g[x_] = D[f[x] /. s, x];
g[0.5]]
The output is
test[1]
f'[0.5]
What am I doing wrong? How do I use the result of NDSolve properly within a module?
(I suspect this question has been asked before, but I don't really know what to search for.)
Thanks to yarchik's answer I figured that simply replacing f for f[x] in the second argument of NDSolve fixes the issue. A shorter solution based on NDSolveValue would be
test[var_] := Module[{a, s, f}, a = 5;
f = NDSolveValue[{f''[x] == a, f'[0] == 0, f[0] == 0}, f, {x, 0, 1}];
f'[0.5]]