3D interpolation question
显示 更早的评论

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
回答(1 个)
David Goodmanson
2017-2-24
编辑:David Goodmanson
2017-2-24
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!