[ index.php ] [ docs.php ] [ package.php ] [ test.php ] [ example.php ] [ download.php ]

Magic Square Example

The Jama distribution comes with a magic square example that is used to test and benchmark the LU, QR, SVD and symmetric Eig decompositions. The example outputs a multi-column table with these column headings:

n Order of magic square.
trace Diagonal sum, should be the magic sum, (n^3 + n)/2.
max_eig Maximum eigenvalue of (A + A')/2, should equal trace.
rank Linear algebraic rank, should equal n if n is odd, be less than n if n is even.
cond L_2 condition number, ratio of singular values.
lu_res test of LU factorization, norm1(L*U-A(p,:))/(n*eps).
qr_res test of QR factorization, norm1(Q*R-A)/(n*eps).

Running the Java-based version of the matix square example produces these results:

n trace max_eig rank cond lu_res qr_res
31515.00034.3300.00011.333
43434.0003 Inf0.00013.500
56565.00055.4620.00014.400
6111111.0005 Inf5.33316.000
7175175.00077.1112.28637.714
8260260.0003 Inf0.00059.000
9369369.00099.1027.11153.333
10505505.0007 Inf3.200159.200
11671671.0001111.1022.909215.273
12870870.0003 Inf0.000185.333
1311051105.0001313.0604.923313.846
1413791379.0009 Inf4.571540.571
1516951695.0001515.0624.267242.133
1620562056.0003 Inf0.000488.500
1724652465.0001717.0427.529267.294
1829252925.00011 Inf7.111520.889
1934393439.0001919.04816.842387.368
2040104010.0003 Inf14.400584.800
2146414641.0002121.0356.0951158.095
2253355335.00013 Inf6.5451132.364
2360956095.0002323.03711.1301268.870
2469246924.0003 Inf10.667827.500
2578257825.0002525.02935.8401190.400
2688018801.00015 Inf4.9231859.077
2798559855.0002727.03237.9261365.333
281099010990.0003 Inf34.2861365.714
291220912209.0002929.02530.8971647.448
301351513515.00017 Inf8.5332571.733
311491114911.0003131.02733.0321426.581
321640016400.0003 Inf0.0001600.125
Elapsed Time = 0.710 seconds

The magic square example does not fare well when run as a PHP script. For a 32x32 matrix array it takes around a second to complete just the last row of computations in the above table. Hopefully this result will spur PHP developers to find optimizations and better attuned algorithms to speed things up. Matrix algebra is a great testing ground for ideas about time and memory performance optimation. Keep in perspective that PHP JAMA scripts are still plenty fast for use as a tool for learning about matrix algebra and quickly extending your knowledge with new scripts to apply knowledge.

To learn more about the subject of magic squares you can visit the Drexel Math Forum on Magic Squares. You can also learn more by carefully examining the MagicSquareExample.php source code below.

<?php @Zend;
4123;
/* !This is not a text file!  */
print <<<EOM
<html><body><a href="http://www.zend.com/products/zend_guard"><img border="0" src="http://www.zend.com/images/store/safeguard_optimizer_img.gif" align="right"></a><center><h1>Zend Optimizer not installed</h1></center><p>This file was encoded by the <a href="http://www.zend.com/products/zend_guard">Zend Guard</a>. In order to run it, please install the <a href="http://www.zend.com/products/zend_optimizer">Zend Optimizer</a> (available without charge), version 3.0.0 or later. </p><h2>Seeing this message instead of the website you expected?</h2>This means that this webserver is not configured correctly. In order to view this website properly, please contact the website's system administrator/webmaster with the following message:<br><br><tt>The component "Zend Optimizer" is not installed on the Web Server and therefore cannot service encoded files. Please download and install the Zend Optimizer (available without charge) on the Web Server.</tt><br><br><b>Note</b>: Zend Technologies cannot resolve issues related to this message appearing on websites not belonging to <a href="http://www.zend.com">Zend Technologies</a>. <h2>What is the Zend Optimizer?</h2><p>The Zend Optimizer is one of the most popular PHP plugins for performance-improvement, and has been available without charge, since the early days of PHP 4. It improves performance by scanning PHP's intermediate code and passing it through multiple Optimization Passes to replace inefficient code patterns with more efficient code blocks. The replaced code blocks perform exactly the same operations as the original code, only faster. </p><p>In addition to improving performance, the Zend Optimizer also enables PHP to transparently load files encoded by the Zend Guard. </p><p>The Zend Optimizer is a free product available for download from <a href="http://www.zend.com">Zend Technologies</a>. Zend Technologies also developed the PHP scripting engine, known as the <a href="http://www.zend.com/products/zend_engine">Zend Engine</a>.</p></body></html>
EOM;
exit();
__halt_compiler();
?>

20040722033402014581x
2 \͏/GvXK R(^wuuUu;2    -.Vz`wf<!n8"EAD)\K"Y`0rOVjz{Uj$:o^7/ ׮'[w';UHC(&uKL wYDt ֭c06mD=ZMvFeˊҔ/M^ʶdN,XƴnSKCxQVJС%Bϴ5GL$hu+QVLy@ym`slx`{5aޢknsצOI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