Você está na página 1de 15

MATLAB 5.

3
Luciano Andr Farina
Maurcio Posser

Aula 1
Conceitos
Bsicos

Aula 1
Conceitos Bsicos

O que o MATLAB
Estrutura dos diretrios

MATLAB - ambiente de programao de


alto nvel
Estrutura dos diretrios
Caminho (path)
Comando de linha:
path(path,novodiretrio)
path(path,novodiretrio)

Aula 1
Conceitos Bsicos

Comandos de linha

workspace
Comandos bsicos
prompt
Armazenando valores
aa==44++22
aa==
66
bb==22**aa
bb==
12
12

55++77
ans
ans==
12
12
55**22
ans
ans==
10
10
22/ /33
ans
ans==
0.6667
0.6667
22^^33
ans=
ans=
88

Aula 1
Conceitos Bsicos

Comandos de linha

Comandos bsicos
HELP
WHO

Funes matemticas

CLC
WHICH

bsicos

DIARY
LOAD / SAVE

funes trigonomtricas:
sin; cos; tan; asin; acos;
atan
logaritmo decimal: log10

ver
help elfun
help specfun

DIR /
LS
CD
WHY

Smbolos e
constantes

logaritmo natural: log


exponencial: exp
valor absoluto: abs

CLEAR
WHAT

EPS
REALMIN/REALMAX
INF

NAN
PI

Aula 1
Conceitos Bsicos

Trabalhando com matrizes

Entrada de matrizes

(,) ou espao:
separador de coluna

(;) : separador
de linhas

a=[1,2;3,4]
a=[1,2;3,4]
aa ==
11
33

22
44

c=[-2.8
c=[-2.8 sqrt(7)
sqrt(7) (3+5+6)*3/4]
(3+5+6)*3/4]
cc ==
-2.8000
-2.8000

2.6458
2.6458

10.5000
10.5000

Qualquer expresso
MATLAB pode ser
elemento matriz

Aula 1
Conceitos Bsicos

A=

A(3,1)
A(3)

7.2

23

Trabalhando com matrizes

11

16

1.2 7

12

17

13

18

11 23

0.5 9

14

19

56 24

13

15

20

10

10

83

10

21

25 22

A(1:5,5)
A(:,5)
A(21:end)'

25

(:) especifica TODOS elementos


end especifica o valor de ndice mximo

A([4,5],[2,3])
A([9 14;10 15])

Aula 1
Conceitos Bsicos

Especificar: x-data e/ou y-data


Especificar: cor, estilo de linha e smbolo
marcador
Sintaxe para grfico com uma curva:
plot(xdata,
plot(xdata, ydata,
ydata, 'color_linestyle_marker')
'color_linestyle_marker')

Sintaxe para grfico com vrias curvas:


plot(x1,
plot(x1, y1,
y1, 'clm1',
'clm1', x2,
x2, y2,
y2, 'clm2',
'clm2', ...)
...)

Grficos

Aula 1
Conceitos Bsicos

Exemplo

xx == 0:0.1:2*pi;
0:0.1:2*pi;
yy == sin(x);
sin(x);
plot(x,y,'b')
plot(x,y,'b')

Grficos

Aula 1
Conceitos Bsicos

Exemplo - acrescentar mais curvas

xx == 0:.1:2*pi;
0:.1:2*pi;
yy == sin(x);
sin(x);
plot(x,y,'b')
plot(x,y,'b')
grid
grid on
on
hold
hold on
on
plot(x,exp(-x),'r:*')
plot(x,exp(-x),'r:*')

Grficos

Aula 1
Conceitos Bsicos

Grficos

subplot - exibe vrios grficos na mesma janela


subplot(#rows, #cols, number)

subplot(2,2,1);
subplot(2,2,1);
plot(1:10)
plot(1:10)
subplot(2,2,2)
subplot(2,2,2)
xx == 0:.1:2*pi;
0:.1:2*pi;
plot(x,sin(x))
plot(x,sin(x))
subplot(2,2,3)
subplot(2,2,3)
xx == 0:.1:2*pi;
0:.1:2*pi;

plot(x,exp(-x),'r')
plot(x,exp(-x),'r')
subplot(2,2,4)
subplot(2,2,4)
plot(peaks)
plot(peaks)

Aula 1
Conceitos Bsicos

Grficos

Eixos com escalas alternativas


plot(x,y)
Linear em
XeY

loglog(x,y)
Logartmico
XeY

semilogx(x,y)
Log X
Linear em Y
e Log. em Y

semilogy(x,y
)
Log Y
Linear em X
e Log. em Y

Aula 1
Conceitos Bsicos

x=-8:0.5:8;
x=-8:0.5:8;
y=x;
y=x;
[X,Y]=meshgrid(x,y);
[X,Y]=meshgrid(x,y);
R=sqrt(X.^2
R=sqrt(X.^2 ++ Y.^2)+eps;
Y.^2)+eps;
Z=sin(R)./R;
Z=sin(R)./R;
mesh(X,Y,Z)
mesh(X,Y,Z)

funo meshgrid : cria


matrizes malha a partir de
dois vetores.
vetores

Grficos

Aula 1
Conceitos Bsicos

x=-8:0.5:8;
x=-8:0.5:8;
y=x;
y=x;
[X,Y]=meshgrid(x,y);
[X,Y]=meshgrid(x,y);
R=sqrt(X.^2
R=sqrt(X.^2 ++ Y.^2)+eps;
Y.^2)+eps;
Z=sin(R)./R;
Z=sin(R)./R;
surf(X,Y,Z)
surf(X,Y,Z)
shading
shading interp
interp
camproj
camproj perspective
perspective

Grficos

Aula 1
Conceitos Bsicos

Grficos
comerciais

Outros tipos

Grficos

Aula 1
Conceitos Bsicos

Superfcies / Cmeras / Luzes


%% Isosurface
Isosurface of
of flow
flow data
data
isosurface(flow(20))
isosurface(flow(20))
daspect([1
daspect([1 11 1]);
1]); box
box on
on
view(3); axis vis3d tight; camva(6)
view(3); axis vis3d tight; camva(6)
camlight
camlight left;
left; lighting
lighting gouraud
gouraud
camproj
camproj perspective
perspective
colormap(hsv)
colormap(hsv)

Grficos

Você também pode gostar