Info

This question is closed. Reopen it to edit or answer.

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

1 view (last 30 days)
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

Answers (2)

Michael Haderlein
Michael Haderlein on 22 Jul 2014
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 on 22 Jul 2014
Edited: Wayne King on 22 Jul 2014
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.

This question is closed.

Community Treasure Hunt

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

Start Hunting!