Mathematica Asked by kotozna on May 29, 2021
I’m trying to plot the integral of an interpolating function multiplied by another (analytic) function, eg:
sol = NDSolve[{ x''[t] == 1.0, x'[0] == 0, x[0] == 0}, {x'[t],
x[t]}, {t, 0, 1}, Method -> {"ImplicitRungeKutta", "DifferenceOrder" -> 4}]
then form some integral
f[t_] = Integrate[ t x'[t] /. sol, t]
and try to plot it
Plot[f[t], {t, 0, 1}]
This works fine if the integrand doesn’t contain an analytic function (t, in the example above), but not if it does.
One way is use NIntegrate
sol = NDSolve[{x''[t] == 1.0, x'[0] == 0, x[0] == 0}, {x'[t],
x[t]}, {t, 0, 1},
Method -> {"ImplicitRungeKutta", "DifferenceOrder" -> 4}]
f[s_?NumericQ] := NIntegrate[t*x'[t] /. sol, {t, 0, s}];
Plot[f[s], {s, 0, 1}]
Another way is add y'[t]=t*x'[t]
.
sol2= NDSolve[{x''[t] == 1.0, x'[0] == 0, x[0] == 0, y'[t] == t*x'[t],
y[0] == 0}, {y[t], x'[t], x[t]}, {t, 0, 1},
Method -> {"ImplicitRungeKutta", "DifferenceOrder" -> 4}];
Plot[y[t] /. sol2, {t, 0, 1}]
Correct answer by cvgmt on May 29, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP