value assigned to variable might be unsured (Ln 12)

2 views (last 30 days)
firas
firas on 11 May 2023
Answered: Shaik on 11 May 2023
m = 45; % mass in kg
k = 35000; % spring constant in N/m
c = 1200; % damping coefficient in N*s/m
F0 = 600; % amplitude of the force in N
omega = 40; % angular frequency of the force in rad/s
x0 = 0.0001; % initial displacement in m
v0 = 0.1; % initial velocity in m/s
t = linspace(0, 10, 1000); % time range from 0 to 10 seconds with 1000 data points
% Calculate the response function using the equation of motion:
omega_n = sqrt(k / m); % natural frequency
zeta = c / (2 * sqrt(m * k)); % damping ratio
omega_d = omega_n * sqrt(1 - zeta^2); % damped natural frequency
% Calculate the response function using the equation of motion:
omega_n = sqrt(k / m); % natural frequency
zeta = c / (2 * sqrt(m * k)); % damping ratio
omega_d = omega_n * sqrt(1 - zeta^2); % damped natural frequency
figure;
plot(t, X);
Unrecognized function or variable 'X'.
xlabel('Time (s)');
ylabel('Displacement (m)');
title('Response of Mass-Spring-Damper System');
grid on;

Answers (1)

Shaik
Shaik on 11 May 2023
Hi Firas,
I hope this resolves your issue,
m = 45; % mass in kg
k = 35000; % spring constant in N/m
c = 1200; % damping coefficient in N*s/m
F0 = 600; % amplitude of the force in N
omega = 40; % angular frequency of the force in rad/s
x0 = 0.0001; % initial displacement in m
v0 = 0.1; % initial velocity in m/s
t = linspace(0, 10, 1000); % time range from 0 to 10 seconds with 1000 data points
% Calculate the response function using the equation of motion:
omega_n = sqrt(k / m); % natural frequency
zeta = c / (2 * sqrt(m * k)); % damping ratio
omega_d = omega_n * sqrt(1 - zeta^2); % damped natural frequency
X = (F0/m) ./ ((omega_n^2 - omega^2 + 2i*zeta*omega_n*omega) .* (omega_n^2 - omega^2 - 2i*zeta*omega_n*omega)); % displacement response
figure;
plot(t, real(X)*cos(omega_d*t) - imag(X)*sin(omega_d*t)); % plot the real part of X against time
xlabel('Time (s)');
ylabel('Displacement (m)');
title('Response of Mass-Spring-Damper System');
grid on;

Community Treasure Hunt

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

Start Hunting!