Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my current code in Mathematica but i can't figure out how to create an if statement to detect if a pivot variable is

image text in transcribedimage text in transcribedThis is my current code in Mathematica but i can't figure out how to create an if statement to detect if a pivot variable is zero. Please help.

CIV E 295 Lab #5-Linear Systems of Equations Files are to be submitted electronically to the appropriate Lab Assignment Dropbox on eClass IMPORTANT NOTE: Please add the printout of your code and the output to the submitted PDF file. Your name and ID should appear at the top of your code. Add your name and your ID between the comment sign in Mathematica. For example (*John Smith*) Alternatively, you can add a cell, select that cell and change its format (from Format menu) from input to title or section Submit only one PDF file and if you code the bonus problem one PDF file and one Mathemtica file. The lab covers: Linear Systems of Equations Modify the code for the Cramer method so that it would give a warning message if the determinant of A is equal to zero. Otherwise, it proceeds with the solution. Test it and show that it works in both cases if the determinant is equal to zero or not. - Modify the code for the Gauss Elimination method so that it would give a warning message if a zero pivot is detected during elimination. Otherwise, it proceeds with the solution. Test it using two examples, one where the method finds a solution to a system of equations of n > 3, and another where the warning message works when a zero pivot element is detected. Examples of matrices where the warning message should be produced are 1 22 0 5 0 0 0-5 0 -2 1 0 0 0 0 9 -2 0 0 1 1 0 0 0 Crame r [A-, B-] := ( n Length[A]; Di Table[A, i, 1, n)]; If [Det[A, "The determinant is equal to zero", : Table [Det [Di [[i]]/Det [A ] ], {i, 1, n}]]) Crame r [ { { 1, , }, {e, 1, ), (), , 1)), {1, 2, 3)) Cramer[(1, 1, 1), (l, 1, e], [e, 5, 1]), (1, 2, 3)] Ouny 125' 125'25 nClear[n, G, i, X, A, B, k, n Length[A]; G Transpose [Insert[Transpose[A], B, n+ 1]]; For[k 1, ksn, k+ If [G[[k, k] ] *G[ [k])- e, "Pivot variable is zero", x- Table[0, [i, 1, n]]; Forin, iz 1,i-i-1, x) 04)- (1, 2, 3} - GaussElimination ((1, 1, 1), [1, 1, e], [e, 5, 1]), (1, 2, 3]] -4, 2, 3) nyo irJs GaussElimination(((1, 2, 2, , 5), {, , , -5, ), {-2, 1, , , ), 19, 9, -2, , , ), {1, i, , , }}, {i, 2, 3, 4, 5)) Transpose: The first two levels of {(1, 2, 2, 0, 5), {0, 0, 0,-5, 0), {-2, 1,0,0,0), {0, 9,-2, Null, 0,0},(1, 1, 0, 0, 0)) cannot be transposed. Insert : Cannot insert at position {6} in Transpose1, 2, 2, 0, 5), {0, 0, 0,-5, 0), {-2, 1, 0, 0, 0), {0, 9,-2, Null' 0' 0), {1, 1, 0, 0, 0))] Part : Part 5 of TransposelnsertITranspose EfL 22.0,5),(0,0,0,-5. Ok-210. 0. Ok {0, 9,-2, Null. O. Oh {1.1. 0,0, 0)ll, {1, 2.3.4 5), 611 does not exist. CIV E 295 Lab #5-Linear Systems of Equations Files are to be submitted electronically to the appropriate Lab Assignment Dropbox on eClass IMPORTANT NOTE: Please add the printout of your code and the output to the submitted PDF file. Your name and ID should appear at the top of your code. Add your name and your ID between the comment sign in Mathematica. For example (*John Smith*) Alternatively, you can add a cell, select that cell and change its format (from Format menu) from input to title or section Submit only one PDF file and if you code the bonus problem one PDF file and one Mathemtica file. The lab covers: Linear Systems of Equations Modify the code for the Cramer method so that it would give a warning message if the determinant of A is equal to zero. Otherwise, it proceeds with the solution. Test it and show that it works in both cases if the determinant is equal to zero or not. - Modify the code for the Gauss Elimination method so that it would give a warning message if a zero pivot is detected during elimination. Otherwise, it proceeds with the solution. Test it using two examples, one where the method finds a solution to a system of equations of n > 3, and another where the warning message works when a zero pivot element is detected. Examples of matrices where the warning message should be produced are 1 22 0 5 0 0 0-5 0 -2 1 0 0 0 0 9 -2 0 0 1 1 0 0 0 Crame r [A-, B-] := ( n Length[A]; Di Table[A, i, 1, n)]; If [Det[A, "The determinant is equal to zero", : Table [Det [Di [[i]]/Det [A ] ], {i, 1, n}]]) Crame r [ { { 1, , }, {e, 1, ), (), , 1)), {1, 2, 3)) Cramer[(1, 1, 1), (l, 1, e], [e, 5, 1]), (1, 2, 3)] Ouny 125' 125'25 nClear[n, G, i, X, A, B, k, n Length[A]; G Transpose [Insert[Transpose[A], B, n+ 1]]; For[k 1, ksn, k+ If [G[[k, k] ] *G[ [k])- e, "Pivot variable is zero", x- Table[0, [i, 1, n]]; Forin, iz 1,i-i-1, x) 04)- (1, 2, 3} - GaussElimination ((1, 1, 1), [1, 1, e], [e, 5, 1]), (1, 2, 3]] -4, 2, 3) nyo irJs GaussElimination(((1, 2, 2, , 5), {, , , -5, ), {-2, 1, , , ), 19, 9, -2, , , ), {1, i, , , }}, {i, 2, 3, 4, 5)) Transpose: The first two levels of {(1, 2, 2, 0, 5), {0, 0, 0,-5, 0), {-2, 1,0,0,0), {0, 9,-2, Null, 0,0},(1, 1, 0, 0, 0)) cannot be transposed. Insert : Cannot insert at position {6} in Transpose1, 2, 2, 0, 5), {0, 0, 0,-5, 0), {-2, 1, 0, 0, 0), {0, 9,-2, Null' 0' 0), {1, 1, 0, 0, 0))] Part : Part 5 of TransposelnsertITranspose EfL 22.0,5),(0,0,0,-5. Ok-210. 0. Ok {0, 9,-2, Null. O. Oh {1.1. 0,0, 0)ll, {1, 2.3.4 5), 611 does not exist

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions