Plotting odd and even periodic extensions of function.

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

回答(1 个)

Jaswanth
Jaswanth 2023-10-5
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.

类别

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

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by