clc
clear
echo on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Questao 1: Resolucao de Sistemas Lineares usando o metodo
%            de decomposicao LU com pivoteamento parcial. 
%
% Seja o sistema Ax = b
%         
% onde
%                 
%         |  2  1 -1  5  6 |       | 13 |
%     A = |  1  2  3 -7 -2 |   B = | -3 | 
%         | -7  3  2  0  4 |       |  2 |
%         | -1  0  3  1  1 |       |  4 |    
%         |  3  5 -8  1  7 |       |  8 |  
%
% Calcule a solucao do sistema acima e apresente as matrizes 
% L,U e P. Mostre que PA = LU. Calcule o determinante e a
% inversa da matriz A.
% 
echo off
disp(' ');
disp('Tecle alguma coisa para continuar...'); pause
clc;
clc;

echo on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Resolucao do Sistema Ax = b, usando o metodo de decomposicao
% LU com pivoteamento parcial.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo off
A=[2  1 -1  5  6; 1  2  3 -7 -2 ; -7  3  2  0  4; -1  0  3  1  1; 3  5 -8  1  7]
b=[13; -3; 2; 4; 8]
x = A\b
disp(' ');
disp('Tecle alguma coisa para continuar...'); pause
clc;
clc;

echo on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Decomposicao LU com pivoteamento parcial.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[L,U,P]=lu(A)
echo off
disp(' ');
disp('Tecle alguma coisa para continuar...'); pause
clc;
clc;

echo on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Verificar que LU = PA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
L*U
P*A
echo off
disp(' ');
disp('Tecle alguma coisa para continuar...'); pause
clc;
clc;

echo on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Determinante de A e inversa de A.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
det(A)
inv(A)
echo off
disp(' ');
disp('Final da Questao 1');
disp(' ');
disp('Tecle alguma coisa para continuar...'); pause
clc;
clc;


