ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
example.php
Go to the documentation of this file.
1 <?php
2 include_once "includes/header.php";
3 include_once "includes/navbar.php";
4 ?>
5 <h2>Magic Square Example</h2>
6 <p>
7 The Jama distribution comes with a magic square example that is used to
8 test and benchmark the LU, QR, SVD and symmetric Eig decompositions.
9 The example outputs a multi-column table with these column headings:
10 </p>
11 
12 <table border='1' cellpadding='5' cellspacing='0' align='center'>
13  <tr>
14  <td><b>n</b></td>
15  <td>Order of magic square.</td>
16  </tr>
17  <tr>
18  <td><b>trace</b></td>
19  <td>Diagonal sum, should be the magic sum, (n^3 + n)/2.</td>
20  </tr>
21  <tr>
22  <td><b>max_eig</b></td>
23  <td>Maximum eigenvalue of (A + A')/2, should equal trace.</td>
24  </tr>
25  <tr>
26  <td><b>rank</b></td>
27  <td>Linear algebraic rank, should equal n if n is odd, be less than n if n is even.</td>
28  </tr>
29  <tr>
30  <td><b>cond</b></td>
31  <td>L_2 condition number, ratio of singular values.</td>
32  </tr>
33  <tr>
34  <td><b>lu_res</b></td>
35  <td>test of LU factorization, norm1(L*U-A(p,:))/(n*eps).</td>
36  </tr>
37  <tr>
38  <td><b>qr_res</b></td>
39  <td>test of QR factorization, norm1(Q*R-A)/(n*eps).</td>
40  </tr>
41 </table>
42 <p>
43 Running the Java-based version of the matix square example produces these results:
44 </p>
45 
46 <table border='1' align='center'>
47  <tr>
48  <th> n </th>
49  <th> trace </th>
50  <th> max_eig </th>
51  <th> rank </th>
52  <th> cond </th>
53  <th> lu_res </th>
54  <th> qr_res </th>
55  </tr>
56  <tr>
57  <td>3</td><td>15</td><td>15.000</td><td>3</td><td>4.330</td><td>0.000</td><td>11.333</td>
58  </tr>
59  <tr>
60  <td>4</td><td>34</td><td>34.000</td><td>3</td><td> Inf</td><td>0.000</td><td>13.500</td>
61  <tr>
62  <td>5</td><td>65</td><td>65.000</td><td>5</td><td>5.462</td><td>0.000</td><td>14.400</td>
63  </tr>
64  <tr>
65  <td>6</td><td>111</td><td>111.000</td><td>5</td><td> Inf</td><td>5.333</td><td>16.000</td>
66  </tr>
67  <tr>
68  <td>7</td><td>175</td><td>175.000</td><td>7</td><td>7.111</td><td>2.286</td><td>37.714</td>
69  </tr>
70  <tr>
71  <td>8</td><td>260</td><td>260.000</td><td>3</td><td> Inf</td><td>0.000</td><td>59.000</td>
72  </tr>
73  <tr>
74  <td>9</td><td>369</td><td>369.000</td><td>9</td><td>9.102</td><td>7.111</td><td>53.333</td>
75  </tr>
76  <tr>
77  <td>10</td><td>505</td><td>505.000</td><td>7</td><td> Inf</td><td>3.200</td><td>159.200</td>
78  </tr>
79  <tr>
80  <td>11</td><td>671</td><td>671.000</td><td>11</td><td>11.102</td><td>2.909</td><td>215.273</td>
81  </tr>
82  <tr>
83  <td>12</td><td>870</td><td>870.000</td><td>3</td><td> Inf</td><td>0.000</td><td>185.333</td>
84  </tr>
85  <tr>
86  <td>13</td><td>1105</td><td>1105.000</td><td>13</td><td>13.060</td><td>4.923</td><td>313.846</td>
87  </tr>
88  <tr>
89  <td>14</td><td>1379</td><td>1379.000</td><td>9</td><td> Inf</td><td>4.571</td><td>540.571</td>
90  </tr>
91  <tr>
92  <td>15</td><td>1695</td><td>1695.000</td><td>15</td><td>15.062</td><td>4.267</td><td>242.133</td>
93  </tr>
94  <tr>
95  <td>16</td><td>2056</td><td>2056.000</td><td>3</td><td> Inf</td><td>0.000</td><td>488.500</td>
96  </tr>
97  <tr>
98  <td>17</td><td>2465</td><td>2465.000</td><td>17</td><td>17.042</td><td>7.529</td><td>267.294</td>
99  </tr>
100  <tr>
101  <td>18</td><td>2925</td><td>2925.000</td><td>11</td><td> Inf</td><td>7.111</td><td>520.889</td>
102  </tr>
103  <tr>
104  <td>19</td><td>3439</td><td>3439.000</td><td>19</td><td>19.048</td><td>16.842</td><td>387.368</td>
105  </tr>
106  <tr>
107  <td>20</td><td>4010</td><td>4010.000</td><td>3</td><td> Inf</td><td>14.400</td><td>584.800</td>
108  </tr>
109  <tr>
110  <td>21</td><td>4641</td><td>4641.000</td><td>21</td><td>21.035</td><td>6.095</td><td>1158.095</td>
111  </tr>
112  <tr>
113  <td>22</td><td>5335</td><td>5335.000</td><td>13</td><td> Inf</td><td>6.545</td><td>1132.364</td>
114  </tr>
115  <tr>
116  <td>23</td><td>6095</td><td>6095.000</td><td>23</td><td>23.037</td><td>11.130</td><td>1268.870</td>
117  </tr>
118  <tr>
119  <td>24</td><td>6924</td><td>6924.000</td><td>3</td><td> Inf</td><td>10.667</td><td>827.500</td>
120  </tr>
121  <tr>
122  <td>25</td><td>7825</td><td>7825.000</td><td>25</td><td>25.029</td><td>35.840</td><td>1190.400</td>
123  </tr>
124  <tr>
125  <td>26</td><td>8801</td><td>8801.000</td><td>15</td><td> Inf</td><td>4.923</td><td>1859.077</td>
126  </tr>
127  <tr>
128  <td>27</td><td>9855</td><td>9855.000</td><td>27</td><td>27.032</td><td>37.926</td><td>1365.333</td>
129  </tr>
130  <tr>
131  <td>28</td><td>10990</td><td>10990.000</td><td>3</td><td> Inf</td><td>34.286</td><td>1365.714</td>
132  </tr>
133  <tr>
134  <td>29</td><td>12209</td><td>12209.000</td><td>29</td><td>29.025</td><td>30.897</td><td>1647.448</td>
135  </tr>
136  <tr>
137  <td>30</td><td>13515</td><td>13515.000</td><td>17</td><td> Inf</td><td>8.533</td><td>2571.733</td>
138  </tr>
139  <tr>
140  <td>31</td><td>14911</td><td>14911.000</td><td>31</td><td>31.027</td><td>33.032</td><td>1426.581</td>
141  </tr>
142  <tr>
143  <td>32</td><td>16400</td><td>16400.000</td><td>3</td><td> Inf</td><td>0.000</td><td>1600.125</td>
144  </tr>
145 </table>
146 <center>Elapsed Time = 0.710 seconds</center>
147 
148 <p>
149 The magic square example does not fare well when <a href='../examples/MagicSquareExample.php'>run as a PHP script</a>. For a 32x32 matrix array
150 it takes around a second to complete just the last row of computations in the above table.
151 Hopefully this result will spur PHP developers to find optimizations and better attuned algorithms
152 to speed things up. Matrix algebra is a great testing ground for ideas about time and memory
153 performance optimation. Keep in perspective that PHP JAMA scripts are still plenty fast for use as
154 a tool for learning about matrix algebra and quickly extending your knowledge with new scripts
155 to apply knowledge.
156 </p>
157 
158 <p>
159 To learn more about the subject of magic squares you can visit the <a href='http://mathforum.org/alejandre/magic.square.html'>Drexel Math Forum on Magic Squares</a>.
160 You can also learn more by carefully examining the <code>MagicSquareExample.php</code> source code below.
161 </p>
162 
163 <?php
164 highlight_file("../examples/MagicSquareExample.php");
165 include_once "includes/footer.php";
166 ?>