Question
The Cholesky factorization one

3. Consider the linear system Ax = b, where 6.25 -1 0.5 2.12 3.6 and [ 7.51 b= -8.68 [ -0.24 Write a MATLAB program for LU-fa
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:

  • The solution consists of 3 code files-
    1. lu_fact.m - manual LU Factorization function
    2. cholesky_fact.m - manual Cholesky function
    3. main.m - calling and testing above functions
  • I have provided code in both text and image format so you can easily copy the code as well as check for correct indentation
  • I have provided the output image of the code so you can easily cross-check for the correct output of the code.
  • Have a nice and healthy day!!

CODE TEXT

1. lu_fact.m

% function for lu factorization

function [L,U]=lu_fact(A)

% fetching n

n=rank(A);

% defining L and U

L=zeros(n); % lower matrix

U=zeros(n); % upper matrix

% factorizing matrix into L and U

for i=1:n

% working on U

for j=i:n

% defining sum of multiplication of elements

sum=0;

for k=1:i

sum=sum+(L(i,k)*U(k,j));

end

% subtracting sum from A

U(i,j)=A(i,j) -sum;

end

% working on L

for j=i:n

if i==j

L(i,i)=1; % for diagonal

else

sum=0;

for k =1:i

sum = sum + (L(j,k) * U(k,i));

end

% subtracting sum from A

L(j,i)=(A(j,i)-sum)/U(i,i);

end

end

end

end

2. cholesky_fact.m

% function cholesky

function [L] = cholesky_fact(A)

% fetching n

n = rank(A);

% initializing L

L = zeros(n+1);

% factorizing a matrix

for i = 1:n

for j=1:i+1

sum = 0;

% suming for diagonals

if (j==i)

for k=1:j

sum = sum + L(j,k)^2;

end

L(j,j)=sqrt(A(j,j)-sum);

else % for remaining elements

for k=1:j

sum = sum + L(i,k) *L(j,k);

end

if L(j,j)>0

L(i,j) = (A(i,j) - sum)/L(j,j);

end

end

end

end

% removing 0 rows and cols

L=L(1:n,1:n);

end

3. main.m

% Initializing A, given in question

A=[6.25 -1 0.5;-1 5 2.12;0.5 2.12 3.6];

% finding LU Factorization using hand written function lu_fact

disp('LU Factorization');

[L,U]=lu_fact(A)

disp('Multiplying L*U gives');

disp(L*U);

% finding Cholesky factorization using hand written function

disp('Cholesky Factorization');

L=cholesky_fact(A);

disp("Multiplying L*L' gives");

disp(L*L');

CODE IMAGES

a. lu_fact.m

lu_fact. mx cholesky_fact. mx main. mx + 1 % function for lu factorization 2 function [LU]=lu_fact(A) % fetching n n=rank(A);

end % subtracting sum from A L(j,i)=(A(j,i)-sum)/U(i,i); end end end end

b. cholesky_fact.m

lu_fact.m x cholesky_fact.mx main.mx % function cholesky 2 function [L] = cholesky_fact(A) % fetching n n = rank(A); % initia

c. main.m

lu_fact. mx cholesky_fact. mx main. mx + % Initializing A, given in question 2 - A=[6.25 -1 0.5; -1 5 2.12;0.5 2.12 3.6); 8 -

OUTPUT IMAGE

LU Factorization L = 1.0000 -0.1600 0.0800 1.0000 0.4545 1.0000 U = 6.2500 0 0 -1.0000 4.8400 2 0.5000 2.2000 .5600 Multiplyi

Add a comment
Know the answer?
Add Answer to:
The Cholesky factorization one 3. Consider the linear system Ax = b, where 6.25 -1 0.5...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • just 1,2,4 Problem 1 Consider the linear system of equations Ax = b, where x €...

    just 1,2,4 Problem 1 Consider the linear system of equations Ax = b, where x € R4X1, and A= 120 b = and h= 0.1. [2+d -1 0 0 1 1 -1 2+d -1 0 h2 0 -1 2 + 1 Lo 0 -1 2+d] 1. Is the above matrix diagonally dominant? Why 2. Use hand calculations to solve the linear system Ax = b with d=1 with the following methods: (a) Gaussian elimination. (b) LU decomposition. Use MATLAB (L,...

  • Linear equation question Use Matlab for b) and c) and show all the work Oct 3,ao16...

    Linear equation question Use Matlab for b) and c) and show all the work Oct 3,ao16 MTH 301: Matrix Theory and Applications Project 1 on Linear System of Equations, and LU factorization This project studies a problem on heat transfer, where a steady-state temperature distribution of a thin plate is sought when the temperature around the boundary is known. Assume the plate shown in the figure represents a cross-section of a metal beam with very negligible heat flow in the...

  • Linear Algebra Question: 18. Consider the system of equations Ax = b where | A= 1...

    Linear Algebra Question: 18. Consider the system of equations Ax = b where | A= 1 -1 0 3 1 -2 -1 4 2 0 4 -1 –4 4 2 0 0 3 -2 2 2 and b = BENA 1 For each j, let a; denote the jth column of A. e) Let T : Ra → Rb be the linear transformation defined by T(x) = Ax. What are a and b? Find bases for the kernel and image...

  • Question 1 (10 marks) For a linear system Ax- b with 1 0 -1 A-1 2-1 2 -1 3 b=14 18 and compute by...

    Please do question 5 for me. Thanks Question 1 (10 marks) For a linear system Ax- b with 1 0 -1 A-1 2-1 2 -1 3 b=14 18 and compute by hand the first four iterations with the Jacobi method, using x()0 Hint: for the ease of calculation, keep to rational fractions rather than decimals Question 2 For the same linear system as in Question 1, compute by hand the first three iterations (10 marks) with the Gauss Seidel method,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT