Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using the pseudo-code provided, write a FORTRAN program, named gauss. 190 that implements Gaussian Elimination with Partial Pivoting that will solve systems of linear equations.
Using the pseudo-code provided, write a FORTRAN program, named gauss. 190 that implements Gaussian Elimination with Partial Pivoting that will solve systems of linear equations. You should test your program with several examples. Here are two examples from the textbook that you can use! Example 1: Oxy + 2xy + xy + x4 - 0 2x + 2xy + 3x3 + 2x = -2 4x - 3x2 +0x3 + x4 = -7 6x + x2 - 6x, -5x = 6 Correct answers x,- 2*3-1,3- --2 numRowSwaps = 0 ! Initialize number of row swaps For col = 1 to (n-1) ! Initialize some needed variables pivotValue = A (col, col)l ! A value on the main mainDiagonalRow = col ! The corresponding rov pivot Row = mainDiagonal Row ! Find the correct pivot row (largest absolute value For row = (col+1) ton If (1A (row, col) > pivotValue) Then pivotValue = A (row, col) | pivotRow = row End If End for ! Switch Rows (pivotRow & mainDiagonal Row) if necess If (pivotRow not equal mainDiagonalRow) Then Add i to numRowSwaps ! Swap rows in matrix A For k = 1 ton Tmp = A (mainDiagonal Row, k) A (mainDiagonal Row, k) = A (pivotRow, k) A (pivotRow, k) = Tmp End for ! Swap values in the vector b as well Tmp = b (mainDiagonalRow) b(mainDiagonalRow) = b (pivotRow) b(pivotRow) = Tmp End If ! Check for singular matrix (Avoid division by 0 lat If (Acol, col)
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