I have a script to plot the projectile motion path with drag. However, the plot comes out as with no drag. Using parameter v0=150,h=10,dt=0.01,theta=0.1745
I think the mistake is in my while loop, buti can't figure it out.
function [rx,ry,vx,vy]=solve_ode_euler(v0,h,dt,theta)n=1000; %number of maximum iterations
rho=1.225;cd=0.479;m=5.5;D=0.1;R=D/2;A=4*pi*R^4;g=9.81;% initializing values of distance and velocity
rx(1)=0;ry(1)=h;v(1)=v0;vx=v0*cos(theta);vy=v0*sin(theta);vx(1)=vx;vy(1)=vy;k=cd*rho*A/(2*m);t(1)=0;i=1;dt=0.01;% while loop to solve projectile with Euler method
while i<n v(i+1)=sqrt((vx(i)^2)+(vy(i)^2)); % velocity magnitude as a vector
rx(i+1)=rx(i)+vx(i)*dt; vx(i+1)=vx(i)-(k*v(i)*vx(i))*dt; ry(i+1)=ry(i)+vy(i)*dt; vy(i+1)=vy(i)-g*dt-(k*v(i)*vy(i))*dt; t(i+1)=t(i)+dt; if ry(i+1)<0 %stops the projectile if reaches the ground
i=n; else i=i+1; endplot(rx,ry) end
Best Answer