Write a program to solve a linear system Ax = b using Gaussian Elimination with
ID: 3825264 • Letter: W
Question
Write a program to solve a linear system Ax = b using Gaussian Elimination with scaled partial pivoting and backsubstitution. You can just type in the system matrices at the beginning of the file. Store the matrices as numpy arrays. Recall that scaled partial pivoting works like this. Suppose the matrix we're work on is an n times n matrix W. (Leaving b out of the question.) Suppose we're working on column i of W, so we want to zero out the elements below position W_ii. First, for each row j with i lessthanorequalto j lessthanorequalto n find the maximum absolute value of the element in or to the right of column i, call it d(j). In other words, d(j) = max{|W_jk|| k = i...n}. Then find j in the range j =i..., n that maximizes the quantity |W_jj|/d(j) Now switch rows i and j. Proceed to zero out the elements in the rows below the diagonal in column i.Explanation / Answer
#include #include #include #define ZERO 1.0E-20 #define true 1 #define false 0 #define N 2 /* Number of equations */ static double absval(double); static void OUTPUT(int, int, int *, double *, double [][N+1]); using namespace std; int main() { double A[N][N+1] = { {0.003, 59.14, 59.17}, {5.291, -6.13, 46.78} }; double X[N]; double AMAX,XM,SUM; /* AMAX save a_{pk} = max_{kRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.