How to plot a piecewise function on Matlab?

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 日

0 投票

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 件のコメント

Amna Habib
Amna Habib 2021 年 9 月 12 日
Thanks Dear Chunru! Please help me to plot both functions in a single plot.
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 件)

カテゴリ

質問済み:

2021 年 9 月 12 日

コメント済み:

2021 年 9 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by