Plotting odd and even periodic extensions of function.

13 views (last 30 days)
Hi all,
i require to plot the odd and even period extenstions of a function. How can i do this?
The function is f(x) = cos (pi/2(x+3/4)) on x E [0,7]. Over the interval of [-6, 16].
any help with this would be greatly appreciated.
thanks

Answers (1)

Jaswanth
Jaswanth on 5 Oct 2023
Hi Ben Hischar,
I understand you would like to create plot of odd and even periodic extensions of the function f(x) = cos (pi/2(x+3/4)) [SNG1] on x E [0,7] over the interval [-6, 16].
Please follow the below code to create plots for odd and even periodic extension:
% Define the original function
f = @(x) cos(pi/2*(x+3/4));
original_interval = [0, 7];
% Create a vector of x-values within the desired interval
x1 = linspace(original_interval(1), original_interval(2), 1000);
% Evaluate the original function for the x-values
y_original = f(x1);
% Create a vector of x-values within the desired interval
extension_interval = [-6,16];
x2 = linspace(extension_interval(1), 0, 1000);
x3 = linspace(0,extension_interval(2) , 1000);
x = [x2 x3];
% Periodic Extension
period = 4; % Period of the function
y_positive = f(x3);
y_odd =[-f(-x2) y_positive];
y_even = [f(abs(x2)) y_positive];
% Plot the original function and the extensions
figure;
plot(x1, y_original, 'b', 'LineWidth', 1.5)
xlabel('x');
ylabel('f(x)');
legend('Original Function');
title('f(x) = cos(\pi/2(x+3/4))');
figure;
plot(x, y_odd, 'g:', 'LineWidth', 1.5)
xlabel('x');
ylabel('f(x)');
legend('Extension - Odd');
title('Odd Extensions of f(x) = cos(\pi/2(x+3/4))');
figure;
plot(x, y_even, 'r:', 'LineWidth', 1.5)
xlabel('x');
ylabel('f(x)');
legend('Extension - Even');
title('Even Extensions of f(x) = cos(\pi/2(x+3/4))');
Please refer to the following resources:
  1. MathWorks Documentation to create function handle: [SNG2] https://in.mathworks.com/help/matlab/matlab_prog/creating-a-function-handle.html?searchHighlight=function%20handle&s_tid=srchtitle_support_results_1_function%20handle
  2. “plot” function creates a 2-D line plot of the data in Y versus the corresponding values in X. Documentation for “plot” function - https://in.mathworks.com/help/matlab/ref/plot.html?searchHighlight=plot&s_tid=srchtitle_support_results_1_plot
Hope this helps.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!