3D interpolation question
Show older comments

my code is
x=-2*pi:pi/4:2*pi;
y=-2*pi:pi/4:2*pi;
[x,y]=meshgrid(x,y);
z=sin(x).*cos(y);
[xfine,yfine]=meshgrid(-2*pi:0.1:2*pi);
zq=interp2(x,y,z,xfine,yfine);
ans1=zq(1,1);
save HW4_7.dat ans1 -ascii;
x=-2*pi:pi/20:2*pi;
y=-2*pi:pi/20:2*pi;
[x,y]=meshgrid(x,y);
z=sin(x).*cos(y);
[xfine,yfine]=meshgrid(-2*pi:0.1:2*pi);
zq=interp2(x,y,z,xfine,yfine);
ans1=zq(1,1);
save HW4_8.dat ans2 -ascii;
It can be run but the answer is not right, how can I modify my code? Plz help me
Answers (1)
David Goodmanson
on 24 Feb 2017
Edited: David Goodmanson
on 24 Feb 2017
0 votes
Hello S, You are close on this. Right now you are making a finer 81x81 matrix and looking at its 1,1 element, which is off in the corner and not anywhere near x = 1 and y = 1. You want the single observation point (1,1). To do that you can make the ultimate small matrices, namely scalars for the x and y coordinates of the observation point. If in each of the two cases you go with zq = interp2(x,y,z,1,1) you will get better results.
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!