将函数的间隔放在一起

时间:2017-01-29 13:20:55

标签: matlab geometry

我有这些功能,并希望将它们放在一个窗口中(使用绘图功能),以便生成复合和平滑功能。

x1 = linspace(0, 0.5, 1000);
y1 = coordinates(1)*x1.^3 + coordinates(2)*x1.^2 + coordinates(3)*x1 + coordinates(4);

x2 = linspace(0.5, 1, 1000);
y2 = coordinates(5)*x2.^3 + coordinates(6)*x2.^2 + coordinates(7)*x2 + coordinates(8);

x3 = linspace(1, 6, 1000);
y3 = coordinates(9)*x3.^3 + coordinates(10)*x3.^2 + coordinates(11)*x3 + coordinates(12);

x4 = linspace(6, 7, 1000);
y4 = coordinates(13)*x4.^3 + coordinates(14)*x4.^2 + coordinates(15)*x4 + coordinates(16);

x5 = linspace(7, 9 ,1000);
y5 = coordinates(17)*x5.^3 + coordinates(18)*x5.^2 + coordinates(19)*x5 + coordinates(20);

如您所见,我在坐标中保存了一些值。您不需要此值。我只想知道如何将绘图功能的部件放在一个窗口中。如下图所示(使用GeoGebra的示例),我想将单个函数放在一个intervall中并接收一个函数: enter image description here

1 个答案:

答案 0 :(得分:2)

您可以使用plot功能指定要绘制的所有数据集。

在对plot的调用中,您还可以指定每个细分的颜色。

您可以使用text功能在图上添加一些文字/标签。

作为三组数据的示例(x1, y1)(x2, y2)(x3, y3)

figure

x1 = linspace(0, 0.5, 1000);
y1 = x1.^2;

x2 = linspace(0.5, 1, 1000);
y2 = x2.^2;

x3 = linspace(1, 2, 1000);
y3 = x3.^2;

plot(x1,y1,'r',x2,y2,'g',x3,y3,'b','linewidth',2)
hold on
text(x1(3),y1(3),'A')
text(x2(3),y2(3),'B')
text(x3(3),y3(3),'C')

grid minor

enter image description here

希望这有帮助。

Qapla'