Question
**C PROGRAMMING ONLY**!!!!!!!


Create a script that will use Cramers rule to find the Solutions of Ax-b for A a 3 x 3 matrix and B a 3x 1 matrix Conditions you need to use 1) User defined functions that will return value and take arguments. 2) Also, this script should use two dimensional pointer that will take care of the whole matrix Then the values of x, y and can be found as follows di bi ci ai bi di a2 b2 d2 1a C a2 b2 c2 | indicates the determinant Check your result with
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#define N 3

// Function to get cofactor of mat[p][q] in temp[][]. n is current
// dimension of mat[][]
void getCofactor(int mat[N][N], int temp[N][N], int p, int q, int n)
{
int i = 0, j = 0,row,col;

// Looping for each element of the matrix
for (row = 0; row < n; row++)
{
for (col = 0; col < n; col++)
{
// Copying into temporary matrix only those element
// which are not in given row and column
if (row != p && col != q)
{
temp[i][j++] = mat[row][col];

// Row is filled, so increase row index and
// reset col index
if (j == n - 1)
{
j = 0;
i++;
}
}
}
}
}

/* Recursive function for finding determinant of matrix.
n is current dimension of mat[][]. */
int determinantOfMatrix(int mat[N][N], int n)
{
int D = 0; // Initialize result

if (n == 1)
return mat[0][0];

int temp[N][N]; // To store cofactors

int sign = 1,f; // To store sign multiplier

// Iterate for each element of first row
for (f = 0; f < n; f++)
{
// Getting Cofactor of mat[0][f]
getCofactor(mat, temp, 0, f, n);
D += sign * mat[0][f] * determinantOfMatrix(temp, n - 1);

// terms are to be added with alternate sign
sign = -sign;
}

return D;
}

/* function for displaying the matrix */
void display(int (*mat)[N], int row, int col)
{
int i,j;
for ( i = 0; i < row; i++)
{
for ( j = 0; j < col; j++)
printf(" %d", mat[i][j]);
printf("n");
}
}

// Driver program to test above functions
int main()
{
int mat[N][N],matx[N][N],maty[N][N],matz[N][N],D[N],i,j,x,y,z,det;
printf("Enter the matrix of cofficeint of dimension 3X3:\n");
for(i=0;i<N;i++)
{
printf("\n Enter the %d Row:",i+1);
for(j=0;j<N;j++)
{
scanf("%d",&mat[i][j]);
matx[i][j]=mat[i][j];
maty[i][j]=mat[i][j];
matz[i][j]=mat[i][j];
}
}
det=determinantOfMatrix(mat, N);
printf("\n%d\n",det);
printf("Enter the matrix of D :\n");
for(i=0;i<N;i++)
scanf("%d",&D[i]);
for(i=0;i<N;i++)
{
matx[i][0]=D[i];
maty[i][1]=D[i];
matz[i][2]=D[i];
}
if(det!=0)
{

x=determinantOfMatrix(matx, N);
printf("\nx=%d\n",x/det);
y=determinantOfMatrix(maty, N);
printf("\ny=%d\n",y/det);
z=x=determinantOfMatrix(matz, N);
printf("\nz=%d\n",z/det);
}
else
printf("\nSystem does not have a unique solution because determinant is 0");

return 0;
}

Add a comment
Know the answer?
Add Answer to:
**C PROGRAMMING ONLY**!!!!!!! Create a script that will use Cramer's rule to find the Solutions of...
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