Quadratic interpolation of an N dim array

119 ビュー (過去 30 日間)
Ano
Ano 2018 年 4 月 26 日
コメント済み: Ameer Hamza 2018 年 4 月 27 日
Hello I would to know how I can perform a quadratic interpolation of an array using matlab ? it is worth mentioning that I am using interp1 for now. thank you!

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 4 月 26 日
You can use polyfit(), and fit a polynomial of order two.
coefficients = polyfit(x, y, 2);
Then to interpolate the value use
interpolatedValues = polyval(coefficients, xq); % xq vector of points where you want to interpolate
  4 件のコメント
Ano
Ano 2018 年 4 月 27 日
編集済み: Ano 2018 年 4 月 27 日
Please find bellow how x and y should look like:
x = [1 3 5];
y(:,:,1) = [0.5 0.6 0.9 ; -1 -3 5;0.2 0.01 -3+1i];
it is worth mentioning that x is the third dim of y and they will not have the same length always. thank you!
Ameer Hamza
Ameer Hamza 2018 年 4 月 27 日
In training phase of interpolation you need to vector x and y of equal length. Because by definition of interpolation, you are trying to estimate a function f: x -> y, which will best (e.g. in the least square sense) model the relation between x and y. This requires training dataset to have the same length of x and y.
After training is complete, you can use f to estimate y value at points xq for which you don't know the actual value of y, using f(xq).

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 4 月 26 日
A = [x(:).^2, x(:), ones(numel(x),1)];
b = y;
coefficients = (A\b).';
This code is fine with x being either a row vector or column vector. The code expects that you are doing the quadratic fitting over each column of y independently (not over the rows.)
The array of coefficients that results will be N x 3 where N is the number of columns of y. The order of the coefficients will be the x^2 coefficient, then the x coefficient, then the constant.

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by