From Script | Spoken-Tutorial
Revision as of 17:51, 3 March 2017 by Kaushik Datta (Talk | contribs)

Jump to: navigation, search
Time Narration
00:01 নমস্কার বন্ধুগণ, scilab -এর script এবং function -এর ওপর এই স্পোকেন টিউটোরিয়ালটিতে আপনাদের স্বাগত জানাই
00:06 প্রথমেই শুরু করা যাক scilab -এ ফাইল ফর্মাট -এর ওপর একটি সংক্ষিপ্ত উপস্থাপনাকে দিয়ে
00:12 যখন কতগুলি কমান্ডসকে একসঙ্গে কার্যকর করতে হয় , তখন সেগুলি বা সেই statements গুলিকে scilab এডিটর -এর সাহায্যে একটি ফাইল -এ লেখা অনেক বেশী সুবিধাজনক
00:21 এইগুলিকে স্ক্রিপ্ট ফাইলস বলে
00:24 স্ক্রিপ্ট ফাইল -এ লিখিত কমান্ডগুলিকে কার্যকর বা সম্পাদন করতে হলে স্ক্রিপ্ট ফাইল-এর নাম দিয়ে exec ফাংশন ব্যবহার করা যেতে পারে
00:34 এই ফাইলগুলির একটি extension থাকে .sce বা .sci
00:42 এবং এটি নির্ভর করে ফাইল -এর content বা উপাদানের ওপর
00:51 (কিন্তু সেগুলিকে সম্পাদন বা কার্যকর করে না)
01:00 files having the .sce extension can contain Scilab function and User defined functions.
01:08 Please remember that the convention of naming the extension as .sce and .sci are not rules but a convention followed by the scilab community.
01:21 চলুন এবারে কম্পিউটার -এ scilab খুলি
01:27 Check on the present working directory by typing the command pwd on the command prompt.
01:35 এবারে scilab কনসল উইন্ডো টাস্ক বার-এ গিয়ে এডিটর option -এ ক্লিক করুন scilab এডিটর খোলবার জন্যে
01:49 তাই এখন আমি ফাইলটি খুলবো ফাইল-এর শর্টকাট আইকন open করে
02:03 Select helloworld.sce file and click on Open.
02:10 You may type the commands in the new file and save this file to the current working directory as helloworld.sce through the File menu.
02:20 Go to Execute button on the scilab editors menu bar and select Load into Scilab option.
02:29 This will load the file into scilab console.
02:34 After loading the file on the console the script produces the output as you see.
02:43 It contains both the commands and the resulting output for the respective commands.
02:49 Now change the value of a to 1.
02:55 In the editor, go to the File menu and click on Save.
03:02 We can also execute the script directly from the scilab interpreter using the exec command and giving the path to the script file as:
03:12 exec into brackets into double quotes helloworld.sce, that is the file name, and press Enter.
03:31 The script file produces a similar output with the use of exec function.
03:37 Let us now talk about functions.
03:39 A function definition starts with the keyword function and ends with the keyword endfunction.
03:46 I have already saved a function file in function.sci, using the scilab editor.
03:57 I will open that file.
04:03 As you see, the function is defined here.
04:08 In these, degrees is the output parameter and radians is the input parameter.
04:21 To the function name radians2degrees.
04:26 I will load this function in Scilab, using the Execute menu option.
04:40 The function is now loaded in the scilab console.
04:44 It can also be loaded using the exec command.
04:47 Once a function is loaded, it can be called like any other Scilab function by passing specific arguments to that function.
04:56 Make a mental note of the percent sign (%) and recall the reason of its use.
05:02 Now let us find values for radians2degrees of %pi/2 and radians2degrees of (%pi/4).
05:17 percent pi/2 and radians2degrees percent pi by 4 (%pi/4).
05:28 Now we will see a function with more than one input and output arguments.
05:33 This function will take polar coordinates as input argument and returns rectangular coordinates as output arguments.
05:44 I will open the file which I have already typed.
05:51 Here you can see, x and y are the output parameters and r and theta are the input parameters to the function polar2rect.
06:06 I will load this function in scilab using the exec option.
06:21 Once the function is loaded, we need to call the function. This function requires two input arguments and two output arguments.
06:31 Therefore r = 2,
06:37 theta = 45;
06:44 and now we will call it x1 comma y1, output parameters, is equal to function name polar2rect into bracket r comma theta and press Enter.
07:25 You will see the value of x1 and y1.
07:29 One of the interesting features of Scilab is, you can define any number of functions in a single .sci file.
07:38 While doing this, please remember that by default all the variables defined in a function are local, the scope of these variables used in a particular function ends with the endfunction keyword of the function definition.
07:55 Advantage of this feature is that, we can use same variable names in different function.
08:05 These variables won't get mixed up unless we use the global option.
08:10 To know more about the global variables, type help global.
08:18 Please note that if any variable is to be "watched" or monitored inside a function then disp is required.
08:26 Inside a function file, you can check for yourself the effect of putting a semicolon ( ; ) at the end of a statement.
08:34 Also check this for disp statements.
08:38 Inline Functions:
08:39 Functions are segments of code that have well defined input and output as well as local variables.
08:46 The simplest way to define a function is by using the command `deff.
08:53 Scilab allows the creation of in-line functions and are especially useful when the body of the function is short.
09:02 This can be done with the help of the function deff().
09:07 It takes two string parameters.
09:10 The first string defines the interface to the function and the second string defines the statements of the function.
09:19 The deff command defines the function in the Scilab and also loads it.
09:26 There is no need to load the function defined by using deff command explicitly through execute menu option .
09:34 Let us see an example to illustrate this concept:
09:41 I will open a file inline.sci where I have written the inline function.
09:51 I will resize the editor window.
09:57 As mentioned earlier, the first string defines the function declaration and the second string defines the statements of the function.
10:13 We will load this function in Scilab editor and use it to find the values of degrees2radians of 90 and degrees2radians of 45.
10:54 A function should call, not just other functions within itself, but also itself.
11:00 This is recursive calling of a function.
11:03 This is required, for example, when writing a function to calculate the factorial of an integer.
11:10 Let us extend the discussion on file formats in Scilab:
11:14 As mentioned earlier Scilab uses two types of file formats, namely the .sce file format and the .sci file formats.
11:23 The files with the .sce file extension are the script files which contain the Scilab commands that you enter during an interactive kind of Scilab session.
11:35 They can comprise comment lines utilized in documenting the function and they can also use the command exec to execute the script.
11:52 The files with the .sci file extension are the function files that start with the function statement.
12:00 A single .sci file can have multiple function definitions which themselves contain any number of Scilab statements, that perform operations on the function arguments or on the output variables, after they have been evaluated.
12:20 This brings us to the end of this spoken tutorial on Scripts and Functions in Scilab.
12:25 There are many other functions in Scilab which will be covered in other spoken tutorials.
12:31 Keep watching the Scilab links.
12:33 This spoken tutorial: has been created by the Free and Open Source Software in Science and Engineering Education (FOSSEE).
12:40 More information on the FOSSEE project could be obtained from or
12:50 Supported by the National Mission on Eduction through ICT, MHRD, Government of India.
12:56 For more information, visit:
13:06 This is Anuradha Amrutkar from IIT Bombay. signing off.
13:10 Thanks for joining us. Goodbye.

Contributors and Content Editors

Kaushik Datta