Question

Finish the following M-file. Run your function on the same matrix A as given in the...

Finish the following M-file. Run your function on the same matrix A as given in the lab.

% LU4 - The function in this M-file computes an LU factorization

% of a 4 x 4 matrix under the assumption that elimination can be

% performed without row exchanges. % Input: 4 x 4 matrix A;

% Output: lower triangular matrix L and upper triangular matrix U.

function [L,U] = LU4(A)

L = eye(4);

U = A;

for j= ...

for i= ...

L(...) = ...; % Do not forget the semicolons here

U(...) = ...; % to suppress intermediate output!

end

end

end

Homework Answers

Answer #1

function [L, U, P] = myLU4(A)

%A must be square

%get size of input matrix

sizeofA=size(A);

n=sizeofA(1);

%instantiate L, P, U

L=eye(n);

P=eye(n);

U=A;

% process

for i=1:n

  

%Row Reduction

if U(i,i) == 0

maxofU = max(abs(U(i:end,1)));

for j=1:n

if maxofU == abs(U(j,i))

temp = U(1,:);

U(1,:) = U(j,:);

U(j,:) = temp;

  

temp = P(:,1);

P(1,i) = P(j,:);

P(j,:) = temp;

end

end

end

  

if U(i,i) ~=1

temp = eye(n);

temp(i,i)=U(i,i);

L=L*temp;

U(i,:) = U(i,:)/U(i,i); %Ensure pivots are 1

end

  

if i~=n

  

for k=i+1:length(U)

temp = eye(n);

temp(k,i) = U(k,i);

L=L*temp;

U(k,:)=U(k,:)-U(k,i)*U(i,:);

end

end

end

P = P';

end

Know the answer?
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
Similar Questions
Recall that if A is an m × n matrix and B is a p ×...
Recall that if A is an m × n matrix and B is a p × q matrix, then the product C = AB is defined if and only if n = p, in which case C is an m × q matrix. (a) Write a function M-file that takes as input two matrices A and B, and as output produces the product by columns of the two matrix. For instance, if A is 3 × 4 and B is...
Part 2: Solve the following problems in MATLAB 1. Fill in the function E = myElim(A,...
Part 2: Solve the following problems in MATLAB 1. Fill in the function E = myElim(A, r_entry, r_pivot, c) to create an m by m elimination matrix ??. Remember that an elimination matrix looks like an identity matrix with one extra entry of ?? in row r_entry and column r_pivot. 2. Fill in the function M = myMult(A, c_pivot) to create an m by m multiplier matrix ??. Remember that a multiplier matrix looks like an identity matrix with the...
Write a C++ program to demonstrate thread synchronization. Your main function should first create a file...
Write a C++ program to demonstrate thread synchronization. Your main function should first create a file called synch.txt. Then it will create two separate threads, Thread-A and Thread-B. Both threads will open synch.txt and write to it. Thread-A will write the numbers 1 - 26 twenty times in nested for loops then exit. In other words, print 1 - 26 over and over again on separate lines for at least 20 times. Thread-B will write the letters A - Z...
Write a program of wordSearch puzzle that use the following text file as an input. The...
Write a program of wordSearch puzzle that use the following text file as an input. The output should be like this: PIXEL found (left) at (0,9). ( Use JAVA Array ) .Please do not use arrylist and the likes! Hints • The puzzle can be represented as a right-sized two-dimensional array of characters (char). • A String can be converted into a right-sized array of characters via the String method toCharArray. . A word can occur in any of 8...
Assume that we are working with an aluminum alloy (k = 180 W/moC) triangular fin with...
Assume that we are working with an aluminum alloy (k = 180 W/moC) triangular fin with a length, L = 5 cm, base thickness, b = 1 cm, a very large width, w = 1 m. The base of the fin is maintained at a temperature of T0 = 200oC (at the left boundary node). The fin is losing heat to the surrounding air/medium at T? = 25oC with a heat transfer coefficient of h = 15 W/m2oC. Using the...