필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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
Alan Stevens
Alan Stevens 2020년 8월 2일
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
Walter Roberson 2020년 8월 2일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Rohit Pappu
Rohit Pappu 2020년 8월 14일
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.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by