# Unable to perform assignment because the left and right sides have a different number of elements. Error in Hyperverlocitynew (line 36)

27 views (last 30 days)
James Murray on 31 Jul 2020 at 22:18
Commented: Walter Roberson on 2 Aug 2020 at 18:41
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

Show 1 older comment
James Murray on 2 Aug 2020 at 17:26
It’s a function that calculates the coefficient of drag as a projectile is shot in the air. the function uses altitude to calculate this.
Alan Stevens on 2 Aug 2020 at 17:39
I've just noticed that you have defined x, y, etc. as zeros(n). This will result in matrices of size nxn for each of them. Is this what you meant, or did you mean zeros(1,n), which will result in vectors of size 1xn?
Walter Roberson on 2 Aug 2020 at 18:41
You are not passing anything into the function. How can it be calculating correct coefficients?
The current hypothesis is that rho is a non-scalar