Hi. How can i plot this equation between (-5,2) values
f(x) =
  • -1 ----> x<-1
  • x^2+x ------> -1 <= x < 2

 採用された回答

Star Strider
Star Strider 2018 年 3 月 16 日

0 投票

Use ‘logical indexing’:
x = linspace(-5,2);
f = @(x) (-1).*(x < -1) + (x.^2 + x).*((x >= -1) & (x < 2));
figure(1)
plot(x, f(x))
grid

2 件のコメント

Sam Oznc
Sam Oznc 2018 年 3 月 17 日
Thank you so much
Star Strider
Star Strider 2018 年 3 月 17 日
As always, my pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by