how to plot this function?

1 view (last 30 days)
Niloufar
Niloufar on 5 Oct 2022
Commented: Niloufar on 6 Oct 2022

Accepted Answer

Image Analyst
Image Analyst on 5 Oct 2022
Edited: Image Analyst on 5 Oct 2022
Here is one way:
x = linspace(-pi, pi, 1000);
f = zeros(1, length(x));
f(abs(x) <= pi/2) = 1;
plot(x, f, 'b-', 'LineWidth', 2)
ylabel('f');
xlabel('x');
grid on;

More Answers (1)

Torsten
Torsten on 5 Oct 2022
f = @(x) abs(x)<=pi/2;
x = linspace(-pi,pi,200);
plot(x,f(x))

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!