using ode45 for coupled equations
显示 更早的评论
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);
采纳的回答
更多回答(1 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!