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

Risposte (1)

David Goodmanson
David Goodmanson il 24 Feb 2017
Modificato: David Goodmanson il 24 Feb 2017

0 voti

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.

Categorie

Scopri di più su Interpolation in Centro assistenza e File Exchange

Richiesto:

il 24 Feb 2017

Modificato:

il 24 Feb 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by