Can you help me please !

1 visualización (últimos 30 días)
Johnny Vendetta
Johnny Vendetta el 3 de Sept. de 2019
Comentada: Johnny Vendetta el 7 de Sept. de 2019
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 comentarios
Adam
Adam el 3 de Sept. de 2019
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.
Johnny Vendetta
Johnny Vendetta el 7 de Sept. de 2019
thank you Adam

Iniciar sesión para comentar.

Respuesta aceptada

Torsten
Torsten el 3 de Sept. de 2019
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
  1 comentario
Johnny Vendetta
Johnny Vendetta el 3 de Sept. de 2019
Thank you so much, Torsten.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by