how to plot this function?

4 vues (au cours des 30 derniers jours)
Niloufar
Niloufar le 5 Oct 2022
Commenté : Niloufar le 6 Oct 2022

Réponse acceptée

Image Analyst
Image Analyst le 5 Oct 2022
Modifié(e) : Image Analyst le 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;
  1 commentaire
Niloufar
Niloufar le 6 Oct 2022
thank you for your help

Connectez-vous pour commenter.

Plus de réponses (1)

Torsten
Torsten le 5 Oct 2022
f = @(x) abs(x)<=pi/2;
x = linspace(-pi,pi,200);
plot(x,f(x))
  1 commentaire
Niloufar
Niloufar le 6 Oct 2022
it worked thank you so much

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by