How to plot two piecewise functions on same graph?

조회 수: 3 (최근 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 CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by