Revision for “SetupGuide” created on April 13, 2015 @ 11:43:34

TitleContentExcerptRevision Note
<h1 id="SetupGuide">Setup Guide</h1>
This tutorial is on how to set up the development environment for programming with the <a href="" target="_blank">SuanShu</a> library (the Java version). In order to use the <a href="" target="_blank">SuanShu</a> library, you need to know some Java programming. Sun (or Oracle) provides excellent online tutorials on learning Java. You can find a lot of easy-to-read-and-follow lessons in <a class="ext-link" href=""><span class="icon">​</span>Sun’s Java Tutorials</a>.
<h2 id="IDE">IDE</h2>
You will need an Integrated Development Environment (IDE) to program <a href="" target="_blank">SuanShu</a>. Although you may choose any IDE you like, we recommend Netbeans. You can download it from <a class="ext-link" href=""><span class="icon">​</span>here</a>. If you are an avid programmer, you may want to download the ‘All’ version. For most of us who are mathematicians with little programming experience, the ‘Java SE’ version suffices.

<a href=""><img class="alignnone size-full wp-image-3602" src="" alt="netbeans_download" width="883" height="343" /></a>

To learn about how to use <a href="" target="_blank">NetBeans</a>, you will find a quick start tutorial <a class="ext-link" href=""><span class="icon">​</span>here</a>. The most important skill for you to learn is debugging. This is especially true for those who are converting from Matlab and R and are used to printing out values. <a href="" target="_blank">NetBeans</a> debugger allows you to easily inspect values, place conditional breakpoints, pause and resume your program and much more. A quick Google search gives these articles.
<li><a class="ext-link" href=""><span class="icon">​</span>NetBeans Debugger- Short Tutorial</a></li>
<li><a class="ext-link" href=""><span class="icon">​</span>YouTube – Using the NetBeans Debugger</a></li>
<em>We cannot emphasize enough that it is imperative that you must master using a debugger to make your programming experience productive and enjoyable.</em>

Hotkey is another tool that will increase your programming productivity. My favorite hotkey is <tt>Ctrl+Shift+F</tt> (meaning that you press all three keys <tt>Ctrl</tt>, <tt>Shift</tt> and <tt>F</tt> all at the same time). It makes my code look pretty and neat. A list of hotkeys is found <a class="ext-link" href=""><span class="icon">​</span>here</a>. You can customize them to your own taste by going to Tools -&gt; Options -&gt; Keymap.

<a href=""><img class="alignnone size-full wp-image-3603" src="" alt="netbeans_keymap" width="759" height="641" /></a>
<h2 id="suanshu.jar">suanshu.jar</h2>
To program the <a href="" target="_blank">SuanShu</a> library, you will need a licensed copy of <strong>suanshu.jar</strong> (the actual file name depends on the version that you have). It is a compressed file that contains the <a href="" target="_blank">SuanShu</a> Java classes for numerical computing. This section walks you through how to set up a <a href="" target="_blank">SuanShu</a> project. You may skip this section if you want to start programming <a href="" target="_blank">SuanShu</a> right away. This <a href="" target="_blank">NetBeans</a> project has everything set up. Please read our <a href="" target="_blank">Basic Trails</a> to get started. If in the future you would like to update the <a href="" target="_blank">SuanShu</a> library for a newer version, you will need to come back to this section.
<h2 id="CreateaSuanShuproject">Create a <a href="" target="_blank">SuanShu</a> project</h2>
To create a <a href="" target="_blank">SuanShu</a> project in <a href="" target="_blank">NetBeans</a>, open the <a href="" target="_blank">NetBeans</a> IDE, click File -&gt; New Project… (<tt>Ctrl+Shift+N</tt>). In ‘categories’, choose ‘Java’; in projects, choose ‘Java Application’. Click ‘Next’.

<a href=""><img class="alignnone size-full wp-image-3604" src="" alt="netbeans_new_project" width="727" height="502" /></a>

In ‘Project Name’, type whatever you like, e.g., <a href="" target="_blank">HelloSuanShu</a>. In ‘Project Location’, type where you would like to save your project. Click ‘Finish’.

<a href=""><img class="alignnone size-full wp-image-3605" src="" alt="netbeans_project_name" width="731" height="503" /></a>

We need to tell this Java project that we will be calling the <a href="" target="_blank">SuanShu</a> library. To do so, right click on the project name in the Projects window. Click ‘Properties’.

<a href=""><img class="alignnone size-full wp-image-3606" src="" alt="netbeans_project_properties" width="375" height="631" /></a>

Click ‘Libraries’. Make sure the ‘Compile’ tab is displayed. Click ‘Add JAR/Folder’ and browse to where you save suanshu.jar. Choose suanshu.jar and then hit ‘OK’.

<a href=""><img class="alignnone size-full wp-image-3607" src="" alt="netbeans_add_jar" width="807" height="583" /></a>


To install the <a href="" target="_blank">SuanShu</a> javadoc in <a href="" target="_blank">NetBeans</a>, we need to associate the suanshu.jar with its javadoc. Click ‘Edit’. Browse where you save and hit ‘OK’.

<a href=""><img class="alignnone size-full wp-image-3608" src="" alt="netbeans_add_javadoc" width="810" height="584" /></a>


Now, you have created an empty <a href="" target="_blank">SuanShu</a> project. Copy and paste these lines under "<tt>// TODO code application logic here</tt>".


System.out.println("Hello SuanShu");


Matrix A1 = new DenseMatrix(new double[][]{//create a matrix

{1, 2, 1},

{4, 5, 2},

{7, 8, 1}




Matrix B = new Inverse(A1);//compute the inverse of A1

Matrix I = A1.multiply(B);//this should be the identity matrix

System.out.println(String.format("%s * %s = %s (the identity matrix)",




Hit <tt>Ctrl+Shift+I</tt> to fix the necessary imports. Make sure you select these two.

import com.numericalmethod.suanshu.matrix.doubles.operation.Inverse;

import com.numericalmethod.suanshu.matrix.doubles.Matrix;

Hit <tt>Alt+Shift+F</tt> to beautify your code. The complete source for this example can be found <a href="" target="_blank">here</a>.

Right click on the project name, e.g., HelloSuanShu, and click ‘Run’ (or simply press <tt>F6</tt> if you make this project your main project). Vola! You should see this in your output window (<tt>Ctrl+4</tt>).

Hello SuanShu


[,1] [,2] [,3]

[1,] 1.000000, 2.000000, 1.000000,

[2,] 4.000000, 5.000000, 2.000000,

[3,] 7.000000, 8.000000, 1.000000,


[,1] [,2] [,3]

[1,] 1.000000, 2.000000, 1.000000,

[2,] 4.000000, 5.000000, 2.000000,

[3,] 7.000000, 8.000000, 1.000000,  * 3×3

[,1] [,2] [,3]

[1,] -1.833333, 1.000000, -0.166667,

[2,] 1.666667, -1.000000, 0.333333,

[3,] -0.500000, 1.000000, -0.500000,  = 3×3

[,1] [,2] [,3]

[1,] 1.000000, 0.000000, 0.000000,

[2,] 0.000000, 1.000000, 0.000000,

[3,] 0.000000, 0.000000, 1.000000,  (the identity matrix)

<h2 id="Javadoc">Javadoc</h2>
<a href="" target="_blank">SuanShu’s</a> javadoc is the complete reference to the <a href="" target="_blank">SuanShu</a> library. You can read it in a browser, e.g., Internet Explorer. You can bring them up dynamically during programming. Each time you press <tt>Ctrl+SPACE</tt> after the ‘.’ of any object you create, you will see a list of available methods for this object, and the javadoc for the method selected.

<a href=""><img class="alignnone size-full wp-image-3786" src="" alt="netbeans_ctrl_space" width="617" height="634" /></a>

To get more information about programming <a href="" target="_blank">SuanShu</a>, please consult our <a href="" target="_blank">tutorials</a>.



Old New Date Created Author Actions
April 13, 2015 @ 11:43:34 sanjay
April 13, 2015 @ 11:43:13 [Autosave] sanjay
April 13, 2015 @ 09:01:53 sanjay