grÁficas en matlab - upibi.net · los gráficos 2-d de matlab están fundamentalmente orientados a...

27
S eguridad en Internet Oriol Roca G r á f i c a s GRÁFICAS EN MATLAB M a t L a b www.upibi.net

Upload: phunglien

Post on 21-Sep-2018

239 views

Category:

Documents


0 download

TRANSCRIPT

S eguridad en InternetOriol RocaG r á f i c a s

GRÁFICAS EN MATLAB

M a t L a b

www.upibi.net

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Funciones orientadas a añadir títulos al gráfico

title('título') añade un título al dibujo.

xlabel('tal') añade una etiqueta al eje de abscisas. Con xlabel off desaparece.

ylabel('cual') añade una etiqueta al eje de ordenadas. Con ylabel off desaparece.

text(x,y,'texto') introduce 'texto' en el lugar especificado por las coordenadas x e y. Si x e y son vectores, el texto se repite por cada par de elementos. Si texto es también un vector de cadenas de texto de la misma dimensión, cada elemento se escribe en las coordenadas correspondientes.

grid activa la inclusión de una cuadrícula en el dibujo. Con grid off desaparece la cuadrícula

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Gráficas 2D

Los gráficos 2-D de MATLAB están fundamentalmente orientados a la representación gráfica de vectores (y matrices). En el caso más sencillo los argumentos básicos de la función plot van a ser vectores.

Ejemplo: definimos los siguientes vectores en el Comand Windows

plot(x,y)

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Graficamos en Comand Windows:

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Colores, markers y estilos de línea.

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Funciones de la forma y = f(x)

Ejemplo: definimos los siguientes vectores en el Comand Windows

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Funciones de la forma y = f(x)

Por último graficamos: plot(x,y)

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

plot(x,y,'r*')

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Podemos graficar dos o mas funciones en una misma gráfica

Se utilizan para ello los comandos hold on y hold off. El primero de ellos hace que los gráficos sucesivos respeten los que ya se han dibujado en la figura (es posible que haya que modificar la escala de los ejes); el comando hold off deshace el efecto de hold on.

Para y = sin x y y = cos x sobre el intervalo de [0, 4π].

Definimos x:

Definimos la función y graficamos:

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Podemos graficar dos o mas funciones en una misma gráfica

Ahora activamos el comando:

Y definimos la siguiente función y graficamos:

Aplicamos un texto para cada gráfica de la función:

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Podemos graficar dos o mas funciones en una misma gráfica:

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

También lo podemos hacer de la siguiente manera:

y=sin(x);

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Ejercicios

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Ejercicios

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Ejercicios

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

GRÁFICAS 3D

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Gráficas 3D

La primera forma de gráfico 3D es la función plot3, que es el análogo tridimensional de la función plot. Esta función dibuja puntos cuyas coordenadas están contenidas en 3 vectores.

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Gráficas 3D

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Gráficas 3D

Ejercicios: Representar las curvas siguientes y representar en gráfica.

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Gráficas 3D

MallasPor ejemplo, si queremos dibujar la gráfica de la función:

Generamos el mallado:

Sustituimos en la función para calcular los valores de z

[x,y]=meshgrid(-2:0.1:2);

z=exp(-x.^2-y.^2);

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Gráficas 3D

Y ahora podemos dibujar el gráfico con alguno de los siguientes comandos que producen los dibujos mostrados en la figura.

mesh(x,y,z) Malla

surf(x,y,z) Superficie

meshz(x,y,z) Malla con cortina

meshc(x,y,z) Malla c/contorno

surfc(x,y,z) Superficie c/contorno

surfl(x,y,z) Superficie con alumbrado

waterfall(x,y,z) Cascada

contour(x,y,z,n) Contorno

n= número de niveles (opcional)

S eguridad en InternetOriol RocaG r á f i c a s M a t L a b

www.upibi.net

Gráficas 3D