问题
This is a interpolation problem: I have a function z=z(x,y) and I know the relationship between x and y like x=f(y,x_0). Here x_0's are starting points of curves on time y=0. Let's assume x_0=[0 1 2] has three values. For each value of x_0, I get a curve in R^2.x1=f1(y),x2=f2(y) and x3=f3(y) and I draw z1,z2,z3 curves in R^3 using (x1,f1), (x2,f2) and (x3,f3). How can I interpolate z1,z2,23 for getting a surface? I will be grateful for any help, mgm
回答1:
Using your notation, and some arbitrary example relationships for x = f(x0, y) and z = f(x,y), this is how you do it (I also added a plot of the direct calculation for reference):
% Define grid
x0_orig = 0:2;
y_orig = 0:3;
[x0, y] = meshgrid(x0_orig, y_orig);
% Calculate x (replace the relationship with your own)
x = x0 + 0.1 * y.^2;
% Calculate z (replace the relationship with your own)
z = 0.1 * (x.^2 + y.^2);
% Plot
subplot(1,3,1)
surf(x, y, z)
xlabel('x')
ylabel('y')
zlabel('z')
title('Original data')
%%%%%%%%%%
% Interpolate with finer grid
x0i = 0:0.25:2;
yi = 0:0.25:3;
xi = interp2(x0_orig, y_orig, x, x0i, yi');
[x0i yi] = meshgrid(x0i, yi);
zi = interp2(x0, y, z, x0i, yi);
subplot(1,3,2)
surf(xi, yi, zi);
title('Interpolated data')
%%%%%%%%%%
% Recalculate directly with finer grid
x0i = 0:0.25:2;
yi = 0:0.25:3;
[x0i yi] = meshgrid(x0i, yi);
xi = x0i + 0.1 * yi.^2;
zi = 0.1 * (xi.^2 + yi.^2);
subplot(1,3,3)
surf(xi, yi, zi)
title('Recalculated directly')
来源:https://stackoverflow.com/questions/8195404/interpolation-curve-to-surface