Professional Documents
Culture Documents
INFORMACIJSKIH TEHNOLOGIJA
Zavod za komunikacije
Teorija informacije
Laboratorijska vježba broj 1
Matlab – uputstva
MATLAB je softverski paket za:
- rješavanje matematičkih problema,
- analizu podataka i
- vizualizaciju.
Rad s matricama
- matrica A se može napraviti na slijedeći način:
A 1 3 2 1
= 6 3
5 1 1 8
0 1
9 6 7 1
2
4 1 1 1
5 4
sum(A)
ans =
34 34 34 34
ans =
- naredba sum() daje sumu po stupcima, a ako tražimo sume redaka onda je
potrebno tražiti sumu transponirane matrice te rezultat također transponirati kako bi
se dobio odgovarajući ispis:
sum(A')'
ans =
3
4
34
34
34
sum(sum(A))
ans =
136
diag(A)
daje
ans =
16
10
7
1
sum(diag(A))
ans = 34
sum(diag(fliplr(A))
) ans = 34
A(4,5)
X=A
X 1 3 2 1
= 6 3
5 1 1 8
0 1
9 6 7 1
2
4 1 1 1
5 4
X(4,5)= 17
X 1 3 2 1 0
= 6 3
5 1 1 8 0
0 1
9 6 7 1 0
2
4 1 1 1 1
5 4 7
Rad s funkcijama
- Matlab posjeduje velik broj ugrađenih funkcija
- popis funkcija možemo dobiti na slijedeći način:
help
rand
help exp
ans =
2.2251e-308
realmax
ans =
1.7977e+30
- Kontrola toka programa - podržava if, switch, case, for petlju, while petlju,
break...
type rank
function r = rank(A,tol)
%RANK Matrix rank.
% RANK(A) provides an estimate of the number of linearly
% independent rows or columns of a matrix A.
% RANK(A,tol) is the number of singular values of A
% that are larger than tol.
% RANK(A) uses the default tol = max(size(A)) * norm(A) * eps.
s = svd(A);
if
nargin==1
tol = max(size(A)') * max(s) *
eps; end
r = sum(s > tol);
Rad s grafikom
- osnovna funkcija je plot
t =
Teorija informacije, Laboratorijska vježba br.1 4
0:pi/100:2*pi; y
= sin(t);
plot(t,y)
y2 = sin(t-.25);
y3 = sin(t-.5);
plot(t,y,t,y2,t,y3)
plot(t, y, 'r:+')
hold on
[x,y,z] = peaks;
contour(x,y,z,20,'k'
) hold on
pcolor(x,y,z)
shading interp
t = 0:pi/10:2*pi;
[X,Y,Z] =
cylinder(4*cos(t));
subplot(2,2,1)
mesh(X)
subplot(2,2,2)
; mesh(Y)
subplot(2,2,3)
; mesh(Z)
subplot(2,2,4)
;
mesh(X,Y,Z)
t = 0:pi/10:2*pi;
help
graphics
help plot
f(x) = sin(x)
>> t = [-2*pi:0.01:2*pi];
>> x = sin(t);
>> plot(t,x);
>> xlabel('Vrijeme[s]');
>> ylabel('Amplituda');
>> title('Graf funkcije f(x)=sin(x) / Deni Kolačko')
f(x) = sinc(x)
>> t = [-2*pi:0.01:2*pi];
>> x = sinc(t);
>> plot(t,x);
>> xlabel('Vrijeme[s]');
>> ylabel('Amplituda');
>> title('Graf funkcije f(x)=sinc(x) / Deni Kolačko')
f(x) = sh(x)
>> t = [-2*pi:0.01:2*pi];
>> x = sinh(t);
>> plot(t,x);
>> xlabel('Vrijeme[s]');
>> ylabel('Amplituda');
>> title('Graf funkcije f(x)=sinh(x) / Deni Kolačko')