using ode45 for coupled equations
Ältere Kommentare anzeigen
I am attempting to simplify my forward euler solution to an ODE solution, but I don't know how to "call" another script to solve.
Here is my forward euler:
dt=.01;
tmin=5;
tmax=10;
t=tmin:dt:tmax;
n=length(t);
z=zeros(1,n);
x=zeros(1,n);
x(1)=1;
z(1)=1;
for i=1:n-1
x(i+1)=x(i)+dt*(t(i)+x(i)+z(i));
z(i+1)=z(i)+dt*(t(i)+x(i)-(3*x(i)));
end
And my current script for ode45:
tspan = [5 10];
t0 = 5;
dt=.01;
tmin=5;
tmax=10;
t=tmin:dt:tmax;
n=length(t);
z=zeros(1,n);
x=zeros(1,n);
x(1)=1;
z(1)=1;
[t,x] = ode45(@(t,x)myfun, tspan, t0);
Akzeptierte Antwort
Weitere Antworten (1)
Kolleggerm1
am 24 Okt. 2019
0 Stimmen
Kategorien
Mehr zu Ordinary 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!