How to use ode4 with ODE system?

20 次查看(过去 30 天)
Bence Vasas
Bence Vasas 2021-7-30
I want to use a fixed step method instead of ode45's adaptive time step method. ode4 or ode5 would be suitable (i guess) but i can't use it with system of equations as the way i used with ode45.
clc
clear all
tspan = [0 250];
O0 = [3 0];
[t,O] = ode4(@(t,O) odefcn(t,O), tspan, O0);
subplot(2,1,1);
plot(t,O(:,1),t,O(:,2),'LineWidth',2)
% xlabel('t')
% ylabel('\Theta')
% legend('\theta_1','\theta_2')
%steptize plotting
subplot(2,1,2);
x = 0:length(t)-1;
stepsize = diff([0; t]);
plot(t, stepsize)
grid
function dOdt = odefcn(t,O)
dOdt = zeros(2,1);
dOdt(1)=1+sin(O(2)-O(1));
dOdt(2)=1.5+sin(O(1)-O(2));
end
The error message:
Error using ode4
Too many output arguments.
Error in Analysis_Still_Matters_FS (line 6)
[t,O] = ode4(@(t,O) odefcn(t,O), tspan, O0);

回答(1 个)

Cris LaPierre
Cris LaPierre 2021-7-30
This is not a MathWorks-supplied function.
The error message suggests this function does not return 2 outputs. When I look at one of the examples on the FileExchange page for ode4, it calls ode4 with a single output. Try updating your code to match the calling syntax in the linked example:
yout = ODE4(F,t0,h,tfinal,y0)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by