[英]Constructing a spline equation in matlab/octave
I am aware that in matlab/octave, the polyfit can extrapolate constants used to build the polynomial equation that fits the given set of data x and y. 我知道在matlab / octave中, polyfit可以外推用于构建适合给定数据x和y的多项式方程的常数。 Polyout outputs the polynomial equation with its constants.
Polyout输出带有常数的多项式方程。 see below the link for the example:
请参阅下面的链接以获取示例:
https://en.wikibooks.org/wiki/Octave_Programming_Tutorial/Polynomials https://zh.wikibooks.org/wiki/Octave_Programming_Tutorial/多项式
How do I 'polyout' the splinefit constants to construct the equation? 我如何“溶解” 样条拟合常数以构造方程式? How do spline equation looks like?
样条方程看起来如何? Is it possible to polyfit an almost perfect line to 6 decimal precision?
是否可以将几乎完美的线polyfit到6位小数精度? Thanks.
谢谢。
n=5;
m=3; x=0:0.000001:1; y=asin(x);
p = polyfit(x,y,n);
f = polyval(p,x);
pp = splinefit(x,y,m);
g = ppval(pp,x);
plot(x,y,'o',x,f,'-',x,g,'o');
format long;
disp ("The value of p is:"), disp (p);
polyout(p, 'x');
disp ("The value of pp is:"), disp (pp);
I figure it out. 我知道了。 Unfortunately polyout(pp,'x') does not work for spline.
不幸的是polyout(pp,'x')不适用于样条曲线。 However, the results can be interpreted manually.
但是,结果可以手动解释。 For the following code:
对于以下代码:
x=0:0.1:1;
y=sin(x);
m=2;
format long;
disp ("The value of pp is:"), disp (pp)
Mathcad/Octave gives the answer it the following format: Mathcad / Octave给出以下格式的答案:
The value of pp is:
scalar structure containing the fields: 包含字段的标量结构:
form = pp
breaks =
0.000000000000000 0.500000000000000 1.000000000000000
coefs =
Columns 1 through 4:
7.91957255741094e-03 3.68579287957638e-04 -1.66790993823105e-01 1.71448144544173e-05
6.55744943740794e-03 2.01675106814849e-02 -1.46254903853663e-01 -2.39717011291503e-01
Columns 5 and 6:
9.99999254411779e-01 -1.23307748213508e-09
8.77582309927074e-01 4.79425560796454e-01
pieces = 2
order = 6
dim = 1
To interpret the output, the output means 为了解释输出,输出表示
y1= -1.23307748213508e-09 + 9.99999254411779e-01*(x-1) + 1.71448144544173e-05*(x-1)^2 .....up to eight polynomial (set up by "order" in spline equation.) y1 = -1.23307748213508e-09 + 9.99999254411779e-01 *(x-1)+ 1.71448144544173e-05 *(x-1)^ 2 .....最多八个多项式(由样条方程式中的“阶数”设置) )
y2 = the same way with the second row except instead (x-1) there is (x -1.5) defined by pieces. y2 =与第二行相同,除了(x-1)以外,(x -1.5)由小块定义。 Hence y = y1 + y2
因此y = y1 + y2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.