I need to work with a matrix. The technique I learned in linear algebra was row reduction. Is there a php code to do that, or is there a superior method since I'll have use of a computer to do the calculations?
I don't know of any language that specifically supports matrices, but PHP does have something called two dimensional arrays. C, Basic, Pascal< PHP, and many other programming languages support 2d arrays.
2d arrays are, for all intents and purposes, matrices.
I understand that I can use the 2d arrays to duplicate the way I wish to store data...
What I need is a way to solve this system of equations. The way I learned in college was to use row reduction. Is there a better method since I have use of a computer, and does anyone know where there is code already written for this task?
Definitely, I agree with scoates. If it can be done mathematically, we can figure out a way to do it with a computer and PHP with a bit of deductive reasoning. Unfortunately, I also do not understand row reduction. Can you give an example and explanation?\
I don't know the english math terms, but I think you mean the Gausse-Jordan method by row reduction?
If so, then here's a basic explanation...
If you have
x + 2y + 4z = 31
3x - y + z = 10
5x + y + 2 = 29
Then you can write that in a matrix
1 2 4 31
3 -1 1 10
5 1 2 29
You could find this by just solving the first step, but if you have different coëficcients, then it could be hard to calculate that, so we use Gausse-Jordan to simplify the matrix with "row operations":
-switch rows (Rij) //i=row1, j=row2
-multiply a row by a value (nRi) //i is the n°of the row
-Ri + nRj
or all together
nRi + mRj (with n!=0)
We are gonna search for a matrix like
1 0 0 r
0 1 0 s
0 0 1 t
so x=r, y=s and z=t
We do this with a limited ammount of row operations, and there's a little trick, the method of Gauss-Jordan
With the row operations R2-3R1 and R3-5R1 we get:
(1) 2 4 31
0 -7 -11 -83
0 -9 -18 -126
You could follow the row operations (slower) or do this:
eg the -1 on R2 becomes (-7*(1))-(2*0)=-7
the 1 on R2 becomes (1*(1))-(4*3)=-11
...
You get it?
-R2 and -1/9R3 gives
1 2 4 31
0 (7) 11 83
0 1 2 14
No need to use the trick here...
Then 7R1-2R2 and 7R3-R2 and 1/3R3 gives
7 0 6 51
0 7 11 83
0 0 (1) 5 //first 0 0 3 15 but we did 1/3R3...
eg the 1 on R1 becomes (1*(7))-(2*0)=7
the 2 on R3 becomes (2*(7))-(11*1)=3 (after wich we diveded R3 with 3 so it becomes 1
...
Let's continue
R1+6R3, R2+11R3, 1/7R1 and 1/7R2 ->
1 0 0 3 //x=3
0 1 0 4 //y=4
0 0 1 5 //z=5
eg the 51 on R1: (51*(1))-(6*5)=21 divided by 7=3
Is there anyone that understands this or did I explain it that bad?
Ofcourse this is just the basic stuff, I doubt it will be easy in PHP
You can get solutions with more unknown terms then there are rows, so you are free to choose it then - or the other way around is possible too.
If the ammount of rows of the matrix WITH known terms does not equel those of the matrix WITHOUT the known terms (in this case
1 2 4
3 -1 1
5 1 2)
then the matrix is false.
Last edited by =X¥®µ§=; Jan 25, 2002 at 14:19.
PHP-Webservices - Profesional Hosting and Programming of sites.
sorry.. that might have been a perfect example.
my head hurt before I read it. (-:
Here's my hour total for the past 2 weeks (and I'm still not done today):
Total 102.55
ouch.
That calls for some beer and some sleep -- possible a cigar, even.
Thanks guy for picking up the post again... I still need some help! I dont understand arrays in PHP well enough. The explaination was a good try on what row reduction is. The project needs to be able to be done over the web on the fly, so I hope there is a solution we can all come up with in PHP!
Bookmarks