フィルターのクリア

How to plot two piecewise functions on same graph?

1 回表示 (過去 30 日間)
Amna Habib
Amna Habib 2022 年 7 月 23 日
コメント済み: Walter Roberson 2022 年 7 月 27 日
I need to plot the attached functions on same plot. Please help me to write the Matlab code.
Thanks in advance!

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 7 月 23 日
range = [-2 2];
fplot([f, g] , range)
  17 件のコメント
Amna Habib
Amna Habib 2022 年 7 月 27 日
Thanks a lot @Walter Roberson. I appreciate your effort.
Walter Roberson
Walter Roberson 2022 年 7 月 27 日
Look more closely at your functions
f = @(x) (x<0.5) .* (30.*x) + (x>=0.5).* (70.*x)-20 ;
g = @(x) (x<0.5).* 30.*(1-x) + (x>=0.5).* 50-(70.*x ) ;
Notice that the -20 in f not being multiplied by any condition. Notice that the -70.*x in g is not being multiplied by any condition.

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

カテゴリ

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