Inner matrix dimensions must agree

조회 수: 3 (최근 30일)
Valéry Ebogo
Valéry Ebogo 2020년 2월 14일
댓글: Valéry Ebogo 2020년 2월 14일
Hi,
when I execute the following code, I get the error message "Inner matrix dimensions must agree".
The error is in line 31, which performs the multiplication of three real matrix of the same size.
this is what I can't understand.
i would like you to help me understand what is the problem.
thank you!
de=ones(5,1); u=ones(22); %dde=zeros(5,1);
Cz=0.001; %vertical deflection rate of the tyre
Cs=50000;
epsilon=0.015;
I=2.1;
Iz=1627;
R=0.35;
Ca=30000;
m=1298.9;
lf=1;
lr=1.454;
br=1.436;
bf=br;
mu=0.9;
g=9.81;
cons=m/(lr+lf);
h=0.5;
C=[0 m*u(22) 0 0 0;-m*u(22) 0 0 0 0;0 0 0 0 0;0 0 0 cos(u(21)) -sin(u(21));0 0 0 sin(u(21)) cos(u(21))];
M=[m 0 0 0 0;0 m 0 0 0;0 0 Iz 0 0;0 0 0 1 0;0 0 0 0 1];
u1=(de(2)+lf*de(3))/(de(1)+0.5*bf*de(3));
u2=(de(2)+lf*de(3))/(de(1)-0.5*bf*de(3));
u3=(de(2)-lr*de(3))/(de(1)+0.5*br*de(3)); %% les ui représentent les rapports permettant de calculer les angles de dérives de chaque roue%%
u4=(de(2)-lr*de(3))/(de(1)-0.5*br*de(3));
U=[u1 u2 u3 u4];
%------vertical load----------
dde=(-de*C)\M; % here: Inner matrix dimensions must agree !
Fz1= cons*(0.5*g*lr-0.5*dde(1)*h-lr*h*dde(2)/bf);
Fz2= cons*(0.5*g*lr-0.5*dde(1)*h+lr*h*dde(2)/bf);
Fz3= cons*(0.5*g*lr+0.5*dde(1)*h-lr*h*dde(2)/bf);
Fz4= cons*(0.5*g*lr+0.5*dde(1)*h+lr*h*dde(2)/bf);
Fz=[Fz1 Fz2 Fz3 Fz4]';
%%% velocity component in the wheel plane : is the longitunal velocity
v1=(de(1)+0.5*bf*de(3))*cos(u(1))+(de(2)+lf*de(3))*sin(u(1));
v2=(de(1)-0.5*bf*de(3))*cos(u(2))+(de(2)+lf*de(3))*sin(u(2));
v3=(de(1)+0.5*br*de(3))*cos(u(3))+(de(2)-lr*de(3))*sin(u(3));
v4=(de(1)-0.5*br*de(3))*cos(u(4))+(de(2)-lr*de(3))*sin(u(4));
V=[v1 v2 v3 v4]';
lamda=zeros(4,1);f=length(lamda);
omega=zeros(4,1);
alph=zeros(4,1);
Re=zeros(4,1);
S=zeros(4,1);
dz=zeros(4,1);
Fs=zeros(4,1);
Ft=zeros(4,1);
for i=1:4
dz(i)=-Cz*Fz(i)+ 0.33*R;
Re(i)=R-dz(i)./3;
omega(i)=(-R*u(i+16)+u(i+4))/I;
S(i)=1+omega(i)*Re(i)./V(i);
alph(i)=atan(U(i))-u(i);
lamda(i)= mu*Fz(i).*(1-S(i))*(1-epsilon*V(i).*sqrt((S(i))^2 + (tan(alph(i)))^2))./(2*sqrt((Cs^2)*(S(i))^2 + (Ca^2)*(tan(alph(i))^2)));
if lamda(i)<1
f(i)=lamda(i)*(2-lamda(i));
Fs(i)=Ca*f(i).*tan(alph(i))./(1-S(i));
Ft(i)=Cs*f(i).*S(i)./(1-S(i));
elseif lamda(i)>1
f(i)=1;
Fs(i)=Ca*f(i).*tan(alph(i))./(1-S(i));
Ft(i)=Cs*f(i).*S(i)./(1-S(i));
end
end
  댓글 수: 4
Murugan C
Murugan C 2020년 2월 14일
now also you will get error.
dde=(-de'*C)\M; % here: Inner matrix dimensions must agree !
K>> dde=(-de'*C)\M;
Error using \
Matrix dimensions must agree.
Valéry Ebogo
Valéry Ebogo 2020년 2월 14일
dde=(-de'*C)\M;
Error using \
% The problem is solved by changing \ by /.
Thank you!

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

채택된 답변

Valéry Ebogo
Valéry Ebogo 2020년 2월 14일
I realized the mistake!
in fact, d is a vector 5x1, the product de*C is correct if the number of columns of de is equal to the number of rows of C. it is thus necessary here to take the transpose of de for this product to be correct.
We thus obtain a vector de'*C which has the same number of columns as M, which leads us to change \ by /(Matrix right division), better adapted in our case.
ie
dde=(-de'*C)/M;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by