Question

In: Computer Science

MATLAB Function: (Backward substitution) Write a function that takes an upper triangular matrix U, and a...

MATLAB Function: (Backward substitution) Write a function that takes an upper triangular matrix U, and a vector b as input and returns the solution of the linear system U x = b. Use this function in the case when U is made of the numbers [(3,2,1),(0,5,4),(0,0,6)], and b = [1,1,−6]^T.

Solutions

Expert Solution

Question

MATLAB Function: (Backward substitution) Write a function that takes an upper triangular matrix U, and a vector b as input and returns the solution of the linear system U x = b. Use this function in the case when U is made of the numbers [(3,2,1),(0,5,4),(0,0,6)], and b = [1,1,−6]^T.

Sol:

MATLAB Function

function x=backSubstitution(U,b)
% Solving an upper triangular system by back-substitution
% Input matrix U is an n by n upper triangular matrix
% Input vector b is n by 1, where n specifies the dimensions of the arrays
% Output vector x is the solution to the linear system
% U x = b
n=length(U);
x=zeros(n,1);
for j=n:-1:1
    if (U(j,j)==0) error('Matrix is singular!'); end;
    x(j)=b(j)/U(j,j);
    b(1:j-1)=b(1:j-1)-U(1:j-1,j)*x(j);
end

MATLAB Main Program - Using the above function

clc;
clear all;
close all;

%Giving the values as in question
U=[3 2 1;0 5 4;0 0 6];
b = [1,1,-6]';
[x]=backSubstitution(U,b)


Related Solutions

Write a Matlab function for a matrix that takes in a matrix in echelon form and...
Write a Matlab function for a matrix that takes in a matrix in echelon form and will return the row canonical form. The function cannot use rref, or any other matlab built in functions.
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or any vector and simply returns back the transpose of that input. You can always verify your answer by using the inbuilt transpose function in MATLAB, however, you cannot use the transpose function directly when writing your code. Here is the starter code that we are providing to help you get started %x is the input vector or matrix. You can find the %size that...
B. Write a function in MATLAB called findInverseOf2x2Matrix that takes in as input any square matrix...
B. Write a function in MATLAB called findInverseOf2x2Matrix that takes in as input any square matrix of size 2 × 2 and returns back the inverse of that matrix if one exists. If no inverse exists, print back a suitable error message. You can safely assume that we will test your code on square matrices of size 2 × 2 only. You can always verify your answer by using the inbuilt inverse function in MATLAB, however, you cannot use the...
Let Un×n be an upper triangular matrix of rank n. If any arithmetic operation takes 1µ...
Let Un×n be an upper triangular matrix of rank n. If any arithmetic operation takes 1µ second on a computing resource, compute the time taken to solve the system Ux = b, assuming it has a unique solution. What would be the time taken if Un×n is lower triangular
Matlab You will write a function to calculate the determinant of a matrix. It should work...
Matlab You will write a function to calculate the determinant of a matrix. It should work for any size matrix. Remember that the determinant can be calculated by multiplying the diagonal elements of an upper right triangular matrix. Your function will take a matrix passed to it and put it in upper right triangular form. You will work down the diagonal beginning at row 1 column 1, then row 2 column 2, etc. Note that the row and column numbers...
et A be a 157 x 157 upper-triangular matrix. Suppose that every diagonal entry of A...
et A be a 157 x 157 upper-triangular matrix. Suppose that every diagonal entry of A is 1 and that there is at least one nonzero off-diagonal entry in A. Is A diagonalizable? Explain how you can answer this question mentally, with no non-trivial calculations.
1) Let A be nxn matrix and Ax=b, if we need change A to Upper triangular...
1) Let A be nxn matrix and Ax=b, if we need change A to Upper triangular matrix using Gaussian Elimination, how many additions/subtraction operations are involved? how many multiplication/division operations are involved? 2) Once we got the upper triangular matrix, now we need to apply back-substitution, how many additions/subtraction operations are involved? how many multiplication/division operations are involved?
for matrices, what is the difference between row reduced echelon form and an upper triangular matrix?
for matrices, what is the difference between row reduced echelon form and an upper triangular matrix?
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal matrix given as two vectors: n×1 vector v representing the main diagonal and (n−1)×1 vector w representing the upper diagonal. Have this function output the Cholesky factor of the matrix as a vector for the main diagonal and a vector for the upper diagonal and output the number of flops and, separately, the number of square roots used as well. Use only basic programming....
Write a MATLAB function function = myMatrixInveesion(....) to calculate matrix inversion by implementing LU decomposition, forward...
Write a MATLAB function function = myMatrixInveesion(....) to calculate matrix inversion by implementing LU decomposition, forward and backward substitution procedures. Do NOT use the built-in "lu" or "inv" commands in your code. You will need to employ Nested Loops. Thank you! function_____ = myMatrixInversion(_____)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT