Can you help me please !

1 次查看(过去 30 天)
I run code Matlab:
function yp=khidonghoc(t,y)
m = 10;
cd = 0.2;
g = 9.81;
w = m*g;
tspan=[0 5];
y0=[0;100;0;10];
yp = zeros(4,1);
yp(1)= y(2);
yp(2) = ((-cd/m)*y(2)*(y(2)^2+y(4)^2)^(0.5));
yp(3) = y(4);
yp(4) = ((-w/m)-(cd/m)*y(4)*(y(2)^2+y(4)^2)^(0.5));
[t,y]=ode45('khidonghoc',tspan,y0);
plot(t,y(:,1),y(:,3))
hold on;grid on;
xlabel('X-Displacement')
ylabel('Y-Displacement')
title('X vs Y Displacement')
end
Matlab error: "Not enough input arguments.
Error in khidonghoc (line 9)
yp(1)= y(2);"
Thanks you very much.
  2 个评论
Adam
Adam 2019-9-3
Pass in some arguments! How did you call the function? It expects two input arguments so if you don't pass them in it will give you that error.

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2019-9-3
function main
tspan=[0 5];
y0=[0;100;0;10];
[t,y]=ode45(@khidonghoc,tspan,y0);
plot(t,y(:,1),t,y(:,3))
hold on;grid on;
xlabel('X-Displacement')
ylabel('Y-Displacement')
title('X vs Y Displacement')
end
function yp=khidonghoc(t,y)
m = 10;
cd = 0.2;
g = 9.81;
w = m*g;
yp = zeros(4,1);
yp(1)= y(2);
yp(2) = ((-cd/m)*y(2)*(y(2)^2+y(4)^2)^(0.5));
yp(3) = y(4);
yp(4) = ((-w/m)-(cd/m)*y(4)*(y(2)^2+y(4)^2)^(0.5));
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by