Not enough input argument in ode45

1 view (last 30 days)
Rishabh Mankotia
Rishabh Mankotia on 21 May 2022
Commented: VBBV on 21 May 2022
function dxdt = mastersystem(t,x);
b = -.68;
a= -1.27;
c= abs(x(1)+1);
d= abs(x(1)-1);
e= abs(x(4)+1);
g= abs(x(4)-1);
f1= b*x(1)+.5*(a-b)*(c-d);
f4= b*x(4)+.5*(a-b)*(e-g);
w(t)= 0.1*sin(2*t);
dxdt(1,1)= -10*x(1)+ 10*x(2)-10*f1+w(t);
dxdt(2,1)= x(1)-1.02*x(2)+x(3)+.02*x(5);
dxdt(3,1)=-14.87*x(2);
dxdt(4,1)=-10*x(4)+10*x(5)-10*f4+w(t);
dxdt(5,1)= x(4)-x(5)+x(6);
dxdt(6,1)= -14.87*x(5);
y(1)=x(1);
y(2)=x(3);
y(3)=x(4);
y(4)=x(5);
y(1)=x(1);
y(2)=x(3);
y(3)=x(4);
y(4)=x(5);
[t,x] = ode45(mastersystem,[0 10],[0 0 0 0 0 0]);
Not enough input arguments.
Error in mastersystem (line 4)
c= abs(x(1)+1);

Answers (1)

VBBV
VBBV on 21 May 2022
Edited: VBBV on 21 May 2022
[t,x] = ode45(@mastersystem,[0 10],[0 0 0 0 0 0]); % use a function handle to pass function as argument
plot(t,x)
function dxdt = mastersystem(t,x);
b = -.68;
a= -1.27;
c= abs(x(1)+1);
d= abs(x(1)-1);
e= abs(x(4)+1);
g= abs(x(4)-1);
f1= b*x(1)+.5*(a-b)*(c-d);
f4= b*x(4)+.5*(a-b)*(e-g);
w = 0.1*sin(2*t); % change this vector assignment
dxdt(1,1)= -10*x(1)+ 10*x(2)-10*f1+w;
dxdt(2,1)= x(1)-1.02*x(2)+x(3)+.02*x(5);
dxdt(3,1)=-14.87*x(2);
dxdt(4,1)=-10*x(4)+10*x(5)-10*f4+w;
dxdt(5,1)= x(4)-x(5)+x(6);
dxdt(6,1)= -14.87*x(5);
y(1)=x(1);
y(2)=x(3);
y(3)=x(4);
y(4)=x(5);
y(1)=x(1);
y(2)=x(3);
y(3)=x(4);
y(4)=x(5);
end
  1 Comment
VBBV
VBBV on 21 May 2022
use a function handle to pass function as argument

Sign in to comment.

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by