% ========== % Apartado I % ========== % % * * * Ejemplo 1 * * * % Generación de la malla no equiespaciada con los datos clear all close all t=[-3,-2,-0.5,0,0.75,1.75,3]; [x,y]=meshgrid(t); z=peaks(x,y); % Generación de la malla fina para la interpolación [xi,yi]=meshgrid(-3:0.25:3); % Interpolación y comparación de resultados zi1=interp2(x,y,z,xi,yi,'nearest'); % usando vecinos más próximos zi2=interp2(x,y,z,xi,yi,'linear'); % usando bilinear zi3=interp2(x,y,z,xi,yi,'cubic'); % usando bicúbica figure(1);surfc(xi,yi,zi1);title('cercano'); hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(2);surfc(xi,yi,zi2);title('bilineal'); hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(3);surfc(xi,yi,zi3);title('bicubica') hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(4);surfc(xi,yi,peaks(xi,yi));title('funcion') hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(5); subplot(2,2,1);surfc(xi,yi,zi1);title('cercano'); subplot(2,2,2);surfc(xi,yi,zi2);title('bilineal'); subplot(2,2,3);surfc(xi,yi,zi3);title('bicubica') subplot(2,2,4);surfc(xi,yi,peaks(xi,yi));title('funcion') % %% * * * EJERCICIO 1 * * * % clear all close all a=pi; f=inline('exp(-(x.^2+y.^2)/4).*cos(x.^2+y.^2)'); [x,y]=meshgrid(linspace(-a,a,9)); z=f(x,y); % Generación de la malla fina para la interpolación [xi,yi]=meshgrid(linspace(-a,a)); % Interpolación y comparación de resultados zi1=interp2(x,y,z,xi,yi,'nearest'); % usando vecinos más próximos zi2=interp2(x,y,z,xi,yi,'linear'); % usando bilinear zi3=interp2(x,y,z,xi,yi,'cubic'); % usando bicúbica figure(1);surfc(xi,yi,zi1);title('cercano'); hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(2);surfc(xi,yi,zi2);title('bilineal'); hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(3);surfc(xi,yi,zi3);title('bicubica') hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(4);surfc(xi,yi,f(xi,yi));title('funcion') hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(5); subplot(2,2,1);surfc(xi,yi,zi1);title('cercano'); subplot(2,2,2);surfc(xi,yi,zi2);title('bilineal'); subplot(2,2,3);surfc(xi,yi,zi3);title('bicubica') subplot(2,2,4);surfc(xi,yi,f(xi,yi));title('funcion') % %% * * * EJERCICIO 2 * * * % clear all close all a=50; [x,y]=meshgrid(-50:25:50); z=[2.2256 11.2256 14.670 12.5589 4.8922; 5.8256 14.8256 18.2700 16.1589 8.4922; 7.4256 16.4256 19.8700 17.7589 10.0922; 7.0256 16.0256 19.4700 17.3589 9.6922; 4.6256 13.6256 17.0700 14.9589 7.2922]; f=inline('20-(x/15-0.2).^2-(y/25-0.3).^2'); %[x,y]=meshgrid(linspace(-a,a,5)) %z=f(x,y); % Generación de la malla fina para la interpolación [xi,yi]=meshgrid(linspace(-a,a)); % Interpolación y comparación de resultados zi1=interp2(x,y,z,xi,yi,'nearest'); % usando vecinos más próximos zi2=interp2(x,y,z,xi,yi,'linear'); % usando bilinear zi3=interp2(x,y,z,xi,yi,'cubic'); % usando bicúbica figure(1);surfc(xi,yi,zi1,'LineWidth',0.1);title('cercano'); hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(2);surfc(xi,yi,zi2);title('bilineal'); hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(3);surfc(xi,yi,zi3);title('bicubica') hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(4);surfc(xi,yi,f(xi,yi));title('funcion') hold on;plot3(x,y,z,'b.','markersize',20);hold off figure(5); subplot(2,2,1);surfc(xi,yi,zi1);title('cercano'); subplot(2,2,2);surfc(xi,yi,zi2);title('bilineal'); subplot(2,2,3);surfc(xi,yi,zi3);title('bicubica') subplot(2,2,4);surfc(xi,yi,f(xi,yi));title('funcion') % % ============ % Apartado 1.2 % ============ % % * * * Ejemplo 1 * * * f=inline('20-(x/15-0.2).^2-(y/25-0.3).^2'); % Generación de n puntos aleatorios en [-3,3] N=20;rand('state', 0);T=rand(2,N)*6-3; x=T(1,:);y=T(2,:); plot(x,y,'.','markersize',10) k = convhull(x,y); hold on, plot(x(k),y(k),'-r'), hold off grid on plot(x,y,'.','markersize',10) tri = delaunay(x,y); hold on, triplot(tri,x,y), hold off figure hidden on z=f(x,y); trimesh(tri,x,y,z) grid on zlabel('Altura') figure hidden on z=f(x,y); trisurf(tri,x,y,z) grid on zlabel('Altura') [xi,yi] = meshgrid(linspace(-3,3,51)); zi = griddata(x,y,z,xi,yi,'cubic'); [c,h] = contour(xi,yi,zi,'b-'); clabel(c,h) xlabel('Longitude'), ylabel('Latitude') figure;surfc(xi,yi,zi); hold on;plot3(x,y,z,'b.','markersize',20);hold off voronoi(x,y) grid on xlabel('Longitude'), ylabel('Latitude')