Borrar filtros
Borrar filtros

Plot the periodic function.

31 visualizaciones (últimos 30 días)
NIBISHA
NIBISHA el 1 de En. de 2024
Respondida: Ayush el 1 de En. de 2024
  1 comentario
KSSV
KSSV el 1 de En. de 2024
What have you attempted for your home work?

Iniciar sesión para comentar.

Respuestas (2)

recent works
recent works el 1 de En. de 2024
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 comentario
Walter Roberson
Walter Roberson el 1 de En. de 2024
This appears to be python code; the stated requirements are that MATLAB code must be used.

Iniciar sesión para comentar.


Ayush
Ayush el 1 de En. de 2024
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

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by