how do I Make two surfaces to equal dimensions
Show older comments
%A. Create two vectors x=[-2:0.75:2], and y=[-2:0.75:2].
%B. Create two matrices X and Y using meshgrid.
xa=-2:0.75:2
ya= -2:0.75:2;
[Xa,Ya]= meshgrid(xa,ya);
% C. Using “surf” plot the function
% f(x,y)=sin(sqrt(x^2+y^2))/sqrt( x^2+y^2).
fa= sin(sqrt(Xa.^2+Ya.^2))./sqrt( Xa.^2+Ya.^2);
size(fa)
surf(Xa,Ya,fa);
title ('surf(X,Y,f) num1')
serf 2 :
% D. Interpolate the function (with interp2)
% using the “cubic” method to resolution of
% dx=dy=0.2.
xd=-2:0.75:2
yd= -2:0.75:2;
[Xd,Yd]= meshgrid(xd,yd);
[xxd,yyd]=meshgrid(-2:0.2:2);% presaice meshgrid
% f= sin(sqrt(X.^2+Y.^2))./sqrt( X.^2+Y.^2);
zzd = interp2(Xd,Yd,f,xxd,yyd)%interpulation of X Y to [xx,yy]
%E. Plot the new interpolated function.
size(zzd)
Answers (1)
Star Strider
on 29 Dec 2017
Your code needs a few minor tweaks to work. You essentially did everything correctly. (I will let you find the changes I made.)
The Code —
%A. Create two vectors x=[-2:0.75:2], and y=[-2:0.75:2].
%B. Create two matrices X and Y using meshgrid.
xa=-2:0.75:2;
ya= -2:0.75:2;
[Xa,Ya]= meshgrid(xa,ya);
% C. Using “surf” plot the function
% f(x,y)=sin(sqrt(x^2+y^2))/sqrt( x^2+y^2).
fa= sin(sqrt(Xa.^2+Ya.^2))./sqrt( Xa.^2+Ya.^2);
size(fa)
figure(1)
surf(Xa,Ya,fa);
title ('surf(X,Y,f) num1')
% serf 2 :
% D. Interpolate the function (with interp2)
% using the “cubic” method to resolution of
% dx=dy=0.2.
xd=-2:0.75:2;
yd= -2:0.75:2;
[Xd,Yd]= meshgrid(xd,yd);
[xxd,yyd]=meshgrid(-2:0.2:2);% presaice meshgrid
f = @(X,Y) sin(sqrt(X.^2+Y.^2))./sqrt( X.^2+Y.^2);
zzd = interp2(Xd,Yd,fa,xxd,yyd,'cubic'); %interpulation of X Y to [xx,yy]
%E. Plot the new interpolated function.
size(zzd)
figure(2)
surf(xxd, yyd, zzd)
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!