how to modify plot range from (-200 to 200)
2 views (last 30 days)
Show older comments
% Define the mass, damping, and stiffness matrices
load C K
load M.mat
% Define the input force as a sinusoidal function of frequency w in Hz
f = linspace(0, 40, 100); % linearly spaced frequency vector in Hz
w = 2*pi*f; % angular frequency vector in rad/s
F = @(t) [sin(2*pi*f(1)*t); zeros(3, 1)];
% Define the initial conditions
x0 = zeros(4, 1);
v0 = zeros(4, 1);
y0 = [x0; v0];
% Define the time span
tspan = [0 20];
% Preallocate arrays to store the magnitude and phase of the response
mag = zeros(size(w));
phase = zeros(size(w));
% Loop over the frequency vector and compute the response at each frequency
for i = 1:length(w)
% Define the input force at the current frequency
F = @(t) [sin(w(i)*t); zeros(3, 1)];
% Solve the differential equation to obtain the steady-state response
[~, y] = ode45(@(t, y) vibration_equation(t, y, M, C, K, F), tspan, y0);
x = y(end, 1:4)';
% Compute the magnitude and phase of the response at the current frequency
mag(i) = abs(x(1));
phase(i) = angle(x(1)) * 180/pi;
end
% Plot the magnitude and phase of the FRF in Hz
figure;
subplot(2, 1, 1);
plot(f, mag);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Frequency Response Function');
grid on;
subplot(2, 1, 2);
plot(f, mod(phase+180,360)-180);
xlabel('Frequency (Hz)');
ylabel('Phase (deg)');
ylim([-180, 180]);
grid on;
function dydt = vibration_equation(t, y, M, C, K, F)
% Compute the acceleration
x = y(1:4);
v = y(5:8);
a = M \ (F(t) - C*v - K*x);
% Compute the derivative of the state vector
dydt = [v; a];
end
I want something like in shown in photo. from -200 to 200 range for phase graph.
0 Comments
Answers (1)
Cris LaPierre
on 18 Mar 2023
Edited: Cris LaPierre
on 18 Mar 2023
The function angle already returns the phase angle on the interval of [,π], which you convert to degrees, or [-180,180]. For some reason, your angles are only negative. So I would first look into why the angles are between 0 and -180 before I'd modify the phase plot and data.
3 Comments
Cris LaPierre
on 18 Mar 2023
I don't think that is the correct approach. Consider looking at the bottom of this page to see what they do with a system with 4 degrees of freedom:
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!