Question: please write the assignment in c langauge here's the code for exercise 9 #include #include #include #define ROWS 10 #define COLS 10 //#define ROWS 3
please write the assignment in c langauge
here's the code for exercise 9
#include
#define ROWS 10 #define COLS 10 //#define ROWS 3 //#define COLS 3
void triangulate(double a[][COLS+1],const size_t M,const size_t N); void printArray(double a[][COLS + 1]);
int main(void){ // double a[ROWS+1][COLS+1] = {{0,0,0,0},{0,1,2,-4},{0,1,1,-2},{0,1,1,-2},{0,-1,-2,5}};
double a[ROWS+1][COLS+1]={ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 2, 8, 2, 4, 2, 4, 9, 7, 5, 8}, {0, 5, 2, 4, 3, 6, 2, 5, 6, 4, 8}, {0, 8, 5, 9, 1, 8, 3, 4, 5, 4, 6}, {0, 4, 10, 7, 2, 4, 4, 1, 9, 7, 8}, {0, 5, 7, 4, 4, 10, 10, 7, 6, 2, 4}, {0, 1, 1, 9, 3, 4, 9, 10, 6, 10, 8}, {0, 9, 2, 1, 7, 3, 6, 7, 7, 10, 1}, {0, 2, 5, 2, 2, 2, 6, 4, 9, 3, 5}, {0, 4, 4, 9, 10, 10, 1, 7, 4, 3, 7}, {0, 7, 5, 1, 3, 2, 6, 6, 7, 10, 2} };
printArray(a); printf(" "); triangulate(a, ROWS, COLS); printArray(a); } void triangulate(double a[][COLS + 1], const size_t m, const size_t n) { int i, j, k; for (i = 1; i = i; k--) { a[j][k] -= a[i][k] * a[j][i] / a[i][i]; } } } } void printArray(double a[][COLS + 1]) { int i, j; for (i = 1; i
Task 1 One deficit with the code you implemented in Exercise 09 is, in the general case, matrix element a[il [i] could be 0, which would result in a division by 0 error: alj] [k] -= a[i] [k] * a[j] [i] /a [i] [i] ; To prevent this condition, implement code to exchange the row with any row in the range i+1 to N to make a [i] [i] non-zero. If no such row can be found, report that the matrix is singular and hence no solution exists using a printf) statement and abort the program. The a [i] [i] entry used to eliminate the non-zero elements below the diagonal in the column is called the pivot element. Task 2 The next modification you need to make is to select as the pivt, the entry with the largest absolute value. That is, when searching rows i+1 to N, choose the row whose entry in the column has the maximum fabs () The reason for this is, if a [i] [i] is a very small number, the scaling factor a [j] (i)/a(i] [i] will become very large, and it is this scaling factor that is used to eliminate the coefficient from the " equation, which could result in a round-off error imposed on coefficient a [j] [k]. Modify your 10x10 matrix to force a zero value as one of the initial diagonal elements and show your triangulation program works without reporting any NAN or INF values when you print the matrix for your screenshot Please name your Eclipse IDE project Lastname REDID_Lab_10. Create a ZIP file of your project folder and submit the ZIP file through Blackboard
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
