Ejemplos en Matlab Curso David Saenz

5
%EJEMPLO 5 %interpolacion unidimensional %suavizar datos horas=1:12; temps=[0 6 8 15 25 28 31 30 22 24 26 22] h=1:0.1:12; t=interp1(horas,temps,h,'spline'); plot(horas,temps,'--',horas,temps,'+',h,t); title('temperatures'); xlabel('horas');ylabel('°C'); %EJEMPLO 6 %archivo ejemplo6 %suavizar datos horas=1:12; temps=[0 6 8 15 25 28 31 30 22 24 26 22] h=1:0.1:12; [h,t]=interp_u(horas,temps); plot(horas,temps,'--',horas,temps,'+',h,t); title('temperatures'); xlabel('horas');ylabel('°C'); %EJEMPLO 7 %interpolacion bidimensional ancho=5; largo=3; temps=[82 81 80 82 84; 79 63 61 65 81; 84 84 82 85 86]; zm=interp2(temps,4,'cubic'); [renglones,columnas]=size(zm); ym=0:ancho/(renglones-1):ancho; xm=0:largo/(columnas-1):largo; surf(xm,ym,zm); xlabel('ancho del pan');ylabel('largo del pan');zlabel('°C'); title('temperatuas'); rotate3d on; %EJEMPLO 8 %interpolacion bidimensional

description

matlab ejemplos

Transcript of Ejemplos en Matlab Curso David Saenz

EJEMPLOS EN MATLAB

%EJEMPLO 5

%interpolacion unidimensional%suavizar datoshoras=1:12;

temps=[0 6 8 15 25 28 31 30 22 24 26 22]

h=1:0.1:12;

t=interp1(horas,temps,h,'spline');

plot(horas,temps,'--',horas,temps,'+',h,t);

title('temperatures');

xlabel('horas');ylabel('C');

%EJEMPLO 6

%archivo ejemplo6%suavizar datoshoras=1:12;

temps=[0 6 8 15 25 28 31 30 22 24 26 22]

h=1:0.1:12;

[h,t]=interp_u(horas,temps);

plot(horas,temps,'--',horas,temps,'+',h,t);

title('temperatures');

xlabel('horas');ylabel('C');

%EJEMPLO 7

%interpolacion bidimensionalancho=5;

largo=3;

temps=[82 81 80 82 84;

79 63 61 65 81;

84 84 82 85 86];

zm=interp2(temps,4,'cubic');

[renglones,columnas]=size(zm);

ym=0:ancho/(renglones-1):ancho;

xm=0:largo/(columnas-1):largo;

surf(xm,ym,zm);

xlabel('ancho del pan');ylabel('largo del pan');zlabel('C');

title('temperatuas');

rotate3d on;

%EJEMPLO 8

%interpolacion bidimensionalancho=5;

largo=3;

temps=[82 81 80 82 84;

79 63 61 65 81;

84 84 82 85 86];

zm=interp2(temps,3,'cubic');

[renglones,columnas]=size(zm);

ym=0:ancho/(renglones-1):ancho;

xm=0:largo/(columnas-1):largo;

colormap(hsv);

surfc(xm,ym,zm);

shading interp;

hold on;

pcolor(xm,ym,zm);

hold off;

xlabel('ancho del pan');ylabel('largo del pan');zlabel('C');

title('temperatuas');

rotate3d on;

%EJEMPLO 9

% minimizar y maximizarf='2*exp(-x)*sin(x)';

fplot(f,[0 8]);

title(f);

xlabel('x');

xmin=fmin(f,2,5);

ymin=2*exp(-xmin)*sin(xmin);

fx='2*exp(-x)*sin(x)';

xmax=fmin(fx,0,3);

ymax=2*exp(-xmax)*sin(xmax);

%%localizacion de cerosxcero=fzero(f,3,5)

ycero=2*exp(-xcero)*sin(xcero)

grid on;

%EJEMPLO 10%integracion y diferenciacionx=0:0.1:3;

y=2*exp(-x).*sin(x);

area=trapz(x,y)

%%mejoramiento de la aproximacionx1=0:.01:3;

y1=2*exp(-x1).*sin(x1);

area=trapz(x1,y1)

%%diferenciacionx=[0:0.1:1],

y=[-0.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.3 11.2];

n=2; %APROX. CUADRATICAp=polyfit(x,y,n);

xi=0:0.01:1;

z=polyval(p,xi);

plot(x,y,'o',x,y,xi,z,':');

xlabel('x');ylabel('f(x)');

title('curva de segundo orden');

pause;

pd=polyder(p);

z=polyval(pd,xi);

plot(xi,z);

xlabel('x');ylabel('dy/dx');

title('derivada de curva polinomial');

%EJEMPLO 11

%graficas 2Dx=0:2*pi/30:2*pi;

y=sin(x);

plot(x,y);

z=cos(x);

plot(x,y,x,z);

%%otra forma esw=[y;z]; %crea una matriz con la fnciones seno y cosenoplot(x,w); % representa w frente a xplot(w,x);

plot(x,y,'g:',x,y,'r--',x,y,'wo',x,y,'c+');

grid;

xlabel('x');ylabel('y');

title('curvas de seno y coseno');

text(2.5,0.7,'sen(x)');

gtext('cos(x)');

axis off;

axis ij;

axis xy;

a=2*sin(x).*cos(x);

b=sin(x)./(cos(x)+eps);

subplot(2,2,1);

plot(x,y);title('sen(x)');

subplot(2,2,2);

plot(x,a);title('2*sen(x)*cos(x)');

subplot(2,2,4);

plot(x,b);title('sen(x)/(cos(x)+eps)');

%%grafica de barrasx=-2.9:0.2:2.9;

y=exp(-x.*x);

clf;

bar(x,y);

title('dibujo de barra');

stairs(x,y);

title('dibujo de escalera');

clf;

x=-2.9:0.2:2.9;

y=randn(5000,1);

hist(y,x);

title('histograma');

%%graficast=0:pi/50:10*pi;

plot3(sin(t),cos(t),t);

title('elice');

xlabel('sent');

ylabel('cost');

zlabel('t');