Explore BrainMass
Share

Explore BrainMass

    Matlab: Naive Gaussian Elimination and L-U Decomposition

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Please find the question attached to the document below.

    function [x] = gaussel(A,b)
    % [x] = gaussel(A,b)
    %
    % This subroutine will perform Gaussian elimination
    % and back substitution to solve the system Ax = b.
    % INPUT : A - matrix for the left hand side.
    % b - vector for the right hand side
    %
    % OUTPUT : x - the solution vector.
    N = max(size(A));
    % Perform Gaussian Elimination
    for j=2:N,
    for i=j:N,
    m = A(i,j-1)/A(j-1,j-1);
    A(i,:) = A(i,:) - A(j-1,:)*m;
    b(i) = b(i) - m*b(j-1);
    end
    end
    % Perform back substitution
    x = zeros(N,1);
    x(N) = b(N)/A(N,N);
    for j=N-1:-1:1,
    x(j) = (b(j)-A(j,j+1:N)*x(j+1:N))/A(j,j);
    end

    % End of function

    a)The above programme solves a linear system of equations using naïve Gaussian elimination.
    Modify this programme so that it outputs upper and lower triangular matrices of LU factorisation. The header line of the modified function should read [x, L, U] = gaussel(A, b)
    Use this function, to solve the system Ax = b, where
    b) Use the LU factorisation of A obtained above to solve the system Ax = c, where

    You can use the 'backslash' Matlab operator for solving the systems of equations with L and U.

    © BrainMass Inc. brainmass.com October 10, 2019, 7:43 am ad1c9bdddf
    https://brainmass.com/computer-science/matlab/matlab-naive-gaussian-elimination-decomposition-592749

    Attachments

    Solution Summary

    In this solution, we modify the naive Gaussian elimination code to yield the L and U matrices as well, and apply the result to solving examples of linear equations.

    $2.19