Please amend my code :(

2 Ansichten (letzte 30 Tage)
지원 안
지원 안 am 23 Mai 2021
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

Antworten (1)

Girijashankar Sahoo
Girijashankar Sahoo am 23 Mai 2021
%% 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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by