27 views (last 30 days)

n=1000; %number of iterations

x=zeros(n); % horizontal distance traveled

y=zeros(n); % vertical distance traveled

vx=zeros(n); % horizontal velocity

vy=zeros(n); % vertical velocity

v=zeros(n); % total velocity

theta_th=0.6575; % launch angle

vx(1)=7815.06*cos(theta_th); % starting x velocity

vy(1)=7815.06*sin(theta_th); % starting y velocity

x(1)=0; % starting x position

y(1)=0; % starting y position

delta_t=0.0001; % step size

a=(pi/4)*(3/12)^2; % area of projectile

m=55/32.174; % mass of projectile

g=32.174; % gravity

k=1.4; %

R=1716.5; % ideal gas constant

for i=2:n

[T,p,rho]=atmos_funEE; %

c=sqrt(k*R*T); % speed of sound

ma=v(n)/c; %

if (0<ma)&&(ma<=0.8) %

cd=0.17; %

elseif (0.8<ma)&&(ma<=1.2) %

cd=0.7763*ma-0.451; %

elseif (1.2<ma)&&(ma<=8) %

cd=0.0093*ma^2-0.1223*ma+0.607; %

end

x(i)=(x(i-1))+(delta_t*(vx(i-1))); %

vx(i)=(vx(i-1))+(delta_t*(-1/2)*rho*a*cd*(v(i-1))*(vx(i-1))*(1/m)); %

y(i)=(y(i-1))+(delta_t*(vy(i-1))); %

vy(i)=(vy(i-1))+(delta_t*(-g-(1/2)*rho*a*cd*v(i-1)*(vy(i-1))*(1/m))); %

v(i)=sqrt((vx(i-1))^2+(vy(i-1))^2); %

end

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/573577-unable-to-perform-assignment-because-the-left-and-right-sides-have-a-different-number-of-elements#comment_956953

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/573577-unable-to-perform-assignment-because-the-left-and-right-sides-have-a-different-number-of-elements#comment_956953

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/573577-unable-to-perform-assignment-because-the-left-and-right-sides-have-a-different-number-of-elements#comment_958180

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/573577-unable-to-perform-assignment-because-the-left-and-right-sides-have-a-different-number-of-elements#comment_958180

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/573577-unable-to-perform-assignment-because-the-left-and-right-sides-have-a-different-number-of-elements#comment_958195

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/573577-unable-to-perform-assignment-because-the-left-and-right-sides-have-a-different-number-of-elements#comment_958195

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/573577-unable-to-perform-assignment-because-the-left-and-right-sides-have-a-different-number-of-elements#comment_958225

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/573577-unable-to-perform-assignment-because-the-left-and-right-sides-have-a-different-number-of-elements#comment_958225

Sign in to comment.