{"id":3471,"date":"2018-11-16T04:24:05","date_gmt":"2018-11-16T04:24:05","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=3471"},"modified":"2018-11-17T15:27:51","modified_gmt":"2018-11-17T15:27:51","slug":"getting-started-with-scilab-linux-journal","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/16\/getting-started-with-scilab-linux-journal\/","title":{"rendered":"Getting Started with Scilab | Linux Journal"},"content":{"rendered":"<p><em>Introducing one of the larger scientific lab packages for Linux.<\/em><\/p>\n<p><a href=\"https:\/\/www.scilab.org\">Scilab<\/a><br \/>\nis meant to be an overall package for numerical science, along the<br \/>\nlines of Maple, Matlab or Mathematica. Although a lot of built-in<br \/>\nfunctionality exists for all sorts of scientific computations, Scilab<br \/>\nalso includes its own programming language, which allows you to use that functionality<br \/>\nto its utmost. If you prefer, you instead can use this language to extend<br \/>\nScilab&#8217;s functionality into completely new areas of research. Some of<br \/>\nthe functionality includes 2D and 3D visualization and optimization tools,<br \/>\nas well as statistical functions. Also included in Scilab is Xcos, an<br \/>\neditor for<br \/>\ndesigning dynamical systems models.<\/p>\n<p>Several options exist for installing Scilab on your system. Most package<br \/>\nmanagement systems should have one or more packages available for<br \/>\nScilab, which also will install several support packages. Or, you<br \/>\nsimply can download and install a tarball that contains<br \/>\neverything you need to be able to run Scilab on your system.<\/p>\n<p>Once<br \/>\nit&#8217;s installed, start the GUI version of Scilab with<br \/>\nthe scilab command. If you installed Scilab via tarball, this command will<br \/>\nbe located in the bin subdirectory where you unpacked the tarball.<\/p>\n<p>When<br \/>\nit first starts, you should see a full workspace created for your<br \/>\nproject.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.linuxjournal.com\/sites\/default\/files\/styles\/max_650x650\/public\/u%5Buid%5D\/12563f1.png\" alt=\"&quot;&quot;\" width=\"650\" height=\"386\" \/><\/p>\n<p><em>Figure 1. When you first start Scilab, you&#8217;ll see an empty<br \/>\nworkspace ready for you to start a new project.<\/em><\/p>\n<p>On the left-hand side is a file browser where you can see data<br \/>\nfiles and Scilab scripts. The right-hand side has several<br \/>\npanes. The top pane is a variable browser, where you can see what<br \/>\ncurrently exists within the workspace. The middle pane contains a<br \/>\nlist of commands within that workspace, and the bottom pane has<br \/>\na news feed of Scilab-related news. The center of the workspace is the<br \/>\nactual Scilab console where you can interact with the execution engine.<\/p>\n<p>Let&#8217;s start with some basic mathematics\u2014for example,<br \/>\ndivision:<\/p>\n<p>&#8211;&gt; 23\/7<br \/>\nans =<\/p>\n<p>3.2857143<\/p>\n<p>As you can see, the command prompt is &#8211;&gt;, where you enter the<br \/>\nnext command to the execution engine. In the variable browser, you<br \/>\ncan see a new variable named ans that contains the results of the<br \/>\ncalculation.<\/p>\n<p>Along with basic arithmetic, there is also a number of built-in functions. One thing to be aware of is that these function names are<br \/>\ncase-sensitive. For example, the statement sqrt(9) gives the answer<br \/>\nof 3, whereas the statement SQRT(9) returns an error.<\/p>\n<p>There<br \/>\nalso are built-in constants for numbers like e or pi. You can use them<br \/>\nin statements, like this command to find the sine of pi\/2:<\/p>\n<p>&#8211;&gt; sin(%pi \/ 2)<br \/>\nans =<\/p>\n<p>1.<\/p>\n<p>If you don&#8217;t remember exactly what a function name is, but you remember how<br \/>\nit starts, you can use the tab-completion functionality in the Scilab<br \/>\nconsole. For example, you can see what functions start with &#8220;fa&#8221; by<br \/>\ntyping those two letters and then pressing the tab key.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.linuxjournal.com\/sites\/default\/files\/styles\/max_650x650\/public\/u%5Buid%5D\/12563f2.png\" alt=\"&quot;&quot;\" width=\"650\" height=\"393\" \/><\/p>\n<p><em>Figure 2. Use tab-completion to avoid typos while typing<br \/>\ncommands in the Scilab console.<\/em><\/p>\n<p>You can assign variables with the &#8220;=&#8221; symbol. For example,<br \/>\nassign your age to the age variable with:<\/p>\n<p>&#8211;&gt; age = 47<br \/>\nage =<\/p>\n<p>47.<\/p>\n<p>You then can access this variable directly:<\/p>\n<p>&#8211;&gt; age<br \/>\nage =<\/p>\n<p>47.<\/p>\n<p>The variable also will be visible in the variable browser pane. Accessing<br \/>\nvariables this way basically executes the variable, which is also why you<br \/>\ncan<br \/>\nget extra output. If you want to see only the value, use<br \/>\nthe disp() function, which provides output like the following:<\/p>\n<p>&#8211;&gt; disp(age)<\/p>\n<p>47.<\/p>\n<p>Before moving onto more complex ideas, you&#8217;ll need to move out of the<br \/>\nconsole. The advantage of the console is that statements are executed<br \/>\nimmediately. But, that&#8217;s also its disadvantage. To write<br \/>\nlarger pieces of code, you&#8217;ll want to use the included editor. Click<br \/>\nthe Applications\u2192SciNotes menu item to open a new window where<br \/>\nyou can enter larger programs.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.linuxjournal.com\/sites\/default\/files\/styles\/max_650x650\/public\/u%5Buid%5D\/12563f3.png\" alt=\"&quot;&quot;\" width=\"650\" height=\"580\" \/><\/p>\n<p><em>Figure 3. The SciNotes application lets you write larger programs<br \/>\nand then run them within Scilab as a single unit.<\/em><\/p>\n<p>Once you&#8217;ve finished writing your code, you can run it either by clicking<br \/>\nthe run icon on the toolbar or selecting one of the options under the<br \/>\nExecute menu item. When you do this, SciNotes will ask you to save<br \/>\nyour code to a file, with the file ending &#8220;.sce&#8221;, before running. Then,<br \/>\nit gets the console to run this file with the following command:<\/p>\n<p>exec(&#8216;\/home\/jbernard\/temp\/scilab-6.0.1\/bin\/test1.sce&#8217;, -1)<\/p>\n<p>If you create or receive a Scilab file outside of Scilab, you can run it<br \/>\nyourself using a similar command.<\/p>\n<p>To build more complex calculations, you also need a way to<br \/>\nmake comparisons and loop over several calculations. Comparisons<br \/>\ncan be done with either:<\/p>\n<p>if &#8230;. then<br \/>\nstmts<br \/>\nend<\/p>\n<p>or:<\/p>\n<p>if &#8230;. then<br \/>\nstmts<br \/>\nelse<br \/>\nstmts<br \/>\nend<\/p>\n<p>or:<\/p>\n<p>if &#8230;. then<br \/>\nstmts<br \/>\nelseif &#8230;. then<br \/>\nstmts<br \/>\nelse<br \/>\nstmts<br \/>\nend<\/p>\n<p>As you can see, the if and elseif lines need to<br \/>\nend with then. You can<br \/>\nhave as many elseif sections as you need for your particular case. Also,<br \/>\nnote that the entire comparison block needs to end with the<br \/>\nend statement.<\/p>\n<p>There<br \/>\nalso are two types of looping commands: for loops and<br \/>\nwhile loops. As<br \/>\nan example, you could use the following to find the square roots<br \/>\nof the first 100 numbers:<\/p>\n<p>for i=1:100<br \/>\na = sqrt(i) disp(a)<br \/>\nend<\/p>\n<p>The for loop takes a sequence of numbers, defined by<br \/>\nstart:end,<br \/>\nand each value is iteratively assigned to the dummy variable i. Then<br \/>\nyou have your code block within the for loop and close it with the<br \/>\nstatement end.<\/p>\n<p>The while loop is similar, except it uses a comparison<br \/>\nstatement to decide when to exit the loop.<\/p>\n<p>The last quick item I want to cover is the graphing functionality<br \/>\navailable within Scilab. You can create both 2D and 3D graphs,<br \/>\nand you can plot data files or the results of<br \/>\nfunctions. For example, the following plots the sine function<br \/>\nfrom 0 to pi*4:<\/p>\n<p>t = linspace(0, 4 * %pi, 100) plot(t, sin(t))<\/p>\n<p><em>Figure 4. Calling the plot function opens a new viewing<br \/>\nwindow where you can see the generated graphs.<\/em><\/p>\n<p>You can use the linspace command to generate the list of values over<br \/>\nwhich the function will be executed. The plot function opens a new<br \/>\nwindow to display the resultant graph. Use the commands under<br \/>\nthe Edit menu item to change the plot&#8217;s details before saving the<br \/>\nresults to an image file.<\/p>\n<p>You can do 3D graphs just as simply. The<br \/>\nfollowing plots a parametric curve over 0 to 4*pi:<\/p>\n<p>t=linspace(0,4*%pi,100); param3d(cos(t),sin(t),t)<\/p>\n<p>This also opens a new plotting window to display the results. If<br \/>\nthe default view isn&#8217;t appropriate, click<br \/>\nTools\u21922D\/3D Rotation, and with this selected, right-click<br \/>\non the graph and rotate it around for a better view of<br \/>\nthe result.<\/p>\n<p>Scilab is a very powerful tool for many types of<br \/>\ncomputational science. Since it&#8217;s available on Linux, macOS and<br \/>\nWindows, it&#8217;s a great option if you&#8217;re collaborating with other<br \/>\npeople across multiple operating systems. It might also prove to be a<br \/>\neffective tool to use in teaching environments, giving students<br \/>\naccess to a powerful computational platform for no cost, no matter<br \/>\nwhat type of computer they are using. I hope this short article has<br \/>\nprovided some ideas of how it might be useful to you. I&#8217;ve<br \/>\nbarely covered the many capabilities available<br \/>\nwith Scilab, so be sure to visit the <a href=\"https:\/\/www.scilab.org\">main<br \/>\nwebsite<\/a> for a number of good tutorials.<\/p>\n<p><a href=\"https:\/\/www.linuxjournal.com\/content\/getting-started-scilab\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introducing one of the larger scientific lab packages for Linux. Scilab is meant to be an overall package for numerical science, along the lines of Maple, Matlab or Mathematica. Although a lot of built-in functionality exists for all sorts of scientific computations, Scilab also includes its own programming language, which allows you to use that &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/16\/getting-started-with-scilab-linux-journal\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Getting Started with Scilab | Linux Journal&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3471","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/3471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=3471"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/3471\/revisions"}],"predecessor-version":[{"id":3745,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/3471\/revisions\/3745"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=3471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=3471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=3471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}