如何将任何点添加到分段 fplot?

How do I add any point to a piecewise fplot?

我的任务是寻找自然三次样条函数 S 来对我提供的一组数据进行插值。我得到了 11 个数据点。从本质上讲,这意味着我必须在这些点之间放置一个三次函数,这样我就有 10 个三次函数,它们一起流入看起来像 1 个函数的东西。

我已经完成了这个。我是 MatLab 的新手,所以我不确定我应该如何在这个图上加上点。

由于我必须将 10 个函数粘合在一起的性质,我找到了一个名为 piecewise 的函数,它非常适用于此。以下是我如何定义分段函数:

syms S(t)
S(t) = piecewise(x(1)<t<x(2), (longExpression1), x(2)<t<x(3), (longExpression2), ... x(10)<t<x(11), (longExpression10));

然后我用 fplot() 绘制函数并定义我想要查看绘图的域:

fplot(S(t), [0,100]);

我需要在此图上绘制 13 个点。 我需要绘制的前 11 个点是位于每个线段末端的点。我需要绘制的最后 2 个点不是端点,而是两个不同分段段中间某处的点。

这 11 个数据点具有以下 x 和 y 值:

x = [0 10 20 30 40 50 60 70 80 90 100];
y = [75.995 91.972 105.711 123.203 131.669 150.697 179.323 203.212 226.505 249.633 281.422];

我的情节是这样的:

您可以尝试以下方法:

fplot(S(t), [0,100]);
hold on         % This will prevent the new plot from erasing the result of fplot
plot(x,y,'or'); % 'ok' is a format identifier, the points will be plot as red(r) circles(o)
plot([x1,X2],[S(x1),S(x2)],'or'); %Plot the two extra points