# How to use ode4 with ODE system?

조회 수: 24(최근 30일)
Bence Vasas 2021년 7월 30일
답변: Cris LaPierre 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 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)

댓글을 달려면 로그인하십시오.

R2020b

### Community Treasure Hunt

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

Start Hunting!