4 views (last 30 days)

Hi,

I am a beginner in Matlab and I have to understand a code.

I don't understand this part where they want to do a quadratic interpolation of unevenly spaced points into a grid

for i = 1:X

for j = 1:Y

closest_pts = [x,y,z, zeros(length(x),1)];

% Find distance of each data point to the current grid point

closest_pts(:,4)= sqrt((closest_pts(:,1)-pos(1)).^2 + (closest_pts(:,2)-pos(2)).^2);

% Use surface fitting to find interpolated displacement at 'pos'

Xf = closest_pts(1:num,1); Yf = closest_pts(1:num,2); Uf = closest_pts(1:num,3);

P = zeros(num,6);

P(:,1) = 1;

P(:,2) = Xf;

P(:,3) = Yf;

P(:,4) = Xf.^2;

P(:,5) = Yf.^2;

P(:,6) = Xf.*Yf;

%This is a standard method of finding the least squares

%solution for a system of equation (see 'Linear Algebra With

%Applications' by Otto Bretscher)

a = pinv(P'*P)*P'*Uf;

interp = a(1) + a(2)*pos(1) + a(3)*pos(2) + a(4)*(pos(1)^2)+...

a(5)*(pos(2)^2) + a(6)*pos(1)*pos(2);

I do understand that interp has the form ax^2+bxy+cy^2+dx+ey+f=z because it is a quadratic interpolation, and I think it is thanks to Vandermonde matrix due to the construction of P...

but I don't understand : a = pinv(P'*P)*P'*Uf;

Maybe it is just gaps in my knowledge of mathematics...

Thank you for your help!!

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/309162-quadratic-interpolation-with-vandermonde-matrix-why-the-use-of-pinv#comment_401684

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/309162-quadratic-interpolation-with-vandermonde-matrix-why-the-use-of-pinv#comment_401684

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/309162-quadratic-interpolation-with-vandermonde-matrix-why-the-use-of-pinv#comment_401700

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/309162-quadratic-interpolation-with-vandermonde-matrix-why-the-use-of-pinv#comment_401700

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/309162-quadratic-interpolation-with-vandermonde-matrix-why-the-use-of-pinv#comment_401717

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/309162-quadratic-interpolation-with-vandermonde-matrix-why-the-use-of-pinv#comment_401717

Sign in to comment.