Vector output from a function
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Stephan
2019 年 3 月 26 日
編集済み: Stephan
2019 年 3 月 26 日
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 件のコメント
その他の回答 (1 件)
Walter Roberson
2019 年 3 月 26 日
編集済み: Walter Roberson
2019 年 3 月 26 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!