How to use ode4 with ODE system?
94 views (last 30 days)
Show older comments
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);
0 Comments
Answers (1)
Cris LaPierre
on 30 Jul 2021
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)
0 Comments
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!