0% found this document useful (0 votes)
50 views3 pages

Gauss Jacobi Method

The C program uses the Gauss-Jacobi method to solve a system of 4 equations with 4 unknowns (x, y, z, t). It takes the system coefficients and initial guesses as input, iteratively calculates new approximations, and outputs the solutions after a maximum number of iterations. The key steps are: 1) Input the coefficients and initial guesses, 2) Calculate new approximations in each iteration, 3) Output the final approximations after the maximum iterations.

Uploaded by

Puja Podder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views3 pages

Gauss Jacobi Method

The C program uses the Gauss-Jacobi method to solve a system of 4 equations with 4 unknowns (x, y, z, t). It takes the system coefficients and initial guesses as input, iteratively calculates new approximations, and outputs the solutions after a maximum number of iterations. The key steps are: 1) Input the coefficients and initial guesses, 2) Calculate new approximations in each iteration, 3) Output the final approximations after the maximum iterations.

Uploaded by

Puja Podder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

GAUSS JACOBI METHOD

Q. Write a C program to solve the following equation by using Gauss


Jacobi Method.
10x + 8y -3z + t = 16
2x + 10y + z - 4t = 9
3x - 4y + 10z + t = 10
2x + 2y – 3z + 10t = 11

Answer:
1 /*
2 Solve by Gauss Jacobi Method.
3 Name- Ajit Kumar Podder
4 Roll No- 2212413
5 Registration Number- 0532105030370
6 */
7
8 #include<stdio.h>
9 #include<math.h>
10 #include <conio.h>
11 int main()
12 {
13 int i,j,k,n,max_itr;
14 float a[20][20],x[10],y[10],s=0.0,t=0.0;
15 printf("\nEnter the number of equations given:\n ");
16 scanf("%d",&n);
17 printf("\nEnter the elements of augmented matrix row-wise:\n\n");
18 for(i=1; i<=n; i++)
19 {
20 for(j=1; j<=(n+1); j++)
21 {
22 scanf("%f",&a[i][j]);
23 }
24 }
25 printf("\nEnter the initial approximations for the unknowns respectively:\n\n");
26 for(i=1;i<=n;i++)
27 {
28 scanf("%f",&x[i]);
29 }
30 printf("\nEnter the maximum number of iterations to perform:\n ");
31 scanf("%d",&max_itr);
32 printf("\nThe computation table is:\n");
33 for(k=1;k<=max_itr;k++)
34 {
35 printf("\nIteration %d: ",k);
36 for(i=1;i<=n;i++)
37 {
38 s=0;
39 for(j=1;j<=n;j++)
40 {
41 if(j!=i)
42 s=s+a[i][j]*x[j];
43 }
44 t=(a[i][n+1]-s)/a[i][i];
45 y[i]=t;
46 printf("x[%d]=%f ",i,y[i]);
47 }
48 for(i=1;i<=n;i++)
49 {
50 x[i]=y[i];
51 }
52 }
53 printf("\n\nThe required solution is:\n");
54 for(i=1;i<=n;i++)
55 printf("x[%d]=%f\n", i,x[i]);
56 getch();
57 return(0);
58 }
Output:

Enter the number of equations given:


4

Enter the elements of augmented matrix row-wise:

10 8 -3 1 16
2 10 1 -4 9
3 -4 10 1 10
2 2 -3 10 11

Enter the initial approximations for the unknowns respectively:

0
0
0
0

Enter the maximum number of iterations to perform:


10

The computation table is:

Iteration 1: x[1]=1.600000 x[2]=0.900000 x[3]=1.000000 x[4]=1.100000


Iteration 2: x[1]=1.070000 x[2]=0.920000 x[3]=0.770000 x[4]=0.900000
Iteration 3: x[1]=1.005000 x[2]=0.969000 x[3]=0.957000 x[4]=0.933000
Iteration 4: x[1]=1.018600 x[2]=0.976500 x[3]=0.992800 x[4]=0.992300
Iteration 5: x[1]=1.017410 x[2]=0.993920 x[3]=0.985790 x[4]=0.998820
Iteration 6: x[1]=1.000719 x[2]=0.997467 x[3]=0.992463 x[4]=0.993471
Iteration 7: x[1]=1.000418 x[2]=0.997998 x[3]=0.999424 x[4]=0.998102
Iteration 8: x[1]=1.001618 x[2]=0.999215 x[3]=0.999264 x[4]=1.000144
Iteration 9: x[1]=1.000393 x[2]=0.999808 x[3]=0.999186 x[4]=0.999613
Iteration 10: x[1]=0.999949 x[2]=0.999848 x[3]=0.999844 x[4]=0.999716

The required solution is:


x[1]=0.999949
x[2]=0.999848
x[3]=0.999844
x[4]=0.999716

__________________________________________________________________________

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy