0

I am trying to use 2D polynomial fitting for my table data, my data format is exactly like the link below: http://www.mathworks.de/help/toolbox/curvefit/brx2ldg-1.html#bso46rp-1

I mean I have vector X with length n, Y with length m and m*n Matrix Z, I would like to fit 5 degree 2d polynomial to my data,

I am wondering that is there any syntax in MATLAB for solving this problem? like SFIT command in IDL, http://star.pst.qub.ac.uk/idl/SFIT.html

I have cftool and sftool, but it seems that they don't work for this purpose or most probably I don't know how to employ them.

and I know that there some m.file which people share in MATLAB Mathworks file exchange, please if you know one works properly, suggest me.

I'd appreciate any help and comment.

4

1 回答 1

2

您可以使用文件交换中的polyfitn并重新格式化您的数据以获得 3 个MxN x,y,z向量。

示例

假设你有一个表格数据

N = 100; M = 80;
x = linspace(0, 1, M);
y = linspace(0, 1, N).';
z = bsxfun(@franke, x, y);

meshgrid为 x 和 y创建

N = 100; M = 80;
[x, y] = meshgrid(0:1:N, 0:1:M);
z = bsxfun(@franke, x, y);

(请注意,unique(x)andunique(y)将为您提供表格行和列的原始linspace值。)

使用polyfitn获得 5 次多项式系数

p = polyfitn([x(:),y(:)], z(:), 5);

您还可以使用提供的将结果转换为符号形式以查看多项式polyn2sym(p)

>> pretty(polyn2sym(p))

                      5                           4                             4                         3   2
     90264379051097 X1         2537627280433653 X1  X2       7778045812403061 X1       6982058230382053 X1  X2
- ------------------------- - -------------------------- + ------------------------ - -------------------------- + ...
  2417851639229258349412352   38685626227668133590597632   604462909807314587353088   77371252455336267181195264
于 2012-09-11T16:08:00.070 回答