0
私たちにはn x nのデータが与えられます。 funxtionを近似してください。 たとえば、 2(1,1)、3(1,2)、4(2,1)、5(2,2) 2つのD-ultinomialを$ 0 * x * y + yとして補間する必要があります+ 2 * x-1 $である。MATLAB。補間法で二次多項式を得るにはどうすればいいですか?
私たちにはn x nのデータが与えられます。 funxtionを近似してください。 たとえば、 2(1,1)、3(1,2)、4(2,1)、5(2,2) 2つのD-ultinomialを$ 0 * x * y + yとして補間する必要があります+ 2 * x-1 $である。MATLAB。補間法で二次多項式を得るにはどうすればいいですか?
この問題は、mldivide関数を使用して解くのは簡単な一次方程式の集合として定式化できます。
私があなたが含まれている例を使ってこれを説明しましょう。
% 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]
ステートメントp = [xy,y,x,c] \ out
問題がoverconstrainedれる最適係数(最小二乗誤差)(すなわち解が正確すべての方程式を満たすに存在していない)を算出します。しかし、変数があるだけの数式があれば(この例のように、4つの入出力ペアのため4つの式があり、推定する必要のある4つの係数がある)、係数は簡単にp = inv([xy,y,x,c]) * out
で計算できます。