Not enough input arguments ode45

조회 수: 20 (최근 30일)
Vipin  Padinjarath
Vipin Padinjarath 2016년 10월 6일
편집: Vipin Padinjarath 2016년 10월 6일
Hi all, I have been trying to understand the use of ode solvers in MATLAB. In the process, I started with first order equations and all went well. The moment I started trying out second order systems, the trouble started. When I run the code, it shows 'not enough input arguments'. I thought that it may the problem with my code and then I started trying codes given as example in text books (Otto&Denier etc.). For every code, every time I run, the same issue pops up. And the code seems to be correct. Please help me to sort it out. I have attached the screenshot of the error message.
">> lorenz Error using lorenz (line 5) Not enough input arguments." This was a code I chose from a text book.
if true
% code
function dx=lorenz(t,x)
sigma=10;
rho=28;
beta=8/3;
dx=[sigma*(x(2)-x(1));x(1)*(rho-x(3)-x(2));x(1)*x(2)-beta*x(3)];
x0=[0 1 1.05];
tspan=[0,20];
[t,x]=ode45(@lorenz,tspan,x0);
plot(x(:,1),x(:,3))
end

채택된 답변

Massimo Zanetti
Massimo Zanetti 2016년 10월 6일
Separate the funciton from the rest
function dx=lorenz(t,x)
sigma=10;
rho=28;
beta=8/3;
dx=[sigma*(x(2)-x(1));x(1)*(rho-x(3)-x(2));x(1)*x(2)-beta*x(3)];
end
and invoke ode45 correctly
x0=[0 1 1.05];
tspan=[0,20];
[t,x]=ode45(@(t,x) lorenz(t,x),tspan,x0);
plot(x(:,1),x(:,3))
Does it work now?
  댓글 수: 4
Vipin  Padinjarath
Vipin Padinjarath 2016년 10월 6일
Yes! It is running now.Thank you very much.
Vipin  Padinjarath
Vipin Padinjarath 2016년 10월 6일
편집: Vipin Padinjarath 2016년 10월 6일
I am sorry, I know that I am troubling you. But please help me with the following code. This i wrote by myself. (Rossler equations)
Function definition
if true
% function dR=RH(t,x,y,z)
dR=zeros(3,1);
dR(1)=-(y+z);
dR(2)=(x+2*y);
dR(3)=(1+z(x-3));
end
end
Solution
if true
s0=[1 1 1];
tspan=[0 50];
[t,x,y,z]=ode45(@(t,x,y,z)RH(t,x,y,z),tspan,s0);
plot3(t,x,y,z)
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by