0

我有两个数组;

R = [r0, r1, r2, ..., r999]

Z = [z0, z1, z2, ..., z999]

我想将 polyfit 应用于上述函数,其中函数为 R(z)。我需要多项式为 x^2+x^4+x^6+x^8

在 excel 中,趋势函数不允许仅使用偶次幂,因此我尝试在 Matlab 中编写此代码,但我无法弄清楚如何自定义 polyfit 以使其仅使用上述偶次幂。

有什么建议么?谢谢

4

1 回答 1

1

您可以使用线性代数中的最小二乘法来解决这个问题:

% The Data
R = [r0, r1, r2, ..., r999]'; % Note the apostrophe
Z = [z0, z1, z2, ..., z999]';

% Create Vandermonde-ish matrix
X = [Z.^2 Z.^4 Z.^6 Z.^8];

% Solve equation system
a = X\R;

% Reshape and pad with zeros for the odd and 0th powers
p = [zeros(size(a)) a]';
pval = flip([0; p(:)]);
于 2016-08-09T15:30:23.243 回答