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!