File Exchange

## Linear equation system 'Ax=r' by Gauss elimination method

version 1.0 (1.54 KB) by

Solve N-equation

Updated

This Matlab program Solve N-equation with Gauss elimination method and check results with Matlab Function.

abdelaziz daha

Neha Verma

### Muhammad Misbah-Ul Islam (view profile)

thanks a lot. good one for beginners.

bahria group

### bahria group (view profile)

m don,t understand this code mean m write own code but not applied

Søren Hartmann Kristensen

Got the problem right where other implementations of the method failed! (including my own attempt)

Tim Davis

Jake: 3 pages? It can be done in about 23 lines of C or Fortran, including the forward/backsolve. It can be done in 1 line of MATLAB (x=A\b), or if you don't want to use backslash, in about 14 lines of (well-written) MATLAB, including proper partial pivoting. This code is double that if you graciously exclude the "please input your matrix" prompts. In addition, Rostami's code does NOT do partial pivoting; all it checks if the pivot is zero.

This code is absolute dreck. Here is the output for a trivial 2-by-2 matrix that breaks this code:
Solution of N-equation "[A][X]=[r]"
Enter number of Equations :2
Enter Matrix [A]:[1e-24 1 ; 1 1]
Enter Matrix [r]:[2 ; 3]
@----------------------------------------------------------@
Output [B][x]=[b]
Upper riangular Matrix [B] =
1.0e+24 *

0.0000 0.0000
0 -1.0000

Matrix [b] =
1.0e+24 *

0.0000
-2.0000

solution of linear equations :
0
2

solve with matlab functions(for checking):
1
2

The MATLAB solution (using x=inv(A)*b of all things!) is correct. Rostami's code gives a completely incorrect answer.

Please delete this file from the File Exchange; it leads unwary users (like Jake) down the wrong path with counterfeit algorithms that pretend to be robust.

Jake de Burgh

Although it takes just one page, it works as millions of pages for me because I really needed it. My professor wrote a program in 3 pages that did whatever your program does but in a really weaker format. thanks very much.

Mohammed Almassri

Thanks for the code.
it is very useful code for me, I need it.

Tim Davis

John's comments say it all. This is MATLAB code at its extreme. Extremely bad. Please remove this from the File Exchange, "it detracts from the sum total of human knowledge".

For all those of you downloading this tripe, if you realy want to see how Gaussian elimination is done, get Cleve Moler's book (http://www.mathworks.com/moler) and the NCM toolbox. See lutx.m.

YetAnother Rostami

Maybe the author mistyped the subject of the review while intending something like "This Matlab program DEMONSTRATES HOW NOT TO Solve N-equation with Gauss elimination method and check results with Matlab Function." ;-)

John D'Errico

Ah, but that is the problem exactly!

This teaches students to start writing BAD Matlab programming. This teaches them bad habits, bad skills that they will then need to unlearn.

This code teaches students to use scripts instead of functions. It teaches them to clear the workspace out from under the user who might wish to test the code.

This code teaches students to use a clunky, kludge of an interface to intereact with the user.

This code teaches students to use multiply nested loops to solve problems where they do not need to be used. (Note that a good implementation of elimination might be written using at worst a single loop.)

This code may even convince some students that a good way to solve a linear system of equations in matlab is to use this code. Instead, this is absolutely terrible as a tool in Matlab.

This code teaches students that inv is a good way to check their results here. NOT TRUE!!!

This code teaches students to not bother with error checking.

This code teaches students a poor implementation of Gaussian elimination.

Sadly, if you are a student who is just learning about Matlab and mathematics in general, you won't know all the above reasons for NOT wanting to download this code. You might believe it is good, as Reza apparently does. You would be mistaken.

I won't even get into the question of the author's sister or mother apparently choosing to rate the code as good. Talk about an "unbiased" review there.

it is a useful program for the students who want to start matlab programing

Foo Rostami

Apart from the technical issues John mentioned, i award this homeward a "poor" rating to balance Sarah's review who incidentally has the same first name as the author...

sarah rostami

John D'Errico

Beware: This is a script that will clear your Matlab workspace. It is a student's homework assignment. As such it is not of any real use or value beyond a homework assignment.

This uses loops to solve a problem poorly that is far better done using only 3 characters to solve in Matlab. A\r

How about the code itself? Is it well implemented? NO. This code deals poorly with zero or infinitesimal pivots.

Worse, the check at the end is poorly implemented - using inv.

The script lacks any help. It lacks any error checks. It lacks any useful comments that show what was done.

I'm sorry, but this homework assignment does not even merit a grade of A as homework. As a submission on the file exchange, it deserves a poor rating.

##### MATLAB Release
MATLAB 7.4 (R2007a)