Please amend my code :(

1 次查看(过去 30 天)
지원 안
지원 안 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
%% 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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by