You are on page 1of 5

Title of script: Getting Started with Scilab Author: Shalini , Anuradha A.

Keywords: Simple calculations, arithmetic, logarithm, exponential, trigonometric functions. diary, file storing operations, working directory. isual !lue Title Slide Slide "arration #elcome to the spoken tutorial on Getting Started with Scilab. At the end of this tutorial, you will be able to: $se Scilab as a calculator. Store %alues in a %ariable. &erform %arious mathematical operations using these %ariables. !reate a file to store commands executed during the session in the current working directory. 'efine complex numbers. &erform exponential, logarithmic and trigonometric operations on numbers. Slide(&rere)uisites* Slide -aunch Scilab The prere)uisite for this tutorial are that Scilab should be installed on your system. +ere is the ,low chart for the tutorial. Start Scilab. This is the Scilab console window. "otice that the cursor is on the command prompt. . suggest that you practice this tutorial in Scilab simultaneously while pausing the %ideo at regular inter%als of time. Scilab can be used as a calculator. -et us see some of the basic operations that it can do. Type 12 plus 1 into 1 minus 51 di%ided 1 on the console and press enter. The output is 12, as expected. "ote that the answer 12 is stored in the default %ariable 7a n s7. #e can also create named %ariables: Type, a e)uals 92,b829 and c8::. This stores the %alues 92,29 and :: in the %ariables a,b and c respecti%ely. "ow we will perform some mathematical operations using these %ariables. //0a3b3c ans 8 55. //0a4;b3c< ans 8 51=. //0d 8 a3b3c d 8 9>=?. ,or example, a3b3c gi%es the result 55 also a times ;b3c< gi%es the result 51= #e can also assign the answer to another %ariable say @d@ by typing d 8 ;a3b<4c gi%e result d 8 9>=?. #e can check the %alues in the %ariables by typing the names of the %ariables separated by commas on the command line //0a,b,c,d a 8 92. b 8 29. c 8 ::. d 8 9>=?. a,b,c,d gi%es a 8 92. b 8 29. c 8 ::. and d 8 9>=?. To take the power, use the Araised toB symbol: for example, C s)uare can be

Scilab !onsole //0 123141/5161 ///0 ans //0a892, b829, c8::

isual !lue found by C raised to 2. //0 CD2 //0 s)rt;9C< //0 9CD;>.E<

"arration

,or finding the s)uare root of a number, say, 9C, we use : s)rt;9C<. This is same as 9C raised to the power of Fero point fi%e. Gy con%ention, only the positi%e %alue comes as output. Hore generally, to find :1 to the power of ;2 by E<, type: "egati%e powers can also be used, and

//0 :1D;26E<

So far, we ha%e seen how to do some simple calculations and how to create %ariables in Scilab. "ow let us start with a new command which helps us remember pre%iously issued commands and their resulting outputs. ,irst type the command pwd :ans 8 6home6cdeep This is the current working directory ;on this computer<. If course, when you type this on your computer, it could be different. The current working directory can be changed by using the icon as shown.

//0 pwd

$se icon to change directory to desktop "ow issue the diary command by typing: diary;@myrecord.txt@< press enter //0 diary;@myrecord.txt@< This command will create a file with the name 7myrecord.txt7 in the current working Slide directory. A transcript of the Scilab session from now onwards will be sa%ed in this file. .ts usefulness will be demonstrated at a later stage in this tutorial &lease pause the tutorial now and attempt exercise number one gi%en with the %ideo. //0Ji //0E.24Ji //0;9>3E4Ji<4;24Ji< "ow, let us see how Scilab handles complex numbers. The imaginary unit i is defined in Scilab as percent i: ;,i%e point two into percent eye gi%es result E.2i also 9> plus E into percent i whole multiply with 2 into percent i gi%es us 9>. 3 2>.i -et us see some other predefined numerical constants a%ailable in Scilab. As with i, their names also start with the percent sign: //0Jpi ,or example, percent pi The %alue of pi is as expected. "ow, we will demonstrate the use of pi using a few built/in trigonometric functions as follows.

isual !lue /0 sin;Jpi62< /0 cos;Jpi62<

"arration ,or the functions sin of percent pi di%ided by 2 gi%es result 9. and cos percent pi di%ided by 2 gi%es result 5.92:'/9C. "otice first that angles are measured in radians. "otice that the second answer is Fero for all practical purposes. This is related to a number known as 7machine epsilon7, .t is the minimum digit resolution that Scilab can gi%e. Type Jeps in console to find its %alue on your computer.

//0 Jeps

.n my computer it gi%es 2.22>'/95 This shows the floating point precision that Scilab uses : 2.22>'/95. This number is a notation for 2.22 times 9>D;/95<. .f one wants to write >.>>>1E5, one can write 1.E5d/1 or 1.E5e/1.

//0>.>>>1E5 //01.E5d/1 //01.E5e/1

#hile scilab %ariables and functions are case/sensiti%e, here we can use small d or capital ', or small e, or capital K. The base of the natural logarithm is another important predefined numerical constant:

//0Je

percent e gi%es us result 2.C9=2=9= as expected. #e can achie%e the same result with the 7e x p7 function:

//0exp;9<

,or instance: exp of 9: ans 8 2.C9=2=9= Lou can see both the answers are same If course,

//0JeD2

similarly, //0e s)uare gi%es the following answer ans 8 C.:=?>E59 which can also be achie%ed by typing exp of 2 as shown. The command log means the natural logarithm of a number, that is, to the base e. $se log9> for taking the logarithm with respect to base 9>.

//0exp;2<

//0log9>;9e/2:<

,or example, log9>;9e/2:< gi%es the expected answer : ans 8 /2:. #e get complex numbers when taking logarithm of negati%e or complex numbers: you can check for yourself: log;/9< and log;Ji< "ow recall that we in%oked a recording of all the typed commands into the file myrecord.txt through the diary command, now, let@s see how to close that file and %iew it.

isual !lue //0diary;>< ,or closing the file type, diary of Fero

"arration

This command will close and sa%e the file myrecord.txt. Also recall that this file was created in current working directory, which in my case is my desktop. -et us open this file: do this using the Ipen/a/file icon on the top. 6home6cdeep6'esktop6myrecord.txt "ote that all transactions, both commands and the corresponding answers gi%en by Scilab, ha%e been sa%ed into this file. Slide #e know that, while a program is being de%eloped, one experiments a lot before arri%ing at suitable code. .f the diary command is not used, it is difficult to keep a track of all the commands that did or didn@t work. Thus,the diary is one way to address this issue. "ow, no further transactions will be sa%ed because we had closed the file using the command diary;><. .f we need to sa%e the session once again, we need to issue the diary command again. Memember, that the diary command will o%erwrite the file. So, if the file contains some useful information, then one should use some other file name in the diary command. &ause the %ideo here and sol%e the second exercise gi%en with the %ideo. Lou may ha%e noticed that the solution for the problem was not exactly Fero. ,or more information on how to deal with this, type Ahelp cleanB. Slide .n general, if you need help, then the @help@ command can be used. ,or example, Ahelp chdirB gi%es detailed information on how to change the current working directory. If course, we used the icon on the top. -et me close the help browser. The up / down arrow keys can been used to see the pre%iously executed commands. #hile using the up / down arrows, you can stop at any command,and press the Knter key to execute it. Lou can edit the commands, if necessary. .n fact, if you are looking for a pre%ious command you typed, which started with the letter @e@, then type e, and then use up arrow key. $se the tab key to auto/complete the commad. .t gi%es us all the a%ailable options to choose. Slide Summary .n this tutorial we ha%e learnt to : 9.$se Scilab as a calculator with an example. 2.Store the result in the default %ariable ans.

isual !lue

"arration :.Assign %alues to the %ariable using the e)uality sign. 1.!heck %alues in %ariables by typing the name of the %ariable separated by commas on the console. E.!heck the current working directory using pwd command. 5. $se diary command to sa%e all commands typed on the console into a file. C.'efine complex numbers, natural exponents and N using Ji, Je and Jpi respecti%ely. =.$se help command for detailed information about any command.

Slide

This brings us to the end of this spoken tutorial on Getting Started with Scilab. There are many other functions in Scilab which will be co%ered in other spoken tutorials. This spoken tutorial has been created by the ,ree and Ipen Source Software in Science and Kngineering Kducation;,ISSKK<.

Hore information on the ,ISSKK proOect could beobtained from


http:66fossee.in or http:66scilab.in Supported by the "ational Hission on Kduction through .!T, H+M', Go%ernment of .ndia. ,or more information, %isit: http:66spoken/tutorial.org6"HK.!T/.ntro

This is Anuradha Amrutkar from ..T Gombay signing off. Thank you for Ooining. Goodbye.

You might also like