This question already has an answer here:
I'm having problems working with the output from DSolve whilst in a module. To handle the result outside a module typically I would do something like
f[t] = y[t] /. solution
But inside a module my t is now t$ followed by some numbers. How can I create and return a function from the output of DSolve inside a module?
Here is my code:
Module[{equations,solution,h,t},
m=1;
g=9.8;
equations = {y''[t]== -m g,y'[0]==100,y[0]==0};
solution = Flatten@ DSolve[equations,y,t];
h[t] = y[t] /. solution;
h[1]]
I get h = 100. t$16608-4.9 t$16608^2, but h[1] = h$16909[1).
h. Furthermore, (in your additional post) you don't return a function! You return only an expression. Can you please clear up what exactly you try and how you want to use it? Btw, you can edit your question and improve it. Don't write an additional post. – halirutan Feb 27 at 10:05Blockrather thanModulein this case", so I voted to close this as a duplicate of a question the explains the distinctions rather well. – Oleksandr R. Mar 28 at 23:08Set(=) instead ofSetDelayed(:=); and you should use a patternh[t_]. You could also simply skiphand returny[1] /. solution. – Michael E2 Mar 29 at 11:42