フィルターのクリア

how to solve a system of equations in matlab

1 回表示 (過去 30 日間)
Jens Petit-jean
Jens Petit-jean 2020 年 11 月 29 日
回答済み: Ameer Hamza 2020 年 11 月 29 日
hello,
How do I solve this system of equations in matlab for F(-2:2) ?
f(x)= x+2 if x<=0
-x+2 if x>0
Apparently you can't use an if for this solution, but I don't really understand why either.
Thanks in advance

採用された回答

Alan Stevens
Alan Stevens 2020 年 11 月 29 日
編集済み: Alan Stevens 2020 年 11 月 29 日
Try this
f = @(x) (x+2).*(x<=0) + (-x+2).*(x>0);
(x<=0) returns 1's where it's true and 0 where it's false. Similarly for (x>0)
  1 件のコメント
Jens Petit-jean
Jens Petit-jean 2020 年 11 月 29 日
aaahhh thanks!

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

その他の回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 11 月 29 日
An alternate from symbolic toolbox
syms x
F = piecewise(x<=0, x+2, x>0, -x+2);
fplot(F, [-2 2])

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by