SetupGuide

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

TitleContentExcerptRevision Note
SetupGuide
<h1 id="SetupGuide">Setup Guide</h1>
This tutorial is on how to set up the development environment for programming with the <a href="http://numericalmethod.com/up/suanshu/" target="_blank">SuanShu</a> library (the Java version). In order to use the <a href="http://numericalmethod.com/up/suanshu/" 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="http://java.sun.com/docs/books/tutorial/"><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="http://numericalmethod.com/up/suanshu/" 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="http://netbeans.org/downloads/"><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="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_download.png"><img class="alignnone size-full wp-image-3602" src="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_download.png" alt="netbeans_download" width="883" height="343" /></a>

To learn about how to use <a href="http://numericalmethod.com/up/netbeans/" target="_blank">NetBeans</a>, you will find a quick start tutorial <a class="ext-link" href="http://netbeans.org/kb/docs/java/quickstart.html"><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="http://numericalmethod.com/up/netbeans/" 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.
<ul>
<li><a class="ext-link" href="http://www.cs.uga.edu/%7Eshoulami/sp2009/cs1301/tutorial/NetBeansDebuggerTutorial/NetBeansDebuggerTutorial.htm"><span class="icon">​</span>NetBeans Debugger- Short Tutorial</a></li>
<li><a class="ext-link" href="http://www.youtube.com/watch?v=joWldbcp1So"><span class="icon">​</span>YouTube – Using the NetBeans Debugger</a></li>
</ul>
<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="http://netbeanside61.blogspot.com/2008/04/top-10-netbeans-ide-keyboard-shortcuts.html"><span class="icon">​</span>here</a>. You can customize them to your own taste by going to Tools -&gt; Options -&gt; Keymap.

<a href="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_keymap.png"><img class="alignnone size-full wp-image-3603" src="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_keymap.png" alt="netbeans_keymap" width="759" height="641" /></a>
<h2 id="suanshu.jar">suanshu.jar</h2>
To program the <a href="http://numericalmethod.com/up/suanshu/" 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="http://numericalmethod.com/up/suanshu/" target="_blank">SuanShu</a> Java classes for numerical computing. This section walks you through how to set up a <a href="http://numericalmethod.com/up/suanshu/" target="_blank">SuanShu</a> project. You may skip this section if you want to start programming <a href="http://numericalmethod.com/up/suanshu/" target="_blank">SuanShu</a> right away. This <a href="http://numericalmethod.com/up/netbeans/" target="_blank">NetBeans</a> project has everything set up. Please read our <a href="http://numericalmethod.com/up/suanshu/tutorial/" target="_blank">Basic Trails</a> to get started. If in the future you would like to update the <a href="http://numericalmethod.com/up/suanshu/" 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="http://numericalmethod.com/up/suanshu/" target="_blank">SuanShu</a> project</h2>
To create a <a href="http://numericalmethod.com/up/suanshu/" target="_blank">SuanShu</a> project in <a href="http://numericalmethod.com/up/netbeans/" target="_blank">NetBeans</a>, open the <a href="http://numericalmethod.com/up/netbeans/" 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="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_new_project.png"><img class="alignnone size-full wp-image-3604" src="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_new_project.png" alt="netbeans_new_project" width="727" height="502" /></a>

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

<a href="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_project_name.png"><img class="alignnone size-full wp-image-3605" src="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_project_name.png" alt="netbeans_project_name" width="731" height="503" /></a>

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

<a href="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_project_properties.png"><img class="alignnone size-full wp-image-3606" src="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_project_properties.png" 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="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_add_jar.png"><img class="alignnone size-full wp-image-3607" src="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_add_jar.png" alt="netbeans_add_jar" width="807" height="583" /></a>

&nbsp;

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

<a href="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_add_javadoc.png"><img class="alignnone size-full wp-image-3608" src="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_add_javadoc.png" alt="netbeans_add_javadoc" width="810" height="584" /></a>

&nbsp;

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

&nbsp;

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

&nbsp;

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

{1, 2, 1},

{4, 5, 2},

{7, 8, 1}

});

System.out.println(A1);

&nbsp;

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)",

A1,

B,

I));

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="http://numericalmethod.com/up/suanshu/tutorial/hellosuanshu/" 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

3×3

[,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.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)

Congratulations!
<h2 id="Javadoc">Javadoc</h2>
<a href="http://numericalmethod.com/up/suanshu/" target="_blank">SuanShu’s</a> javadoc is the complete reference to the <a href="http://numericalmethod.com/up/suanshu/" 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="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_ctrl_space.png"><img class="alignnone size-full wp-image-3786" src="http://numericalmethod.com/wp-content/uploads/2015/04/netbeans_ctrl_space.png" alt="netbeans_ctrl_space" width="617" height="634" /></a>

To get more information about programming <a href="http://numericalmethod.com/up/suanshu/" target="_blank">SuanShu</a>, please consult our <a href="http://numericalmethod.com/up/suanshu/tutorial/" target="_blank">tutorials</a>.

&nbsp;

&nbsp;



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