Question
Modify Mathetica program below (Mathematica Program #1 to use Gaussian Elimination with Partial Pivoting (instead of Naive Gaussian Elimination). Use the same (A|b) in the
Modify Mathetica program below (Mathematica Program #1 to use Gaussian Elimination with Partial Pivoting (instead of Naive Gaussian Elimination). Use the same (A|b) in the picture below function x = naiv_gauss(A,B); n length (b); x = zeros(n,1 ); function [x] = gausselimm(A,B) [nA, mA] = size(A) [nB, mB] = size(B) if nA mA then error ('gausselim Matrix A must be a square'); abort; else if mA nB then error ('gausselim Incompatible dimensions b(wA and b'); abort; end; a = [A,B]; //Matrix n=nA // number of rows and columns in A, rows in B m= mB // no. Of columns in B // forward elimination with pivoting in partial for k = 1; n-1 Kpivot = k; amax = abs(a(k,k)); for i = k +1;n if abs(a(i, k)) > amax then Kpivot = i; amax = a(k,i); end; end; temp = a(Kpivot,: ) ; a(Kpivot,: ) = a(k,: ); a(k,: ) = temp // forward elimination for ii = k+ 1; n for j = k+1; n+m a(i,j)= a(i,j) - a(k,j) *a(i,k)/a(k,k); end; end; end; //backward substitution for j = 1; m x(n, j ) = a(n, n+j/a(n,n); for i = n 1; -1: 1 sum k = 0 for k = i + 1:n sum k = sum k +a(i, k) * x(k,j); end; x(i,j) = (a(i,n+j) -sum k )/ a(i,i); end; end; //end function
Mathematica Program #1. Implement procedure Naive_Gauss (on page 77 in text) in Mathematica. Print the error message "Error: Divide By Zero" if there is an attempt to divide by 0 (and exit the program gracefully). Test your program with the following matrix from class (to test your error message, just replace a11 with a 0). 6 -2 2 4 16 12 -8 6 10 26 3 -13 9 3 19 -6 4 1 18-34 (Alb) Hints. Here is an example of one way to create a two-dimensional list A of values (that is, a 4x4 matrix) in Mathematica... along with a 4x1 vector B A={(1,2,3,4),(5,3,2,-2),(4,4,7,-9),(4,2,1,9)) B(2,7,9,-11) To display A nicely as in a homework assignment, you may use the following statement: A//MatrixForm Or MatrixForm[A] Make sure to display the original coefficient matrix A, and the row-reduced coefficient matrix, as well as the solution vector X In Mathematica, you may reference, for example, a31 and b3, as: BII3]] Mathematica Program #1. Implement procedure Naive_Gauss (on page 77 in text) in Mathematica. Print the error message "Error: Divide By Zero" if there is an attempt to divide by 0 (and exit the program gracefully). Test your program with the following matrix from class (to test your error message, just replace a11 with a 0). 6 -2 2 4 16 12 -8 6 10 26 3 -13 9 3 19 -6 4 1 18-34 (Alb) Hints. Here is an example of one way to create a two-dimensional list A of values (that is, a 4x4 matrix) in Mathematica... along with a 4x1 vector B A={(1,2,3,4),(5,3,2,-2),(4,4,7,-9),(4,2,1,9)) B(2,7,9,-11) To display A nicely as in a homework assignment, you may use the following statement: A//MatrixForm Or MatrixForm[A] Make sure to display the original coefficient matrix A, and the row-reduced coefficient matrix, as well as the solution vector X In Mathematica, you may reference, for example, a31 and b3, as: BII3]]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started