Unable to perform assignment because the left and right sides have a different number of elements. Error in Hyperverlocitynew (line 36)
1 view (last 30 days)
Show older comments
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
4 Comments
Alan Stevens
on 2 Aug 2020
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
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
Answers (1)
Rohit Pappu
on 14 Aug 2020
As per my understanding, you are unable to assign the value of the equation to vx(i). The error might have occurred because the variable cd is declared conditionally and thus it behaves like a matrix.
A plausible solution would be to declare cd outside the loop which would make the variable remain as a scalar.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!