Question

I am trying to solve n linear equations with n variables. I used cramer's rule but in cases it failed when determinant is equal to zero. How to approach this problem ?

I am using c language.

Also my linear equation is of form:

for n = 3:

- x + y + z = a
  x - y + z = b
  x + y - z = c

for n = 2:

- x + y = a
  x - y = b

I am unable to proceed further.

No correct solution

OTHER TIPS

when solving with cramer, if the determinant is zero you have two cases:

  • at least one variable has a non zero - determinant: there is no solution

  • the determinant for all variables is zero: then you have an infinite number of solutions.

    in the last case, you can find an answer in terms of one of the variables.

If the determinant is equal to zero, then the system is degenerate, meaning that there are either no solutions or an infinite number of solutions. Consider your second example:

-x+y=a
x-y=b

We can rewrite this as

x-y=-a
x-y=b

So either b=-a, in which case any pair (x,x-b) is a solution, or else b!=-a in which case there are no solutions.

In Ax = b, when the determinant of A is equal to zero there is no unique solution. In particular, if b is 0 there are infinitely many solutions. It's also possible that no solution exists.

Your options are:

  • flagging this as an error
  • returning the x that minimizes the difference between Ax and b
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top