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.
Asked
Active
Viewed 396 times
0
-
2There 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](http://ww2.odu.edu/~agodunov/teaching/notes/Nm06_matrix2a.pdf) in 2 seconds – OldProgrammer Jan 22 '14 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? – Rob Kennedy Jan 22 '14 at 17:51
-
Google "gaussian elimination". First link is the Wikipedia article, which describes the process and provides an example. – comingstorm Jan 23 '14 at 00:20
1 Answers
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)):

4pie0
- 29,204
- 9
- 82
- 118
-
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? – user3182683 Jan 22 '14 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 '14 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? – user3182683 Jan 22 '14 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 '14 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? – user3182683 Jan 22 '14 at 18:13
-
-
-
-