Two dimensional interpolation polynomial
古いコメントを表示
Hello everyone.
I have a file which size is 681*441, it contains values measured at 300321 points. I want to find the interpolation polynomial. I have looked for functions which return what I am seeking; but I have found none. griddedinterpolant does not return the polynomial in question, but only values in a more precise grid. On the other hand, the function polyfit does provide with the nodes of a polynomial of any desired order, but it seems to work only in one dimension.
Can someone please tell me if there is a way to do as in the function polyfit but returning a two dimensional polynomial?
Thanks.
Jaime.
4 件のコメント
David K.
2019 年 9 月 25 日
I do not have any certainties on how to do this well, but if no one else has a way to do this I have some ideas. First, fitting a polynomial is at it's core an optimization problem so you could probably create your own 2d fitting with some of Matlab's optimization with fmincon. Where it is searching for the coefficients of the 2d polynomial and the cost that it is minimizing is the error off the real set of data. You would need to decide what degree of polynomial you want to search for. If you want to attach the actual file you have I could probably check it out and see how it goes.
Jaime De La Mota Sanchis
2019 年 9 月 25 日
編集済み: Jaime De La Mota Sanchis
2019 年 9 月 25 日
David K.
2019 年 9 月 25 日
Hm, actually I do not know if I understand your question. I thought you had data and was looking for the polynomial equation that fit it, but you already have said equation. Is this just a test example and you plan to apply to actual data to find the equations for?
You are also mentioning interpolation and I am not sure why gridded interpolant ot interp2 would not work with what you need it for.
Jaime De La Mota Sanchis
2019 年 9 月 25 日
採用された回答
その他の回答 (2 件)
John D'Errico
2019 年 9 月 26 日
0 投票
I don't think you realize that an interpolation polynomial that passes exctly through 300321 points will be impossible to evaluate in double precision arithmetic. In fact, it may require a precision that is on the order of many thousand of decimal digits to get any thing out if it. Possibly hundreds of thousands of digits will be required.
And then, expect complete crapola anyway. Why? Because the polynomial might actually predict the points, but give you meaningless garbage between the points!
Sharon Dolberg
2022 年 12 月 24 日
I wrote a multidimensional polyval function, a bit different from the original polyval. May it assist the users:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [a,ErrV]=polyvalN(MatIn,TargetIn)
[n,m]=size(MatIn);
MatOut=sum(pagemtimes(reshape(MatIn',m,1,n),reshape(MatIn',1,m,n)),3);
TargetOut=sum(MatIn.*TargetIn)';
a=MatOut\TargetOut;
ErrV=MatIn*a-TargetIn;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This function takes in a matrix MatIn which already includes the approximated structure for a linear approximated function (polynom) which the coefficient (a) of the approximated function needs to be found according to the target values TargetIn
for example:
------------
We have 8 points on a box
X=[-1;1;-1;1;-1;1;-1;1];
Y=[-1;-1;1;1;-1;-1;1;1]*2;
Z=[-1;-1;-1;-1;1;1;1;1]*0.5;
The approximated function which we intend to find the coefficients for is:
MatIn=[ones(8,1), X , Y , Z , X.*Y , X.*Z , Y.*Z ];
The value in each point is given. We can use rand or any known values in each point. Just in order to check the function polyvalN, we'll use known a's
intentionally:
TargetIn= 7 + 6*X + 5*Y + 4*Z + 3*X.*Y + 2*X.*Z + 1*Y.*Z;
Now, is we pose MatIn,TargetIn to polyvalN , we expect to get a's
[7;6;5;...1]
-------------
Notes:1. MatIn should be nXm wherein n>=m
TargetIn should be nx1
2. The point represented by X,Y,Z are not necessarily be in a box
structure as in the example. Actually, they can also represent any
single-dimension/multidimensional location, as long as note 1 is kept, and that MatIn includes
the vectors in the approximation.
カテゴリ
ヘルプ センター および File Exchange で Interpolation についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
