Writing a function for a Projectile?

18 ビュー (過去 30 日間)
Emily
Emily 2014 年 3 月 28 日
回答済み: Sara 2014 年 3 月 28 日
Writing a function determining horizontal and vertical position of 2 kg projectile with user given initial velocity(of 300m/s) and angle. Must incorporate linear drag coefficient value of 0.3 Function should plot the location of projectile for each time step from when its fired until its hit the ground. I separated the vertical and horizontal positions into two separate functions but my while loops are infinite and i don't know why. My function readsfunction [ horizontal_position ] = Horizontal_position(theta,v0) %this function will determine horizontal of a %projectile shot k=0.3; %drag coefficent x=0; %inital position dt=0.1; i=1; v=v0*cosd(theta); while x>=1 n(i)=i+dt; acceleration=-v*k; vf=v+(acceleration*dt); ave_velocity=(vf+v)/2; horizontal_position_change=ave_velocity*dt; horizontal_position=(horizontal_position_change+x); end end

回答 (1 件)

Sara
Sara 2014 年 3 月 28 日
You do not recalculate x in the loop. Is it possible that it should have been:
x=(horizontal_position_change+x);
in the last line?

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by