0

假设我们要确定一个多项式方程的系数,该多项式方程在 0 到 1 之间逼近正切函数,如下所示:

-A 是 m×n 范德蒙矩阵。使用 0 到 11 之间的 m 值填充条目(作为输入给出)。

- 使用正切函数计算相应的向量 b。

-x 是通过在 MATLAB 中键入 x= A\b 来计算的。

现在,使用 MATLAB,将计算得到的 x 代入 Ax。结果被绘制出来,它非常接近正切函数。但是如果我使用 n−1 度的 polyval 函数(在 MATLAB 中)来计算 b,则结果图与原始 b 有很大不同。我无法理解这两种方法的结果之间存在如此显着差异的原因。

这是代码:

clear all;
format long;
m = 60;
n = 11;
t = linspace(0,1,m);
A= fliplr(vander(t));
A=A(:,1:n);
b=tan(t');
x= A\b;
y=polyval(x, t);
plot(t,y,'r')
y2= A*x
hold on;
plot(t,y2,'g.');
hold on;
plot(t,tan(t),'--b');

任何见解将不胜感激。谢谢你。

4

1 回答 1

1

After A= fliplr(vander(t)) the A matrix is equal to

1 t(1) t(1)^2 ...
1 t(2) t(2)^2 ...
...
1 t(m) t(m)^2 ...

It is not correct because polyval accepts the coefficients in descending powers. You don't need to flip the columns of A:

A= vander(t);
A= A(:,end-n+1:end);
于 2016-09-24T04:58:13.667 回答