0

I need to solve a system of n-linear equations with n-unknown variables in C++ using the gaussian method of elimnation. Any hints how to achieve that? I'll be probably using rand(); for the amount of n, since isn't available, because C++11 I can't use.

3
  • 2
    There is this cool new tool out called, "google." Give it a try. Seriously, SO is not the correct forum for these types of questions. I found this link in 2 seconds Jan 22, 2014 at 17:46
  • The technique of Gaussian elimination has been known for centuries, so it really shouldn't require "hints." Just look it up. Which specific part of the task are you having trouble with? Jan 22, 2014 at 17:51
  • Google "gaussian elimination". First link is the Wikipedia article, which describes the process and provides an example. Jan 23, 2014 at 0:20

1 Answer 1

3

to solve a linear system

AX=B

you need to invert a matrix A, which results in A^(-1) and multiply A^(-1) * B to obtain X. This is the example code to invert non-singular matrix using Gauss - Jordan elimination algorithm (complexity is O(n^3)):

matrix inversion using Gauss-Jordan elimination

9
  • Thanks for the example. Excuse my ignorance, but since I now got this, could you tell me what else I should implement to solve my problem? Jan 22, 2014 at 18:00
  • you know your matrix A, right? then you also know A^(-1). so now you just need to multiply this by B and this is your point of interest
    – 4pie0
    Jan 22, 2014 at 18:01
  • My matrix A is the variables before the variables in the system, right? The matrix B is the variables of the "answer" of those equations? Jan 22, 2014 at 18:04
  • yes, i.e. if: 1x+2y=3, 4x+5y=6, then A 1st row is 1 2 , 2nd row 4 5, B 1st row is 3 , 2nd row 6
    – 4pie0
    Jan 22, 2014 at 18:07
  • So, to find the value of the variables, I have to invert the matrix A, and multiply it to B, that's all I have to do? Jan 22, 2014 at 18:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.