Question
Could you please help me to write a MATLAB code? Thanks! function [L,U,p]=lu_fac_pp(A) n=size(A,1) p=zeros(n,1) for k=1:n p(k)=k; end for k=1:n-1 ......... (I need to
Could you please help me to write a MATLAB code? Thanks!
function [L,U,p]=lu_fac_pp(A)
n=size(A,1)
p=zeros(n,1)
for k=1:n
p(k)=k;
end
for k=1:n-1
......... (I need to choose max pivot entry in abs value in this loop)
.........(I need to check whether A is not invertible in this loop)
and return
if r not=k, then swap entire r~k with entire row r
...... (I need to do Gauss elimination in this part (store the multiplying vectors))
end
................check abs(A(n,n)) to find whether A is not invertible
L=tril(A,-1)+eye(n);
U=tril(A);
%%%%%%%%%%%%%
Command Window:
>> A=[1,1,0,3 ; 2,1,-1,1 ; 3,-1,-1,2 ; -1,2,6,-1]
>>b=[4;1;-3;4]
>>[L,U,p] = lu_fac_pp(A)
L=[ 1,0,0,0; -1/3,1,0,0; 2/3,1,1,0;1/3,4/5,3/10,1]
U=[3,-1,-1,2; 0,5/6,17/3,-1/3; 0,0,-6,0; 0,0,0,13/5]
p=[3;4;2;1]
>> c=perm_b(b,p)
c=[-3;4;1;4]
>>d=ult_sys(L,c)
d=[-3;3;0;2.6]
>> x= ut_sys(U,d)
x=[-1;2;0;1]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started