Borrar filtros
Borrar filtros

Please amend my code :(

2 visualizaciones (últimos 30 días)
지원 안
지원 안 el 23 de Mayo de 2021
Respondida: Girijashankar Sahoo el 23 de Mayo de 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

Respuestas (1)

Girijashankar Sahoo
Girijashankar Sahoo el 23 de Mayo de 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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by