Clase 3 de Leng de Program

3
CLASE Nro. 03 DE LENGUAJE DE PROGRAMACION 1. GRAFICOS EN 3D: Para plotear una superficie en el espacio (3D), se requiere de tres pasos: - Generar la malla, es decir se genera el dominio (comando meshgrid) - Introducir la funcion que permite el rango de la funcion - Se plotea el grafico (comando surf) Ejemplo 1: plotear la superficie = 2 + 2 [x,y]=meshgrid(-3:3) x = 3 -2 -1 0 1 2 3 3 -2 -1 0 1 2 3 3 -2 -1 0 1 2 3 3 -2 -1 0 1 2 3 3 -2 -1 0 1 2 3 3 -2 -1 0 1 2 3 3 -2 -1 0 1 2 3 y = 3 -3 -3 -3 -3 -3 -3 2 -2 -2 -2 -2 -2 -2 1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3 z=x.^2+y.^2; surf(x,y,z) Mejorando el grafico con una malla mas fina delta=0.1 [x,y]=meshgrid(-3:0.1:3); z=x.^2+y.^2; surf(x,y,z) -4 -2 0 2 4 -4 -2 0 2 4 0 5 10 15 20

description

clase matlab

Transcript of Clase 3 de Leng de Program

Page 1: Clase 3 de Leng de Program

CLASE Nro. 03 DE LENGUAJE DE PROGRAMACION

1. GRAFICOS EN 3D:

Para plotear una superficie en el espacio (3D), se requiere de tres pasos:

- Generar la malla, es decir se genera el dominio (comando meshgrid)

- Introducir la funcion que permite el rango de la funcion

- Se plotea el grafico (comando surf)

Ejemplo 1: plotear la superficie 𝑧 = 𝑥2 + 𝑦2

[x,y]=meshgrid(-3:3)

x =

3 -2 -1 0 1 2 3

3 -2 -1 0 1 2 3

3 -2 -1 0 1 2 3

3 -2 -1 0 1 2 3

3 -2 -1 0 1 2 3

3 -2 -1 0 1 2 3

3 -2 -1 0 1 2 3 y =

3 -3 -3 -3 -3 -3 -3

2 -2 -2 -2 -2 -2 -2

1 -1 -1 -1 -1 -1 -1

0 0 0 0 0 0 0

1 1 1 1 1 1 1

2 2 2 2 2 2 2

3 3 3 3 3 3 3

z=x.^2+y.^2;

surf(x,y,z)

Mejorando el grafico con una malla mas fina delta=0.1 [x,y]=meshgrid(-3:0.1:3);

z=x.^2+y.^2;

surf(x,y,z)

-4

-2

0

2

4

-4

-2

0

2

40

5

10

15

20

Page 2: Clase 3 de Leng de Program

Ejemplo 2: Trazar la misma funcion en coordenadas cilindricas Generando la malla en coordenadas

cilindricas:

[r,theta]=meshgrid(0:.1:5,0:pi/40:2*pi);

convirtiendo a coordenadas cartesianas x=r.*cos(theta); y=r.*sin(theta);

Generando la funcion:

z=x.^2+y.^2;surf(x,y,z)

hold on

contour(x,y,z)

colorbar;

ploteando la superficie x=0

for i=1:2:7

x=x+i

end

Page 3: Clase 3 de Leng de Program

x =

0

x =

1

x =

4

x =

9

x =

16