Is it possible to plot multiple equations with different intervals?

If I have three different equations for example y=x, y=x^2, and y=sqrt(x), is it possible to graph them over three different intervals on the same graph. Like y=x is plotted from 0 to a, y=x^2 is plotted a to b, and y=sqrt(x) is plotted from b to c?

 採用された回答

Star Strider
Star Strider 2014 年 10 月 24 日

3 投票

Yes.
For example:
x = [linspace(0,5,25); linspace(5,10,25); linspace(10,15,25)];
y = [x(1,:); x(2,:).^2; sqrt(x(3,:))];
figure(1)
plot(x', y')
grid
produces:
There are probably other ways of doing it, but this works.

4 件のコメント

John
John 2014 年 10 月 24 日
Star strider you come through again, thank you!
Star Strider
Star Strider 2014 年 10 月 24 日
My pleasure, as always!
Johan Ahlberg
Johan Ahlberg 2022 年 9 月 19 日
Hi, is there a way for the lines to be connected, as in that there is a straight line inbetween them?
@Johan Ahlberg — The point here was to not connect them. Connecting them simply requires reshaping the vectors —
x = [linspace(0,5,25); linspace(5,10,25); linspace(10,15,25)];
y = [x(1,:); x(2,:).^2; sqrt(x(3,:))];
figure(1)
plot(x', y')
grid
xlabel('X')
ylabel('Y')
title('Separated')
xv = reshape(x',1,[]);
yv = reshape(y',1,[]);
figure
plot(xv, yv)
grid
xlabel('X')
ylabel('Y')
title('Connected')
.

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2014 年 10 月 24 日

コメント済み:

2022 年 9 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by