필터 지우기
필터 지우기

Plot the periodic function.

조회 수: 12 (최근 30일)
NIBISHA
NIBISHA 2024년 1월 1일
답변: Ayush 2024년 1월 1일
  댓글 수: 1
KSSV
KSSV 2024년 1월 1일
What have you attempted for your home work?

댓글을 달려면 로그인하십시오.

답변 (2개)

recent works
recent works 2024년 1월 1일
import matplotlib.pyplot as plt
# Define the periodic function
def f(x):
if x % 4 < 2:
return 1/2
else:
return -1/2
# Generate x-axis values
x = range(0, 16)
# Calculate y-axis values
y = [f(i) for i in x]
# Plot the function
plt.plot(x, y)
# Set plot labels and title
plt.xlabel("x")
plt.ylabel("f(x)")
plt.title("Periodic Function")
# Set axis limits
plt.xlim(0, 16)
plt.ylim(-1/2, 1/2)
# Show the plot
plt.grid(True)
plt.show()
Key points:
  • Period: The function repeats every 4 units along the x-axis.
  • Amplitude: The function oscillates between 1/2 and -1/2.
  • Shape: The function has a rectangular shape within each period.
  • Discontinuities: The function has jumps at x = 2 and x = 4, where it changes value abruptly.
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 1월 1일
This appears to be python code; the stated requirements are that MATLAB code must be used.

댓글을 달려면 로그인하십시오.


Ayush
Ayush 2024년 1월 1일
I understand that you want to get the Laplace Transform of your equation and verify the results through MATLAB code. Here is the MATLAB code for that:
syms t s
% Define one period of the piecewise function using heaviside functions
f_t_period = 0.5 * (heaviside(t) - heaviside(t - 2)) - 0.5 * (heaviside(t - 2) - heaviside(t - 4));
% Define the periodic extension of the function
f_t = f_t_period - subs(f_t_period, t, t - 4);
% Define the period
T = 4;
% Compute the Laplace transform of one period of the function
F_s = (1 - exp(-s*T))^(-1) * int(f_t_period * exp(-s*t), t, 0, T);
% Plot the original piecewise function over multiple periods
num_periods = 3; % Number of periods to plot
t_vals = linspace(0, num_periods*T, 1000); % Define time values for plotting
f_vals = double(subs(f_t, t, mod(t_vals, T))); % Evaluate f(t) at the time values with modulo for periodicity
figure;
subplot(2, 1, 1);
plot(t_vals, f_vals, 'LineWidth', 2);
title('Original Periodic Function f(t)');
xlabel('Time t');
ylabel('f(t)');
axis([0 num_periods*T -1 1]);
grid on;
% Plot the real part of the Laplace transform over a range of s values
% We avoid s = 0 to prevent division by zero
s_vals = linspace(0.01, 10, 200); % Define s values for plotting, starting just above zero
F_vals = double(subs(F_s, s, s_vals)); % Evaluate F(s) at the s values
subplot(2, 1, 2);
plot(s_vals, real(F_vals), 'LineWidth', 2); % Plot only the real part
title('Laplace Transform F(s)');
xlabel('s');
ylabel('Real part of F(s)');
grid on;
Thanks,
Ayush

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by