Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

hi members i have error using my matlab code "Subscripted assignment dimension mismatch" plz help me out.

조회 수: 1 (최근 30일)
M=[1 0;0 2]; % mass matrix
C=[1.6 -0.8; -0.8 0.8]; % damping matrix
K=[5 -4;-4 4]; % stiffness matrix
A=[zeros(size(M)) eye(size(M));-inv(M)*K -inv(M)*C];
B=[zeros(size(M)); inv(M)];....................................(here iam getting error message)
TO=4; %RISE TIME OF FORCE
N=600;
T=0.1; % SAMPLING PERIOD
NO=TO/T;
phi=eye(size(A))+T*A+T^2*A^2/2+T^3*A^3/6;
gamma=inv(A)*(phi-eye(size(A)))*B;
x(:,1)=zeros(2*length(M),1);
for k=1:N,
if k<=NO +1; f(k)=1;
else;f(k)=0;end
F(:,k)=[0;1]*f(k); % Force is only applied to mass m
x(:,k+1)=phi*x(:,k)+gamma*F(:,k);
end
k=[0:N];
plot(k,x(1,:),'.')
title('system response for unit step at first disc E8.20')
ylabel('x_1(k)')
xlabel('k')
grid

답변 (2개)

Michael Haderlein
Michael Haderlein 2014년 7월 22일
I cannot reproduce the error.
M=[1 0;0 2]; % mass matrix
C=[1.6 -0.8; -0.8 0.8]; % damping matrix
K=[5 -4;-4 4]; % stiffness matrix
A=[zeros(size(M)) eye(size(M));-inv(M)*K -inv(M)*C];
B=[zeros(size(M)); inv(M)]
B =
0 0
0 0
1.000000000000000 0
0 0.500000000000000
Maybe you have some variable x or F in the memory and the error appears in the line x(:,1)=... or F(:,k)=...? If so, delete the variables (see clear function).
Best regards, Michael

Wayne King
Wayne King 2014년 7월 22일
편집: Wayne King 2014년 7월 22일
There is no error there unless you have already set B equal to something in your workspace, clear the variables used here and then execute:
clearvars M C K A B
M=[1 0;0 2]; % mass matrix
C=[1.6 -0.8; -0.8 0.8]; % damping matrix
K=[5 -4;-4 4]; % stiffness matrix
A=[zeros(size(M)) eye(size(M));-inv(M)*K -inv(M)*C];
B=[zeros(size(M)); inv(M)];
B is a 4x2 matrix as expected.

Community Treasure Hunt

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

Start Hunting!

Translated by