how to plot this function?

1 visualizzazione (ultimi 30 giorni)
Niloufar
Niloufar il 5 Ott 2022
Commentato: Niloufar il 6 Ott 2022

Risposta accettata

Image Analyst
Image Analyst il 5 Ott 2022
Modificato: Image Analyst il 5 Ott 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;

Più risposte (1)

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

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by