SitePoint Sponsor 

User Tag List
Results 1 to 12 of 12
Thread: need php code

Sep 24, 2001, 06:25 #1
 Join Date
 May 2001
 Location
 Northern Virginia
 Posts
 445
 Mentioned
 0 Post(s)
 Tagged
 0 Thread(s)
need php code
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?

Sep 24, 2001, 11:35 #2
 Join Date
 Nov 2000
 Location
 Portland, OR
 Posts
 480
 Mentioned
 0 Post(s)
 Tagged
 0 Thread(s)
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.

Sep 24, 2001, 11:59 #3
 Join Date
 May 2001
 Location
 Northern Virginia
 Posts
 445
 Mentioned
 0 Post(s)
 Tagged
 0 Thread(s)
way to solve...
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?

Jan 25, 2002, 10:56 #4
mathcad will help you with this
http://www.mathcad.com/PHPWebservices  Profesional Hosting and Programming of sites.

Jan 25, 2002, 11:09 #5
 Join Date
 Nov 2001
 Location
 Montreal
 Posts
 794
 Mentioned
 0 Post(s)
 Tagged
 0 Thread(s)
I'm not familiar with row reduction (unforunately, I never studied matrices  I miss doing academic math).
Can you explain, briefly? Maybe we can come up with some code that will do it.
S
ps  I found this, but I'm not following basic matrix terminology/markup.. sorry.Last edited by scoates; Jan 25, 2002 at 11:12.

Jan 25, 2002, 11:24 #6
 Join Date
 Jun 2001
 Location
 Before These Crowded Streets
 Posts
 9,446
 Mentioned
 0 Post(s)
 Tagged
 0 Thread(s)
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?\
Sketch

Jan 25, 2002, 11:29 #7
 Join Date
 Nov 2001
 Location
 Montreal
 Posts
 794
 Mentioned
 0 Post(s)
 Tagged
 0 Thread(s)
Before and After data would help, too. (:
Inputs and Outputs. You know what I mean. (:
S

Jan 25, 2002, 13:14 #8
I don't know the english math terms, but I think you mean the GausseJordan 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 GausseJordan 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 GaussJordan
With the row operations R23R1 and R35R1 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 7R12R2 and 7R3R2 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 13:19.
PHPWebservices  Profesional Hosting and Programming of sites.

Jan 25, 2002, 13:36 #9
 Join Date
 Nov 2001
 Location
 Montreal
 Posts
 794
 Mentioned
 0 Post(s)
 Tagged
 0 Thread(s)
my head hurts.
S

Jan 25, 2002, 13:53 #10
was it THAT bad?
actually this is just the veryveryvery basic of matrices
but i like them, and you are all using them without knowing > eg if you go to school, you get grades
 chemistry  math  fysics  ...
John***********4*************9***********4
Homer**********8*************6***********4
Leela**********2*************10**********10
and look! we have a matrixPHPWebservices  Profesional Hosting and Programming of sites.

Jan 25, 2002, 13:59 #11
 Join Date
 Nov 2001
 Location
 Montreal
 Posts
 794
 Mentioned
 0 Post(s)
 Tagged
 0 Thread(s)
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.
ok, NOW we're offtopic. (:
S

Jan 25, 2002, 14:22 #12
 Join Date
 May 2001
 Location
 Northern Virginia
 Posts
 445
 Mentioned
 0 Post(s)
 Tagged
 0 Thread(s)
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