How can i pass an index to ode function?
Ältere Kommentare anzeigen
Hi all,
I'm a new user and I'm having trouble with ode45 function for a second order differential equation.
I should find a soultion for the problem d2y/dt2=(1-A*y)dy/dt-y in which A is a vector that depends on the time. I use [t,f]=ode45('fun',t,y0); How can I tell to the software that at timestep 1 I should use A(1) or a timestep 2 I should use A(2)?
thank you in advance Francesco
thank u advance
Akzeptierte Antwort
Weitere Antworten (2)
Sara
am 24 Apr. 2014
You will need check the time into the fun and pass both A and t to it. You want something like:
[t,f]=ode45(@(t,x)fun(t,x,t,A),t,y0);
function dy = fun(t,x,timeserie,A)
k = find(t >= timeserie,1);
k = max(1,k-1);
a = A(k);
Jan
am 25 Apr. 2014
0 Stimmen
It is important, that the function to be integrated is smooth. Otherwise the result of the integration is suspicious. See http://www.mathworks.com/matlabcentral/answers/59582#answer_72047
Kategorien
Mehr zu Numerical Integration and Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!