Please amend my code :(

3 ビュー (過去 30 日間)
지원 안
지원 안 2021 年 5 月 23 日
回答済み: Girijashankar Sahoo 2021 年 5 月 23 日
I want V when x=5000 but something wrong...
please amend my code
clear all
close all
grav=9.81;
theta=pi/4;
v=20;
x=0; vx=cos(theta).*v;
y=0; vy=sin(theta).*v;
dt=0.05;
for n=1:100
x=x+vx*dt;
vx=vx+vx.*dt;
y=y+vy*dt
vy=vy-grav*dt;
if(y<0); break; end
n=1:10000
if(x==5000);break; end
else(x<5000);
v=v+1;
end
v

回答 (1 件)

Girijashankar Sahoo
Girijashankar Sahoo 2021 年 5 月 23 日
%% if statement end after else, #look the code again
grav=9.81;
theta=pi/4;
v=20;
x=0; vx=cos(theta).*v;
y=0; vy=sin(theta).*v;
dt=0.05;
for n=1:100
x=x+vx*dt;
vx=vx+vx.*dt;
y=y+vy*dt
vy=vy-grav*dt;
if(y<0); break; end
n=1:10000
if(x==5000);break;
else(x<5000);
v=v+1;
end
end
v

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by