MATLAB: Problem with Response function in a mass-spring-damper System

massspringdampersystemsvibration analysis

Hello!
So I am attempting to determine the response of an under-damped system (There is a spring, Mass and damper in the system). I have an error in my response function, x(t) that I cant seem to figure out. The error is as follows:
Error using * Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'
Here is my Response Function:
And here is My command Window with the error:
%%Damped Response
c = 8; Dampinging Coefficient
m = 2; Mass
k = 16 Spring Constant
x0 = 1 X
xd0 = -1 X Dot
wn = sqrt(k/m) Natural Frequency
zeta = c/2/m/wn;
B = x0;
A = (xd0 + zeta*wn*x0)/wn/sqrt(1-zeta^2);
C = sqrt(A^2+B^2);
x = DampedResponse(zeta,wn,A,B,t);
figure; plot(t,x,t,C*exp(-zeta*wn*t),'--r',t,-C*exp(-zeta*wn*t),'--r'); grid on;
if true
% code
end
Response Function For my System:
function x = DampedResponse(zeta,wn,A,B,t)
wd = wn*sqrt(1-zeta^2);
x = exp(-zeta*wn*t)*(A*sin(wd*t)+B*cos(wd*t));
end

Best Answer

You forgot to include ‘t’. When I provided it, the problem turned out to be solved by using element-wise multiplication in this assignment in ‘DampedResponse’:
x = exp(-zeta*wn*t).*(A*sin(wd*t)+B*cos(wd*t));
↑ ← INSERT DOT-OPERATOR HERE
Related Question