hw5_solutionsMAE107

hw5_solutionsMAE107 - %Problem1: This program call the...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
%Problem1: This program call the function LU to calculate the LU %decomposition of the matrix A clc;clear; A=[10 2 -1; % Defining A -3 -6 2; 1 1 5]; [L1,U1]=lu_decomp(A); % Calling the lu_decomp function disp( 'Calculated L1 = ' );disp(L1); disp( 'Calculated U1 = ' );disp(U1); disp( 'L1*U1 = ' );disp(L1*U1); [L2,U2]=lu(A); % Calling the Matlab's intrinsic function 'lu' disp( 'L2 obtained using Matlab command (lu)' );disp(L2); disp( 'U2 obtained using Matlab command (lu)' );disp(U2); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [L,U] = lu_decomp(A) % The LU decomposition of the matrix A is calculated and the L and U matrices % are exported as the outputs of the function. disp( 'Input matrix A: ' );disp(A); n = length(A); L = eye(n); U = zeros(3); %Initializing for j = 1:n-1, % Loop through each column j<n L(j+1:n,j) = A(j+1:n,j) / A(j,j); % Writing to the fist column of L % Add the L_ij, for j+1<=i<=n, times the upper triangular part of the j’th row of % the matrix to the rows j+1:n (below the pivot) in the matrix. for k=j+1:n A(k,j+1:n) = A(k,j+1:n) - L(k,j) * A(j,j+1:n); end end for i=1:n; U(i,i:n)=A(i,i:n); end ;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Output: Input matrix A:      10     2    -1     -3    -6     2      1     1     5 Calculated L1 =      1.0000         0         0    -0.3000    1.0000         0     0.1000   -0.1481    1.0000 Calculated U1 =     10.0000    2.0000   -1.0000          0   -5.4000    1.7000          0         0    5.3519 L1*U1 =     10.0000    2.0000   -1.0000    -3.0000   -6.0000    2.0000     1.0000    1.0000    5.0000 L2 obtained using Matlab command (lu)     1.0000         0         0    -0.3000    1.0000         0     0.1000   -0.1481    1.0000 U2 obtained using Matlab command (lu)    10.0000    2.0000   -1.0000          0   -5.4000    1.7000          0         0    5.3519 Published with MATLAB® 7.1
Background image of page 2
Problem 2.  Solution:   The computation of the inverse of a square matrix A may be accomplished using the  Gaussian elimination process. If we define a linear system  Ax=b  in the form  of a 11 a 12 a 13 a 21 a 22 a 23 a 31 a 32 a 33  x 11 x 12 x 13 x 21 x 22 x 23 x 31 x 32 x 33 = 1
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

hw5_solutionsMAE107 - %Problem1: This program call the...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online