Sie sind auf Seite 1von 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. Visual Clue Title Slide Slide Narration Welcome to the spoken tutorial on Getting Started with Scilab. At the end of this tutorial, you will be able to: Use Scilab as a calculator. Store values in a variable. Perform various mathematical operations using these variables. Create a file to store commands executed during the session in the current working directory. Define complex numbers. Perform exponential, logarithmic and trigonometric operations on numbers. Slide[Prerequisites] Slide Launch Scilab The prerequisite for this tutorial are that Scilab should be installed on your system. Here is the Flow chart for the tutorial. Start Scilab. This is the Scilab console window. Notice that the cursor is on the command prompt. I suggest that you practice this tutorial in Scilab simultaneously while pausing the video at regular intervals of time. Scilab can be used as a calculator. Let us see some of the basic operations that it can do. Type 42 plus 4 into 4 minus 64 divided 4 on the console and press enter. The output is 42, as expected. Note that the answer 42 is stored in the default variable "a n s". We can also create named variables: Type, a equals 12,b=21 and c=33. This stores the values 12,21 and 33 in the variables a,b and c respectively. Now we will perform some mathematical operations using these variables. -->a+b+c ans = 66. -->a*(b+c) ans = 648. -->d = a+b+c d = 1089. For example, a+b+c gives the result 66 also a times (b+c) gives the result 648 We can also assign the answer to another variable say 'd' by typing d = (a+b)*c give result d = 1089. We can check the values in the variables by typing the names of the variables separated by commas on the command line -->a,b,c,d a = 12. b = 21. c = 33. d = 1089. a,b,c,d gives a = 12. b = 21. c = 33. and d = 1089. To take the power, use the raised to symbol: for example, 7 square can be

Scilab Console --> 42+4*4-64/4 ---> ans -->a=12, b=21, c=33

Visual Clue found by 7 raised to 2. --> 7^2 --> sqrt(17) --> 17^(0.5)

Narration

For finding the square root of a number, say, 17, we use : sqrt(17). This is same as 17 raised to the power of zero point five. By convention, only the positive value comes as output. More generally, to find 34 to the power of (2 by 5), type: Negative powers can also be used, and

--> 34^(2/5)

So far, we have seen how to do some simple calculations and how to create variables in Scilab. Now let us start with a new command which helps us remember previously issued commands and their resulting outputs. First type the command pwd :ans = /home/cdeep This is the current working directory (on this computer). Of 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.

--> pwd

Use icon to change directory to desktop Now issue the diary command by typing: diary('myrecord.txt') press enter --> diary('myrecord.txt') This command will create a file with the name "myrecord.txt" in the current working Slide directory. A transcript of the Scilab session from now onwards will be saved in this file. Its usefulness will be demonstrated at a later stage in this tutorial Please pause the tutorial now and attempt exercise number one given with the video. -->%i -->5.2*%i -->(10+5*%i)*(2*%i) Now, let us see how Scilab handles complex numbers. The imaginary unit i is defined in Scilab as percent i: (Five point two into percent eye gives result 5.2i also 10 plus 5 into percent i whole multiply with 2 into percent i gives us 10. + 20.i Let us see some other predefined numerical constants available in Scilab. As with i, their names also start with the percent sign: -->%pi For example, percent pi The value of pi is as expected. Now, we will demonstrate the use of pi using a few built-in trigonometric functions as follows.

Visual Clue -> sin(%pi/2) -> cos(%pi/2)

Narration For the functions sin of percent pi divided by 2 gives result 1. and cos percent pi divided by 2 gives result 6.123D-17. Notice first that angles are measured in radians. Notice that the second answer is zero for all practical purposes. This is related to a number known as "machine epsilon", It is the minimum digit resolution that Scilab can give. Type %eps in console to find its value on your computer.

--> %eps

In my computer it gives 2.220D-16 This shows the floating point precision that Scilab uses : 2.220D-16. This number is a notation for 2.22 times 10^(-16). If one wants to write 0.000456, one can write 4.56d-4 or 4.56e-4.

-->0.000456 -->4.56d-4 -->4.56e-4

While scilab variables and functions are case-sensitive, here we can use small d or capital D, or small e, or capital E. The base of the natural logarithm is another important predefined numerical constant:

-->%e

percent e gives us result 2.7182818 as expected. We can achieve the same result with the "e x p" function:

-->exp(1)

For instance: exp of 1: ans = 2.7182818 You can see both the answers are same Of course,

-->%e^2

similarly, -->e square gives the following answer ans = 7.3890561 which can also be achieved by typing exp of 2 as shown. The command log means the natural logarithm of a number, that is, to the base e. Use log10 for taking the logarithm with respect to base 10.

-->exp(2)

-->log10(1e-23)

For example, log10(1e-23) gives the expected answer : ans = -23. We get complex numbers when taking logarithm of negative or complex numbers: you can check for yourself: log(-1) and log(%i) Now recall that we invoked 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 view it.

Visual Clue -->diary(0) For closing the file type, diary of zero

Narration

This command will close and save the file myrecord.txt. Also recall that this file was created in current working directory, which in my case is my desktop. Let us open this file: do this using the Open-a-file icon on the top. /home/cdeep/Desktop/myrecord.txt Note that all transactions, both commands and the corresponding answers given by Scilab, have been saved into this file. Slide We know that, while a program is being developed, one experiments a lot before arriving at suitable code. If 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. Now, no further transactions will be saved because we had closed the file using the command diary(0). If we need to save the session once again, we need to issue the diary command again. Remember, that the diary command will overwrite the file. So, if the file contains some useful information, then one should use some other file name in the diary command. Pause the video here and solve the second exercise given with the video. You may have noticed that the solution for the problem was not exactly zero. For more information on how to deal with this, type help clean. Slide In general, if you need help, then the 'help' command can be used. For example, help chdir gives detailed information on how to change the current working directory. Of course, we used the icon on the top. Let me close the help browser. The up - down arrow keys can been used to see the previously executed commands. While using the up - down arrows, you can stop at any command,and press the Enter key to execute it. You can edit the commands, if necessary. In fact, if you are looking for a previous command you typed, which started with the letter 'e', then type e, and then use up arrow key. Use the tab key to auto-complete the commad. It gives us all the available options to choose. Slide Summary In this tutorial we have learnt to : 1.Use Scilab as a calculator with an example. 2.Store the result in the default variable ans.

Visual Clue

Narration 3.Assign values to the variable using the equality sign. 4.Check values in variables by typing the name of the variable separated by commas on the console. 5.Check the current working directory using pwd command. 6. Use diary command to save all commands typed on the console into a file. 7.Define complex numbers, natural exponents and using %i, %e and %pi respectively. 8.Use 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 covered in other spoken tutorials. This spoken tutorial has been created by the Free and Open Source Software in Science and Engineering Education(FOSSEE).

More information on the FOSSEE project could beobtained from


http://fossee.in or http://scilab.in Supported by the National Mission on Eduction through ICT, MHRD, Government of India. For more information, visit: http://spoken-tutorial.org/NMEICT-Intro

This is Anuradha Amrutkar from IIT Bombay signing off. Thank you for joining. Goodbye.

Das könnte Ihnen auch gefallen