We are given a n x n data. Approximate the funxtion. For example. If we are given 2(1,1), 3(1,2), 4(2,1), 5(2,2) Then we have to interpolate the 2 D- ultinomial as $0*x*y+y+2*x-1$.
Asked
Active
Viewed 69 times
1 Answers
0
This problem can be formulated as a set of linear equations, which are trivial to solve using mldivide function.
Let me illustrate this using the example you included.
% from the given example
in = [...
1,1;
1,2;
2,1;
2,2];
out = [...
2;
3;
4;
5];
% compute the variable terms in the polynomial
x = in(:,1);
y = in(:,2);
xy = x .* y;
c = ones(size(out)); % constant
% compute the coefficients of the polynomial
p = [xy,y,x,c] \ out;
% result: [0; 1; 2; -1]
The statementp = [xy,y,x,c] \ out
computes the optimal coefficients (least-square error) when the problem is overconstrained (i.e. no solution exists to exactly satisfy all equations). But if there are only as many equations as there are variables (like in this example, there are 4 equations due to 4 input-output pairs and there are 4 coefficients that need to be estimated), then the coefficients can be computed simply by p = inv([xy,y,x,c]) * out
.

aksadv
- 806
- 5
- 6