scilab part i (1)
DESCRIPTION
sTRANSCRIPT
Slide 1
Basic of Scilab
Course OutlineIntroduction to Scilab EnvironmentIntroduction to Environment Basic OperationsMatricesPredefined FunctionsProgramming Boolean/Condition Statements Loops Creation of User defined Functions Different Visualization (with commands)
IntroductionScilab is a scientific software package for technical computing.
The following are the main features of Scilab:
A high-level programming language (interpreter)A data environmentA large collection of predefined functionsIntegrated graphics
IntroductionInternational PresenceFrance Strong presence in mechatronics and engineering Used in high schools, at the agregation de mathmatiques, engineering schools and universitiesEurope European projectsEurocodes (civil engineering)North America Collaboration with National Instruments:LabView/Scilab interface
IntroductionInternational Presence China Since 2002 : yearly Scilab Contest 2005 : Scilab used in secondary schools Chinese Scilab Consortium Japan Collaboration with National Institute of informatics (NII) Since 2006 : yearly Scilab Contest India Collaboration with Indian Institute of Technology (IIT) Bombay Scilab user group and Web site
IntroductionApplication Area of SCILAB Mathematics linear algebra univariate polynomialsdifferential equationsData AnalysisStatisticsOptimizationSignal and SystemsControl SystemsSignal ProcessingImage ProcessingGUI Creation & Application Deployment
Getting Started
Scilab command line is denoted with the symbol -->
It accepts variable declarations, expressions, script and function calls
Scilab scripts and functions are ASCII files
To re-use a previous command, type the up arrow
Getting StartedScilab Shortcut CommandsKeyboardCTRL CommandDescriptionctrl-pRecall previous linectrl-nRecall next linectrl-bMove back one characterctrl-fMove forward one characterhomectrl-aMove to beginning of lineendctrl-eMove to end of lineescctrl-uClear linedelctrl-dDelete character at cursorbackspacectrl-hDelete character before cursorctrl-kDelete to end of linectrl-cInterrupt Scilab and pause after carriage return
Getting StartedFile MenuExecuteOpen a fileLoad EnvironmentSave EnvironmentChange Current DirectoryPage setupPrintQuit
Getting StartedType pwd or getcwd to know the current directory
Create your Working Directory
In you local drive (C:), create a folder named Scilab_CS10-2LC:\Scilab_CS10-2L
Getting StartedEdit Menu
Cut (Ctrl-X) Copy (Ctrl-C) Paste (Ctrl-V) Select All
Getting StartedPreferences Menu
ColorsConsole backgroundConsole font
FontShow / Hide Toolbar Clear History --> resethistoryClear Console --> clc
Getting StartedControl Menu
Resume - resume execution of SCILAB after a pause.Abort - end execution of current program.
Interrupt - interrupt execution of current program, triggering a pause mode.
Getting StartedApplications Menu
Editor (SciNotes 5.3.3) - Opens up a separate text editor window where the user can edit Scilab code. (you may also type: edit)
Xcos - Opens the xcos application for simulations. (you may also type: xcos) Matlab to Scilab translator - Opens a GUI tool for translating Matlab code.
Getting StartedHelp (?) Menu
Scilab Basic Command who - displays current variable names. whos - listing of variables in long form. who_user - listing of user's variables. clc - Clear Command Window. resethistory - Deletes all entries in the Scilab history.clear - kills variables.apropos - searches keywords in Scilab help. disp - displays variables .pwd - print Scilab current directory
Practice ExercisesScilab is also capable of processing trigonometric function like sin, cos, and tan. Using help find out what are the equivalent commands for sin-1, cos-1, and tan-1.
Use apropos to find out the available function to convert numbers from base 10 (decimal) to base 16 (hexadecimal). Test the function with the following data:- convert F00D to base 10- convert 62804 to base 16
Scilab BasicVariables
A variable can be defined simply with the syntax-->name = instruction; The ; symbol prevents to print on screen the results Standard rules common to languages as C or Pascal apply for Scilab variables Names are case sensitive: a is not the same as ATo see the variable value just type its name on the prompt, or go to Applications menu and choose variable browser , or type browsevar() in the command line.
Scilab BasicVariable Types
A specific set of operators is available for the corresponding typeCommon types are(constant, polynomial, function, handle, string, boolean, list, rational, state -space, sparse, boolean sparse)The type of a variable can be obtained using the command : typeof ( variable_name)
Scilab BasicWrite protected variables
Certain variables are predefined and write-protected%i = 1 imaginary unit%pi = 3.1415927 . . . pi greek%e = 2.718281 . . . number of Nepero%eps = 2.2 1016 precision (machine dependent)%inf infinity%nan NotANumber%s s polynomial variable%z z polynomial variable%t true boolean variable%f false boolean variable
Scilab BasicOperators & Order of PrecedenceOperators ( ) parentheses comp. transpose ^ power / division * multiplication - subtraction + addition
Scilab BasicFunctions
Is the main abstraction feature in SCILAB A collection of commands which are executed in a new environment thus isolating function variables from the original environment variables.Consist of built-in functions or user defined functionsTo display List of Built-in Functions type what
Scilab BasicFunctions (Predefined)
Basic function calling syntax : Output = functionname(input)Example: X = sqrt(25)
Take note :The result of a function is assigned to the output variable.The input value is always entered in parenthesis after the function name.The input can be a value or a variable that contains a value.Functions can operate on a vector or matrix.
Scilab BasicFunctions (Predefined)
Elementary functions :sqrt, diag, cosRounding : round, fix, ceil, floorSorting : sort, sortup, gsort, findSpecific matrices : zeros, eye, onesLinear algebra : det, invPolynomials : poly, roots, coeffRandom numbers : randCharacter strings : string, part, evstr, execstr
Scilab BasicMatrices
To insert a matrix the syntaxes are:
Scilab BasicScalars and vectors
Scalars and vectors are matrices
row columnScilab BasicIncremental vectors
Also available linspace(x0,xf,npti)
Scilab BasicAccessing matrix elements
A(i,j) access the element in row i and column jA(2,1:3) select the columns from 1 to 3 of the second rowB=A(3:5,1:3) assign to B the selected sub matrixA(:,2) select column 2A([1 3],3) select a 1x2 vector of two elements: A(1,3) and A(3,3)
Scilab BasicMatrix operations
A wide number of operations are available, in addition to the basic operations such as sum, product, transpose, matrix exponential, inverse, rank, kernel, etc. A library of operations are available under the Linear Algebra section of the help Some operations are also defined to be performed on the single elements of the matrix
Scilab BasicMatrix Functions
--> a = eye(3,3)--> b = ones(4,3)--> b = zeros(3,4)--> c = diag([ 1 2 3 4])--> d = rand(3,3)--> e = [1:5]--> f = [1:3; 4:6; 7:9]--> g = [1:0.1:5]--> h = linspace(1, 5, 5)
Scilab BasicMatrix Operation
+addition-subtraction*multiplication/division\left division^powertranspose.*array multiply./array division.^array power
Scilab BasicPolynomial operations
Defining a variable as polynomial allows to access several specific operations
Scilab BasicPolynomial operations
Define a polynomial from the coefficient: polyDefine a polynomial from its expression (previous example)Define a polynomial by operations on elementary polynomialsExtract the coefficients of a polynomial: coeff
Scilab BasicComplex Numbers
Scilab handles complex numbers as easily as real numbers %i stands for
Practice Exercises1.) Given the following values of matrix A, B, and C
Generate the matrix below using some of the matrix operations and functions. A1225730627721203B36371248163254128526C12300302061171110030R1000161616162012203001616161646222000701616161660140000316161616040260
Practice Exercises2.) Generate the matrix below using some of the matrix operations and functions. M001100001100111111111111001100001100