How do I plot piecewise defined functions in different colours.

Good day
I want to write a program to plot piecewise defined functions on the same graph in different colour.The functions are:
F(x)=0.5X if X<=100 ; 50 +0.2(x-1000) if 100<x<=200 ; 75+0.5x if x>200
On same graph with
G(X)= 0.01X IF X<=75 ; 50+0.1(X-75) IF x>75
Note these may not be actual figures.Just for illustrative purposes.
Thanks.

1 件のコメント

Adam
Adam 2017 年 8 月 8 日
編集済み: Adam 2017 年 8 月 8 日
You'd have to just define each piece as its own plot and give them the colour you want. You can't multicolour a single plot object.
doc hold
shows how to keep existing plots on an axes when you add a new one.

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

回答 (1 件)

José-Luis
José-Luis 2017 年 8 月 8 日
編集済み: José-Luis 2017 年 8 月 8 日

0 投票

myFun = @(x) ((x<=100).*(0.5 .* x)) + ((x>100 & x<=200) .* (50+0.2.*(x-1000))) + ((x>200).*(75+(0.5.* x)));
fplot(myFun,[0, 300],'Color',rand(1,3));
Same principle can be applied for g(x).
Don't forget to hold on

1 件のコメント

bless Tsikaz
bless Tsikaz 2017 年 8 月 8 日
Thanks Jose.I will quickly try that out.

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

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

タグ

質問済み:

2017 年 8 月 8 日

コメント済み:

2017 年 8 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by