【源码】实现n维曲线拟合的polyfitn函数(替代polyfit函数)

Polyfitn函数是polyfit的扩展,允许用户实现多个独立变量的模型拟合。

Polyfitn is an extension of polyfit, allowing the user to create models with more than one independent variable.

允许用户自定义通用的模型,例如,具有常数项和二次项、但没有线性项的二次模型。

It also allows the user to specify a general model, for example, a quadratic model, with constant and quadratic terms, but no linear term.

例如,为了将余弦曲线中选择的点拟合为多项式模型,我们只需要偶数阶项。

For example, to fit a polynomial model to points selected from a cosine curve, we will only need the even ordered terms.

x = -2:.1:2;
y = cos(x);
p = polyfitn(x,y,‘constant x^2 x^4 x^6’);
p.Coefficients
ans =
[0.99996 -0.49968 0.041242 -0.0012079]

x = rand(100,1);
y = rand(100,1);
z = exp(x+y) + randn(100,1)/100;
p = polyfitn([x,y],z,3);

源码下载地址:

http://page5.dfpan.com/fs/7ldcaj32e2311239163/

更多精彩文章请关注微信号:在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42825609/article/details/85111261
今日推荐