# Projectile motion using while loop Time of flight

조회 수: 3 (최근 30일)
dotty daniels 2020년 10월 27일
편집: dotty daniels 2020년 10월 27일
So i need a program that tells you when a potato launcher will hit a target.... (can change this variable and still work). initial variables vx=200, vy,x,y=0 dtarg=23 delta_t=.01seconds.I've checked all the forum information and am still not able to get mine to run correctly. our inputs for (delt_x=vx*delta_t) (delta_y=vy*delta_t) (delta_vx=(-.0254)*(v^x)^2) delta_vy=-(9.8)*delta_t. Like i said we're looking for time of impact and to a set target distance(dtarg). I am not sure what I am missing to make my code work. Any help is grately appreciated.
clc
clear all
dt=0.01; %s
i=1;
x=0;
y=0;
delta_x=0;
delta_y=0;
g=-9.81;
vx=200
vy=0
delta_vx=0;
delta_vy=0;
Dtarget=15;
while x<=Dtarget
delta_vy(i)=-(9.81)*dt
delta_vx(i)=(-.0254)*(vx^2)*dt
delta_x(i)=vx*dt
delta_y(i)=vy*dt
i=i+1;
end

댓글을 달려면 로그인하십시오.

### 채택된 답변

Sindar 2020년 10월 27일
Basically, the issue is that you are only updating a small portion of the relevant variables each time step. A few questions
• Is delt_x your current position, or the change in position from your last time step?
• Should x, y, vx & vy be constant? They are in your code
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
dotty daniels 2020년 10월 27일
Sorry I did get it. I had way too many variables and was making it way more complex than i should have been. Thank you very much

댓글을 달려면 로그인하십시오.

### 카테고리

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