How to plot a piecewise function on Matlab?

조회 수: 99 (최근 30일)
Amna Habib
Amna Habib 2021년 9월 12일
댓글: Amna Habib 2021년 9월 12일
I need to plot the two piecewisely defined functions on the same graph. Please help me to write code. Thanks in advance.
f(x)= 1-sqrt{5-x} for x =<5,
1 for 5=< x =<7,
1-sqrt{(x-7)/3} for x =>7.
Similarly,
g(x)= sqrt{(5-x)/2} for x =<5,
0 for 5=< x =<7,
sqrt{(x-7)/5} for x =>7.

채택된 답변

Chunru
Chunru 2021년 9월 12일
편집: Chunru 2021년 9월 12일
You can try the another function.
syms f(x)
f(x) = piecewise(x<=5, 1-sqrt(5-x), 5<x<7, 1, x>=7, 1-sqrt((x-7)/3) )
f(x) = 
fplot(f, [0 10])
  댓글 수: 3
Chunru
Chunru 2021년 9월 12일
Try define another function. Then "hold on"; and plot the function.
Amna Habib
Amna Habib 2021년 9월 12일
Ok, Thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by