I am creating a function to solve for Projectile Motion using Quadratic Drag… I am new to MATLAB and have written a function for Quadratic Drag that yields Vdotx (acceleration in x-direction) and Vdoty (acceleration in y-direction) both varying with time. I need to write a for loop to evaluate velocity in both directions using:
%Vx(t+dt)= Vx(t)+Vdotx(t)dt
%Vy(t+dt)= Vy(t)+Vdoty(t)dt
And then solving for position using:
%x(t+dt) = x(t)+Vx(t)dt
%y(x+dt) = y(t)+Vy(t)dt
The issue I can't get around is when using "For loops" a real positive integer is needed for indices. For example I would like my for loop to evaluate the x and y positions for a dt of 0.001. To do this I have written:
dt = 0.001;Vo = 10;theta = (pi/180)*33.3;Vox = Vo*cos(theta);Voy = Vo*sin(theta);Vx(1) = Vox;Vy(1) = Voy;y(1) = 10;x(1) = 0;for t = 1:dt:8 Vx(t+dt)=Vx(t)+Vdotx*dt; Vy(t+dt)=Vx(t)+Vdotx*dt; x(t+dt) = x(t)+Vx(t)*dt y(t+dt) = x(t)+Vy(t)*dtend
This does not work because the indice (dt) is not an integer. Please help.
Thank you
Best Answer