Question
write c++ to solve this linear system.

Given 2x+4y-z 2 -2x -3y +7z 10 Write a program to solve the linear system above using Gauss- Elimination. Question2 Let f(x)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C programme

#include<stdio.h>
int main()
{
int i,j,k,n;
float A[20][20],c,x[10];
printf("\nEnter the size of matrix: ");
scanf("%d",&n);
printf("\nEnter the elements of augmented matrix row-wise:\n");
for(i=1; i<=n; i++)
{
for(j=1; j<=(n+1); j++)
{
printf(" A[%d][%d]:", i,j);
scanf("%f",&A[i][j]);
}
}
/* Now finding the elements of diagonal matrix */
for(j=1; j<=n; j++)
{
for(i=1; i<=n; i++)
{
if(i!=j)
{
c=A[i][j]/A[j][j];
for(k=1; k<=n+1; k++)
{
A[i][k]=A[i][k]-c*A[j][k];
}
}
}
}
printf("\nThe solution is:\n");
for(i=1; i<=n; i++)
{
x[i]=A[i][n+1]/A[i][i];
printf("\n x%d=%f\n",i,x[i]);
}
return(0);

}

Input/output

Enter the size of matrix: 3

Enter the element of augmented matrix raw-wise:

A[1][1]=2

A[1][2]=4

A[1][3]=-1

A[1][4]=2

A[2][1]=4

A[2][2]=9

A[2][3]=-3

A[2][4]=8

A[3][1]=-2

A[3][2]=-3

A[3][3]=7

A[3][4]=10

The solution is :

X1=-67/7

X2=36/7

X3=8/7

Add a comment
Know the answer?
Add Answer to:
Given 2x+4y-z 2 -2x -3y +7z 10 Write a program to solve the linear system above using Gauss- Elim...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT