Exp. No. 1 Gauss Elimination method Problem : Solve the system of equations using Gauss Elimination method. , , Programming command: #include <stdio.h> #include <conio.h> #define MAX 10 void gaussElimination(float a[MAX][MAX+1], int n) { int i,j,k; float factor , x[MAX]; for ( i = 0; i < n; i++) { for ( j = i + 1; j < n; j++) { factor = a[j][i] / a[i][i]; for (k = i; k < n + 1; k++){ a[j][k] -= factor *a[i][k]; } } } for (i = n - 1; i >= 0; i--) { x[i] = a[i][n]; for (j = i + 1; j < n; j++){ x[i] -= a[i][j] * x[j]; } x[i] /= a[i][i];} for ( i = 0; i < n; i++){ printf("x%d = %.2f ", i+1, x[i]); } } int main() { int n,i,j; float a[MAX][MAX+1]; printf("Enter the number of variables: "); scanf("%d", &n); printf("Enter the augmented matrix:\n"); for ( i = 0; i < n; i++) { for (j = 0; j < n+1; j++) { scanf("%f", &a[i][j]); } } gaussElimination(a, n); getch(); return 0; } Output: Enter the number of variables: 4 Enter the augmented matrix: 1 1 0 3 4 2 1 -1 1 1 3 -1 -1 2 -3 -1 2 3 -1 4 x1 = -1.00 x2 = 2.00 x3 = 0.00 x4 = 1.00 Exp.No.2 Gauss Jordan method Problem: Solve the system of equations using Gauss Jordan method. Programming command: , Programming command: #include <stdio.h> #include <conio.h> #define MAX 10 void gaussJordan(float a[MAX][MAX + 1], int n) { int i, j, k; float pivot, factor; for (i = 0; i < n; i++) { pivot = a[i][i]; for (j = i; j < n + 1; j++) a[i][j] = a[i][j] / pivot; for (k = 0; k < n; k++) { if (k != i) { factor = a[k][i]; for (j = i; j < n + 1; j++) a[k][j] = a[k][j] - factor * a[i][j]; } } } for (i = 0; i < n; i++) { printf("x%d = %.2f\n", i + 1, a[i][n]); } } int main() { int n, i, j; float a[MAX][MAX + 1]; printf("Enter the number of variables: "); scanf("%d", &n); printf("Enter the augmented matrix:\n"); for (i = 0; i < n; i++) { for (j = 0; j < n + 1; j++) { scanf("%f", &a[i][j]); } } gaussJordan(a, n); getch(); return 0; } Output: Enter the number of variables: 3 Enter the augmented matrix: 2 3 -1 5 4 4 -3 3 2 -3 2 2 x1 = 1.00 x2 = 2.00 x3 = 3.00 Exp.No.4 Basis and Dimension Problem : Determine whether {(1, −3,2), (−3,1,3), (−2, −10,2)} form a basis of R 3 . Also find the dimension. Programming command: #include <stdio.h> #include <conio.h> #define MAX 10 int echelon_rank(float m[MAX][MAX], int rows, int cols) { int i, j, k, rank = 0, pivot; float factor, temp; for (i = 0; i < cols && rank < rows; i++) { pivot = rank; while (pivot < rows && m[pivot][i] == 0) pivot++; if (pivot == rows) continue; /* Swap rows if needed */ if (pivot != rank) { for (k = 0; k < cols; k++) { temp = m[rank][k]; m[rank][k] = m[pivot][k]; m[pivot][k] = temp; } } /* Eliminate below */ for (j = rank + 1; j < rows; j++) { factor = m[j][i] / m[rank][i]; for (k = i; k < cols; k++) { m[j][k] -= factor * m[rank][k]; } } rank++; } return rank; } int main() { int rows = 3, cols = 3, rank, i, j; float v[MAX][MAX] = { {1, -3, 2}, {-3, 1, 3}, {-2, -10, 2} }; rank = echelon_rank(v, rows, cols); printf("Basis dimension: %d\n", rank); if (rank == rows) printf("The given vectors form a basis.\n"); else printf("The given vectors do NOT form a basis.\n"); getch(); return 0; } Output: Basis dimension: 3 The given vectors form a basis. Exp.No.8 System of equations using Jacobi method Problem: Solve the system of equations 4x − y=15, −x +4y – z =10, −y + 4z = 10 using Jacobi method. Programming command: #include <stdio.h> #include <conio.h> #include <math.h> #define N 3 #define TOL 0.000001 #define MAX_ITER 100 /* Function to perform Jacobi Iteration */ void jacobi(float A[N][N], float B[N], float X[N]) { float X_old[N], diff, sum; int i, j, iter = 0; /* Initialize solution to 0 */ for (i = 0; i < N; i++) X[i] = 0; printf("Iterating using Jacobi Method:\n"); do { /* Copy current X values to X_old */ for (i = 0; i < N; i++) X_old[i] = X[i]; /* Compute new X values */ for (i = 0; i < N; i++) { sum = 0; for (j = 0; j < N; j++) { if (i != j) sum += A[i][j] * X_old[j]; } X[i] = (B[i] - sum) / A[i][i]; } // Compute difference for convergence check diff = 0; for (i = 0; i < N; i++) diff += fabs(X[i] - X_old[i]); // Print intermediate results printf("Iteration %d: ", iter + 1); for (i = 0; i < N; i++) printf("x%d = %.6f ", i + 1, X[i]); printf("\n"); iter++; } while (diff > TOL && iter < MAX_ITER); printf("\nFinal solution after %d iterations:\n", iter); for (i = 0; i < N; i++) printf("x%d = %.6f\n", i + 1, X[i]); } int main() { float A[N][N] = {{4, -1, 0}, {-1, 4, -1}, {0, -1, 4}}; float B[N] = {15, 10, 10}; float X[N]; jacobi(A, B, X); getch(); return 0; } Output: Iterating using Jacobi Method: Iteration 1: x1 = 3.750000 x2 = 2.500000 x3 = 2.500000 Iteration 2: x1 = 4.375000 x2 = 4.062500 x3 = 3.125000 Iteration 3: x1 = 4.765625 x2 = 4.375000 x3 = 3.515625 Iteration 4: x1 = 4.843750 x2 = 4.570312 x3 = 3.593750 Iteration 5: x1 = 4.892578 x2 = 4.609375 x3 = 3.642578 Iteration 6: x1 = 4.902344 x2 = 4.633789 x3 = 3.652344 Iteration 7: x1 = 4.908447 x2 = 4.638672 x3 = 3.658447 Iteration 8: x1 = 4.909668 x2 = 4.641724 x3 = 3.659668 Iteration 9: x1 = 4.910431 x2 = 4.642334 x3 = 3.660431 Iteration 10: x1 = 4.910583 x2 = 4.642715 x3 = 3.660583 Iteration 11: x1 = 4.910679 x2 = 4.642792 x3 = 3.660679 Iteration 12: x1 = 4.910698 x2 = 4.642839 x3 = 3.660698 Iteration 13: x1 = 4.910710 x2 = 4.642849 x3 = 3.660710 Iteration 14: x1 = 4.910712 x2 = 4.642855 x3 = 3.660712 Iteration 15: x1 = 4.910714 x2 = 4.642856 x3 = 3.660714 Iteration 16: x1 = 4.910714 x2 = 4.642857 x3 = 3.660714 Iteration 17: x1 = 4.910714 x2 = 4.642857 x3 = 3.660714 Final solution after 17 iterations: x1 = 4.910714 x2 = 4.642857 x3 = 3.660714