How to solve an ODE with external time-varying source?
1 view (last 30 days)
Show older comments
Hi,
I am trying to numerically solve y(t) from an equation with the following form:
f is a function of x(t), x(t) is a given set of time-varying values stored in a line vector, [x1 x2 x3 ... xn]. x(t) is the solution of a DDE so I do not think it has any analytic expressions.
My problems are:
Can I turn the line vector into a function of t and just insert that function? If yes, how should I do; if no, is there any other ways to solve the equation?
Thank you.
0 Comments
Accepted Answer
Torsten
on 17 Jan 2019
a) Save [t1 t2 ... tn], [x1 x2 ... xn] in two arrays T and X.
b) Pass T and X to the integrator:
[tsim,ysim] = ode45(@(t,y)fun(t,y,T,X),tspan,y0)
c) Define the ODE in function "fun":
function dy = fun(t,y,T,X)
source = interp1(T,X,t)
source = f(source);
dy = (source-y)/tau
end
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!