how to modify plot range from (-200 to 200)

2 次查看(过去 30 天)
% 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.

回答(1 个)

Cris LaPierre
Cris LaPierre 2023-3-18
编辑:Cris LaPierre 2023-3-18
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 个评论
AL
AL 2023-3-18
thank you so much for your effort and give me inside behind what is happning. is there anyway we can normalize this and get both positive and negative values?
Cris LaPierre
Cris LaPierre 2023-3-18
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:

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by