I'm suppose to plot the conventional integral , but I'm getting wrong values
이전 댓글 표시
ok
댓글 수: 2
You need to specify the condition for the first 7 seconds given in your problem inside the loop as below
% Clear the workspace, close all figures, and clear command window
clc;
clear all;
close all;
% Given parameters
f1 = 3; % Amplitude of the forcing function
f2 = 0; % Second amplitude (set to 0)
T1 = 7; % Time period for first interval
T2 = 30; % Time period for second interval
T3 = 40; % Time period for third interval
zeta = 0.1; % Damping ratio
wn = 3; % Natural frequency
wd = wn * sqrt(1 - zeta^2); % Damped natural frequency
m = 1; % Mass
% Define symbolic variables
syms t tau;
% Define the forcing function F1(t)
F1 = (f1*t/ T1);
% Calculate damping coefficient
c1 = (1 / (m * wd));
A = 1;
% Define the impulse response function x1(tau)
x1 = A*(exp(-zeta * (t - tau))) * (sin(wd * (t - tau)));
x2 = exp(-zeta * (t - tau)) * (sin(wd * (t - tau)));
% Define expressions for each interval of x(t)
x_1 = c1 * int(x1, tau, 0, t);
x_2 = c1 * (int(x1, tau, 0, T1) + int(0, tau, T1, t));
x_3 = c1 * (int(x1, tau, 0, T1) + int(0, tau, T1, T2) + int(f2*x2, tau, T2, T3));
x_4 = c1 * (int(x1, tau, 0, T1) + int(0, tau, T1, T2) + int(f2*x2, tau, T2, T3) + int(0, tau, T3, t));
% Total expression for x(t)
X_total = x_1 + x_2+ x_3 + x_4;
% Define time vector
t_values = linspace(0, T3, 1000);
% Evaluate x(t) for each time point
x_values = zeros(size(t_values));
for i = 1:length(t_values)
if t_values(i) <= 7
x_values(i) = double(subs(F1, t, t_values(i))); % from the given conditions in your question
else
x_values(i) = double(subs(X_total, t, t_values(i)));
end
end
% Plot x(t)
plot(t_values, x_values, 'b', 'LineWidth', 2);
xlabel('Time (s)');
ylabel('Displacement (m)');
title('Displacement Response x(t)');
grid on;
Mohammad Adeeb
2024년 2월 12일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MuPAD에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


