please use C++ For this assignment, you will need to write two codes. For the fi
ID: 1766740 • Letter: P
Question
please use C++
For this assignment, you will need to write two codes. For the first, you will implement Gaussian Elimination in the manner it was presented in class. Do not use other formulations or methods Your program should accept a matrix, A, of arbitrary size up to 10 x 10, either by reading it from a file or from the keyboard at runtime. (Hint: Reuse the relevant portions of your code from the first assignment.) Your matrix may not be hardcoded. Likewise, your code should accept a column vector. b. Then your matrix must be passed to one or more subroutines that return the solution to Ax = b to the main program. Use your code to solve the two following matrix systems Do not use pivoting 4.678.483.51 2.31 6.62 3.014.84 3.554.47 6.87 6.083.42 0.15 9.24 5.04 1.486.84 3.01 1.96 3.67 3.34 4.88 1.458.45 5.61 4.41 4.42 3.33 5.67 4.15 8.585.41 5.84 3.20 9.60158 9.311.491.967.447.2188 3.39 5.66 8.61 9.44 1.13623 4.286.65 5.567.25 8.714.14 9.627.538.047.09 9.55 3 30 For your second code, implement Thomas' algorithm. This code should function in the same manner as the Gaussian Elimination code, and the algorithm must be in its own subroutine and called from the main program. Use this code to solve the following systems of equations 4.67 8.480 3.014.84 3.550 4.41 4.42 3.33 5.67 4.15 8.58 5.410 9.31 1.491.960 1.58 0.88 6.23 5.56 7.258.71 4.14 7.09 9.553.30 3.42 0.159.240 5.66|8.61 9.440 3.01 1.96 3.67 8.45 5.61Explanation / Answer
#include #include using namespace std; void elimination (double A[][5], double passed_b[]); void substitution (double U[][5], double g[], double vector_xx[]); int main() { double A[5][5], b[5], vector_x[5]; printf("For Matrix A, "); for (int row = 0; row < 5 ; row++) { for (int column = 0; column < 5; column++) { printf("Enter the value for the element %d column %d: ", row + 1, column + 1); scanf("%lf", &A[row][column]); } } printf(" "); printf("For Matrix b, "); for (int row = 0; row < 5; row++) { printf(" enter the value for the element %d: ", row + 1); scanf("%lf", &b[row]); } for (int row = 0; row < 5; row++) { vector_x[row] = 0; } FILE * out_file; out_file = fopen("Gaussian Elimination.txt","w") fprintf(out_file, "Gaussian Elimination Program "); fprintf(out_file, " "); fprintf(out_file, "Matrix A: Matrix b: "); for (int row = 0; row < 5; row++) { for (int column = 0; column < 5; column++) { if (column == 5 - 1) { fprintf(out_file, "%7.3f %7.3f ", A[row][column], b[row]); } else { fprintf(out_file,"%7.3f ", A[row][column]); } }} elimination(A, b); substitution(A, b, vector_x); fprintf(out_file, " "); fprintf(out_file, "Matrix x: "); for (int row = 0; row < 5; row++) { fprintf(out_file, "%7.3lf ", vector_x[row]); } fclose(out_file); return 0; } void elimination (double A[][5], double passed_b[]) { for (int k = 0; k < 4; k++) { for (int i = k + 1; i < 5; i++) { A[i][k] = A[i][k] / A[k][k]; for (int j = k + 1; j < 5; j++) { A[i][j] = A[i][j] - A[i][k] * A[k][j]; } passed_b[i] = passed_b[i] - A[i][k] * passed_b[k]; } } } void substitution ( double U[][5], double g[], double vector_xx[]) { double line_sum; vector_xx[4] = g[4] / U[4][4]; for (int k = 4 - 1; k > -1; k--) { line_sum = 0; for (int j = k + 1; jRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.