Vector output from a function
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Karlie Brillant
el 26 de Mzo. de 2019
Working on a projectile motion problem. I am trying to get x_dist and y_height vectors as outputs from my function so that I can then graph them. When I run my function it tells me that the variable x_dist does not exist even though it is in my function. Any help would be appreciated!
function [x_dist,y_height]=projectile(V_int,theta)
dt=1; %seconds
w=3; %kg
k=0.32;
g=9.81; %m/s^2
i=1;
y=0;
while y>0
a_y(i)=w*g-V_int*k;
a_x(i)=-V_int*k;
v_y(i)=(V_int*sin(theta))+(a_y(i)*dt);
v_x(i)=(V_int*cos(theta))+(a_x(i)*dt);
x_dist(i)=(V_int-v_x(i))/1;
y_height(i)=(V_int-v_y(i))/1;
V_int=v_x(i);
V_int=v_y(i);
i=i+1;
dt=dt+1;
end
pause(0.5);
comet(x_dist,y_height);
end
0 comentarios
Respuesta aceptada
Stephan
el 26 de Mzo. de 2019
Editada: Stephan
el 26 de Mzo. de 2019
Hi,
you set y=0. one line later you start a while loop, that is valid as long as y>0. This can not work. For this reason xdist is not there, because the while loop stopps the same moment it starts. xdist is defined inside the while loop.
Best regards
Stephan
0 comentarios
Más respuestas (1)
Walter Roberson
el 26 de Mzo. de 2019
Editada: Walter Roberson
el 26 de Mzo. de 2019
You initialize y = 0. You have while y>0 . But 0>0 is false, so the body of your while loop is never done, and nothing was ever assigned to x_dist or y_height.
Note: you also do not assign to y in the loop, so if the loop did ever get started, then it would not stop.
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!