-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d881e1e
commit 4c274af
Showing
5 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
%% Miniteste Prático 2015/2016 | ||
% Ex2 | ||
% a) | ||
fprintf("2.a)\n") | ||
H = [0 0 1/2 0 1/2 1/5; | ||
1/4 1/3 1/2 1/2 1/2 1/5; | ||
1/4 0 0 0 0 1/5; | ||
1/4 1/3 0 0 0 1/5; | ||
1/4 0 0 1/2 0 1/5; | ||
0 1/3 0 0 0 0]; | ||
|
||
x0 = ones(6,1)/6; | ||
x3 = H^3*x0; | ||
prA = x3(1) | ||
prB = x3(2) | ||
prC = x3(3) | ||
prD = x3(4) | ||
prE = x3(5) | ||
prF = x3(6) | ||
|
||
% b) | ||
fprintf("2.b)\n") | ||
x_atual = x0; | ||
N = 100; | ||
resultado = zeros(length(H),N); | ||
for k=1:100 | ||
x_atual = H*x_atual; | ||
resultado(:,k) = x_atual; | ||
end | ||
figure; | ||
stem(1:N,resultado) | ||
|
||
%c) | ||
fprintf("2.c)\n") | ||
[max_pr, pag_max_pr] = max(x_atual); | ||
|
||
%% Miniteste Prático 2018/2019 | ||
% Ex2 | ||
% a) | ||
fprintf("2.a)\n") | ||
T = [0.7 0.1 0 0 0 0; | ||
0.2 0 0 0.3 0 0; | ||
0.1 0.3 0.1 0.4 0 0; | ||
0 0.6 0 0.1 0 0; | ||
0 0 0.4 0.2 1 0; | ||
0 0 0.5 0 0 1] | ||
|
||
v = [0 1/2 0 1/2 0 0]' | ||
|
||
%b) | ||
fprintf("2.b)\n") | ||
Q = T(1:4,1:4); | ||
I = eye(size(Q)); | ||
F = inv(I-Q); | ||
S = sum(F); | ||
media = S(1) | ||
|
||
%c) | ||
fprintf("2.c)\n") | ||
v0 = [1 0 0 0 0 0]'; | ||
v5 = T^5*v0; | ||
prob_Iraque_EUA = v5(5) | ||
v0 = [0 0 1 0 0 0]'; | ||
v50 = T^50*v0; | ||
prob_Brasil_Israel = v50(6) |
Binary file added
BIN
+66.5 KB
Testes/Práticos/Miniteste Prático 15 out 2015/MPEI-2015-2016-Miniteste2.pdf
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
%% Ex2 | ||
% a) | ||
fprintf("2.a)\n") | ||
T = [0.84 0.1 0 0.5; | ||
0.1 0.7 0 0.1; | ||
0.05 0.1 0.8 0.1; | ||
0.01 0.1 0.2 0.3]; | ||
|
||
TA_i = 1; | ||
TB_i = 2; | ||
TC_i = 10; | ||
TD_i = 5; | ||
TT = TA_i + TB_i + TC_i + TD_i; | ||
|
||
x0 = [TA_i/TT TB_i/TT TC_i/TT TD_i/TT]'; | ||
x7 = T^7*x0; | ||
|
||
TA_f = x7(1)*TT | ||
TB_f = x7(2)*TT | ||
TC_f = x7(3)*TT | ||
TD_f = x7(4)*TT | ||
|
||
TT_f = TB_f + TC_f + TA_f + TD_f; % verificação, tem de dar 18 | ||
|
||
% b) | ||
fprintf("2.b)\n") | ||
|
||
TA_max = 0; | ||
i = 0; | ||
while 1 | ||
xi = T^i*x0; | ||
TA_em_i = xi(1)*TT; | ||
if TA_em_i >= TA_max | ||
TA_max = TA_em_i; | ||
else | ||
break; | ||
end | ||
i = i+1; | ||
end | ||
TA_max | ||
|
||
TB_max = 0; | ||
i = 0; | ||
while 1 | ||
xi = T^i*x0; | ||
TB_em_i = xi(2)*TT; | ||
if TB_em_i >= TB_max | ||
TB_max = TB_em_i; | ||
else | ||
break; | ||
end | ||
i = i+1; | ||
end | ||
TB_max | ||
|
||
TC_max = 0; | ||
i = 0; | ||
while 1 | ||
xi = T^i*x0; | ||
TC_em_i = xi(3)*TT; | ||
if TC_em_i >= TC_max | ||
TC_max = TC_em_i; | ||
else | ||
break; | ||
end | ||
i = i+1; | ||
end | ||
TC_max | ||
|
||
TD_max = 0; | ||
i = 0; | ||
while 1 | ||
xi = T^i*x0; | ||
TD_em_i = xi(4)*TT; | ||
if TD_em_i >= TD_max | ||
TD_max = TD_em_i; | ||
else | ||
break; | ||
end | ||
i = i+1; | ||
end | ||
TD_max | ||
|
||
% c) | ||
fprintf("2.c)\n") | ||
|
||
mes = 1; | ||
while 1 | ||
xi = T^mes*x0; | ||
if xi(4)*TT < 2 | ||
break; | ||
end | ||
mes = mes+1; | ||
end | ||
mes | ||
|
Binary file added
BIN
+94.5 KB
Testes/Práticos/Miniteste Prático 18 jan 2017/MPEI-2016-2017-MinitestePrático-18jan.pdf
Binary file not shown.
89 changes: 89 additions & 0 deletions
89
Testes/Práticos/Miniteste Prático 18 jan 2017/Resolução matlab.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
%% Ex1 | ||
% a) | ||
fprintf("1.a)\n") | ||
T = [0.9 0.5 0.5; 0.09 0.4 0.4; 0.01 0.1 0.1] | ||
v = [0 0 1]' | ||
|
||
% b) | ||
fprintf("1.b)\n") | ||
v3 = T^3*v; | ||
prob_0erros = v3(1) | ||
prob_1erro = v3(2) | ||
prob_2ouMaisErros = v3(3) | ||
fprintf("Pacote recebido sem erros: %d\n", v3(1)); | ||
fprintf("Pacote recebido com 1 erro: %d\n", v3(2)); | ||
fprintf("Pacote recebido com 2 ou mais erros: %d\n", v3(3)); | ||
|
||
%% Ex2 | ||
%a) | ||
fprintf("2.a)\n") | ||
H = [0 1/2 1/3 1/4 0; 1/2 0 0 1/4 1/2; 1/2 1/2 1/3 1/4 0; 0 0 0 0 1/2; 0 0 1/3 1/4 0]; | ||
B = 0.8; | ||
N = 5; | ||
%M(1:N,1:N) = 1/N; | ||
%A = B*H + (1-B)*M | ||
A = B*H + (1-B)*ones(N)/N | ||
|
||
% b) | ||
fprintf("2.b)\n") | ||
x0 = ones(N,1)/N; | ||
x10 = H^10*x0 | ||
prC = x10(1) | ||
prD = x10(2) | ||
prE = x10(3) | ||
prF = x10(4) | ||
prG = x10(5) | ||
|
||
%% Ex3 | ||
% a) | ||
fprintf("3.a)\n") | ||
T = [0.7 0.2 0 0 0 0; 0.2 0 0.3 0 0 0; 0 0.6 0.3 0 0 0; 0.1 0.2 0.3 0.1 0 0; 0 0 0.1 0.5 1 0; 0 0 0 0.4 0 1] | ||
|
||
%b) | ||
fprintf("3.b)\n") | ||
x0 = [1 0 0 0 0 0]'; | ||
x9 = T^9*x0; | ||
prob_10serc = x9(3) | ||
x14 = T^14*x0; | ||
prob_15serd = x14(4) | ||
|
||
% c) | ||
fprintf("3.c)\n") | ||
Q = T(1:4,1:4); | ||
I = eye(size(Q)); | ||
F = inv(I-Q); | ||
S = sum(F); | ||
media = S(3) | ||
|
||
%% Exemplo | ||
N = 20; | ||
[U,L] = surfer('http://www.ua.pt',N); | ||
|
||
imagesc(L); | ||
colormap(gray); | ||
|
||
H=full(L); | ||
c=sum(full(L)); % número de ligações(d) | ||
H=H./repmat(c,N,1) | ||
p=0.85 | ||
A=p*H+(1-p)* ones(N)/N % matriz da Google | ||
A(isnan(A))=1/N % resolver dead ends | ||
|
||
x0=ones(N,1)/N; | ||
iter=1; | ||
x=x0; | ||
epsilon=1e-3; | ||
while 1 | ||
fprintf(1,'iteração %d\n',iter); | ||
xold=x | ||
x=A*x; | ||
if max(abs(x-xold))<epsilon break ; end | ||
iter=iter+1; | ||
end | ||
x | ||
|
||
[xs idx]=sort(x,'descend'); | ||
for p=1:N | ||
fprintf(1,'PageRank=%.3f: %s\n',x(idx(p)), U{idx(p)}); | ||
end | ||
|