SlideShare a Scribd company logo
1 of 150
Download to read offline
1
SCILAB
AN INTRODUCTION
Arun Umrao
www.sites.google.com/view/arunumrao
DRAFT COPY - GPL LICENSING
2
Contents
I Scilab 7
1 Scilab Core 9
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.1.1 Everything As Matrix . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.1.2 Approximate Zero . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.1.3 Computational Error . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2 Simple Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.2.1 Addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2.2 Subtraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.2.3 Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.2.4 Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.2.5 Scoping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.2.6 Square Root (sqrt) . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.2.7 Exponent (ˆ Operator) . . . . . . . . . . . . . . . . . . . . . . . . 17
1.2.8 Algebraic Equations . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.2.9 Logarithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.2.10 Index Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.3 Arithmetical Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.3.1 Result Variable (ans) . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.3.2 Left Matrix Division () . . . . . . . . . . . . . . . . . . . . . . . . 25
1.3.3 Square Brackets ([...]) . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.3.4 Element-Wise Operation . . . . . . . . . . . . . . . . . . . . . . . . 27
1.3.5 Matrix-Wise Operation . . . . . . . . . . . . . . . . . . . . . . . . 27
1.3.6 Colon (Range Operator) . . . . . . . . . . . . . . . . . . . . . . . . 27
1.3.7 Comma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
1.3.8 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.3.9 Dot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.3.10 Empty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.3.11 Equal Sign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.3.12 global . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.3.13 Hat Symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.3.14 Less Than . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.3.15 Minus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.3.16 Not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.3.17 Parenthesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.3.18 Percent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.3.19 Plus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.3.20 Quote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.3.21 Return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.3.22 Semicolon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
1.3.23 Forward Slash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.3.24 Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.3.25 Asterisk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3
1.3.26 Tilda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
1.4 Core Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
1.4.1 Abort Process (abort) . . . . . . . . . . . . . . . . . . . . . . . . . 41
1.4.2 Add a Demo (add demo) . . . . . . . . . . . . . . . . . . . . . . . 42
1.4.3 Number of Arguments (argn) . . . . . . . . . . . . . . . . . . . . . 42
1.4.4 Banner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.4.5 Boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Shortcut && And Elementwise & . . . . . . . . . . . . . . . . . . . 43
Shortcut || And Elementwise | . . . . . . . . . . . . . . . . . . . . . 43
1.4.6 Break a Process (break) . . . . . . . . . . . . . . . . . . . . . . . . 44
1.4.7 Case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.4.8 Kill the Value (clear) . . . . . . . . . . . . . . . . . . . . . . . . . . 45
1.4.9 Remove a Function (clearfun) . . . . . . . . . . . . . . . . . . . . . 45
1.4.10 Clear Global . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
1.4.11 Compile Scilab Function (comp) . . . . . . . . . . . . . . . . . . . 45
1.4.12 Continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
1.4.13 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
1.4.14 Delete Break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
1.4.15 Display Break Points (dispbpt) . . . . . . . . . . . . . . . . . . . . 47
1.4.16 Do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
1.4.17 Edit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
1.4.18 Else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
1.4.19 Else-If . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
1.4.20 End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
1.4.21 Catch Error (errcatch) . . . . . . . . . . . . . . . . . . . . . . . . . 50
1.4.22 Clear The Error (errclear) . . . . . . . . . . . . . . . . . . . . . . . 50
1.4.23 Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
1.4.24 Exists a Variable (exists) . . . . . . . . . . . . . . . . . . . . . . . 51
1.4.25 Exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
1.4.26 Extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
1.4.27 For . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
1.4.28 Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
1.4.29 MD5 Hash (getmd5) . . . . . . . . . . . . . . . . . . . . . . . . . . 54
1.4.30 Get Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
1.4.31 Get Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
1.4.32 Get Operating System . . . . . . . . . . . . . . . . . . . . . . . . . 55
1.4.33 Get Scilab Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
1.4.34 Get Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
1.4.35 Get Variale Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
1.4.36 Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
1.4.37 Insertion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
1.4.38 Interface Properties (intppty) . . . . . . . . . . . . . . . . . . . . . 57
1.4.39 Inverse Coefficients (inv coeff) . . . . . . . . . . . . . . . . . . . . 57
1.4.40 Is Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
1.4.41 Is Global . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
1.4.42 Line Spacing (linspace) . . . . . . . . . . . . . . . . . . . . . . . . 58
1.4.43 Last Error (lasterror) . . . . . . . . . . . . . . . . . . . . . . . . . 59
4
1.4.44 Macro To List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
1.4.45 Macro To Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
1.4.46 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
1.4.47 Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
1.4.48 Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
1.4.49 Matlab Mode (mtlb mode) . . . . . . . . . . . . . . . . . . . . . . 62
1.4.50 Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
1.4.51 New Function (newfun) . . . . . . . . . . . . . . . . . . . . . . . . 63
1.4.52 Null . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
1.4.53 Pause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
1.4.54 Predefined Variables (predef) . . . . . . . . . . . . . . . . . . . . . 64
1.4.55 Print Output in L
A
TEX (prettyprint) . . . . . . . . . . . . . . . . . 65
1.4.56 Quit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
1.4.57 Random Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
1.4.58 Read Gateway . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
1.4.59 Resume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
1.4.60 Select . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
1.4.61 Set Break Points (setbpt) . . . . . . . . . . . . . . . . . . . . . . . 67
1.4.62 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
1.4.63 Temporary Directory (TMPDIR) . . . . . . . . . . . . . . . . . . . 68
1.4.64 Test Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
1.4.65 Then . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
1.4.66 Try . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
1.4.67 Type (type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
1.4.68 Integer Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
1.4.69 Varn (varn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
1.4.70 Warning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
1.4.71 With tk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
1.4.72 While . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
1.5 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
1.5.1 Defining Own Function . . . . . . . . . . . . . . . . . . . . . . . . 73
1.5.2 Rewriting Own Function . . . . . . . . . . . . . . . . . . . . . . . . 74
1.5.3 Redefining Function Error . . . . . . . . . . . . . . . . . . . . . . . 75
1.5.4 Compilation Warning . . . . . . . . . . . . . . . . . . . . . . . . . 76
1.5.5 Undefined Variable Error . . . . . . . . . . . . . . . . . . . . . . . 76
1.5.6 Implementation Error . . . . . . . . . . . . . . . . . . . . . . . . . 77
1.5.7 Change Function in Prototype (funcprot) . . . . . . . . . . . . . . 77
1.5.8 Function Pointer (funptr) . . . . . . . . . . . . . . . . . . . . . . . 78
2 Linear Algebra 79
2.1 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
2.1.1 Simultaneous Solution . . . . . . . . . . . . . . . . . . . . . . . . . 79
2.1.2 Mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
2.1.3 Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
2.1.4 Data Frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
2.1.5 Tabulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
2.2 Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
5
2.2.1 Clean (clean) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
2.2.2 Degree of Polynomial (degree) . . . . . . . . . . . . . . . . . . . . 83
2.2.3 Solve Algebraic Equations (fsolve) . . . . . . . . . . . . . . . . . . 84
2.2.4 Denominator (denom) . . . . . . . . . . . . . . . . . . . . . . . . . 85
2.2.5 Derivative (derivat) . . . . . . . . . . . . . . . . . . . . . . . . . . 86
2.2.6 Determinant (determ) . . . . . . . . . . . . . . . . . . . . . . . . . 86
2.2.7 Determinant (detr) . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
2.2.8 Factors (factors) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
2.2.9 Greatest Common Divisor (gcd) . . . . . . . . . . . . . . . . . . . 88
2.2.10 Inverse of Matrix (invr) . . . . . . . . . . . . . . . . . . . . . . . . 88
2.2.11 Least Common Multiple (lcm) . . . . . . . . . . . . . . . . . . . . 89
2.2.12 LCM By Diagonalization (lcmdiag) . . . . . . . . . . . . . . . . . . 89
2.2.13 Numerator (numer) . . . . . . . . . . . . . . . . . . . . . . . . . . 90
2.2.14 Polynomial (poly) . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
2.2.15 Polynomial Division (pdiv) . . . . . . . . . . . . . . . . . . . . . . 91
2.2.16 Residue (residu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
2.2.17 Roots of Polynomial (roots) . . . . . . . . . . . . . . . . . . . . . . 93
Roots of Quadratic Equation . . . . . . . . . . . . . . . . . . . . . 93
Roots of Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . 94
2.2.18 Simplification (simp) . . . . . . . . . . . . . . . . . . . . . . . . . . 95
2.2.19 Flip Matrix Dimension (flipdim) . . . . . . . . . . . . . . . . . . . 95
2.2.20 Permutation (permute) . . . . . . . . . . . . . . . . . . . . . . . . 96
2.2.21 Matrix Replication (repmat) . . . . . . . . . . . . . . . . . . . . . 96
2.2.22 Cumulative Product (cumprod) . . . . . . . . . . . . . . . . . . . . 96
2.2.23 Cumulative Summation (cumsum) . . . . . . . . . . . . . . . . . . 98
2.2.24 Kronekar Product (kron) . . . . . . . . . . . . . . . . . . . . . . . 99
2.2.25 Product (prod) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
2.2.26 Summation (sum) . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
2.3 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
2.3.1 Determinant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
2.3.2 Transpose Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
2.3.3 Diagonal Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
2.3.4 Identity Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
2.3.5 Inverse of Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
2.3.6 Normalization of Matrix . . . . . . . . . . . . . . . . . . . . . . . . 110
2.3.7 Normalzation Factor (norm) . . . . . . . . . . . . . . . . . . . . . . 111
2.3.8 Permutation & Transposition (pertrans) . . . . . . . . . . . . . . . 112
2.3.9 Orthogonal Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
2.3.10 Complex Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
2.3.11 Matrix Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
2.3.12 Eigenvalues of Matrix . . . . . . . . . . . . . . . . . . . . . . . . . 115
2.3.13 Triangular Lower Matrix (tril) . . . . . . . . . . . . . . . . . . . . 116
2.3.14 Triangular Upper Matrix (triu) . . . . . . . . . . . . . . . . . . . . 116
2.3.15 Lower Upper Matrix (lu) . . . . . . . . . . . . . . . . . . . . . . . 117
2.3.16 Diagonal Matrix (diag) . . . . . . . . . . . . . . . . . . . . . . . . 117
2.3.17 Jordan Canonical Form (bdiag) . . . . . . . . . . . . . . . . . . . . 119
2.3.18 Cholensky Factorization (chol) . . . . . . . . . . . . . . . . . . . . 120
6
2.3.19 Determinant of Matrix (det) . . . . . . . . . . . . . . . . . . . . . 121
2.3.20 Inverse Matrix (inv) . . . . . . . . . . . . . . . . . . . . . . . . . . 122
2.3.21 Orthogonal Matrix (orth) . . . . . . . . . . . . . . . . . . . . . . . 123
2.3.22 Rank of Matrix (rank) . . . . . . . . . . . . . . . . . . . . . . . . . 125
2.3.23 Eigenvalues & Eigenvectors (spec) . . . . . . . . . . . . . . . . . . 126
2.3.24 Square Root of Matrix . . . . . . . . . . . . . . . . . . . . . . . . . 128
2.3.25 Hermitian Factorisation (sqroot) . . . . . . . . . . . . . . . . . . . 130
2.3.26 Signaular Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
2.3.27 Singular Value Approximation (sva) . . . . . . . . . . . . . . . . . 131
2.3.28 Singular Value Decomposition (svd) . . . . . . . . . . . . . . . . . 131
2.3.29 Trace of Matrix (trace) . . . . . . . . . . . . . . . . . . . . . . . . 135
3 Calculus 137
3.1 Derivative Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
3.1.1 Derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
3.1.2 Numeric Derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
3.1.3 Numeric Difference . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
3.1.4 Function Evaluation (feval) . . . . . . . . . . . . . . . . . . . . . . 138
3.2 Integral Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
3.2.1 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
3.2.2 Double Integral (int2d) . . . . . . . . . . . . . . . . . . . . . . . . 140
3.2.3 Tripple Integration (int3d) . . . . . . . . . . . . . . . . . . . . . . 141
3.2.4 Integrate (integrate) . . . . . . . . . . . . . . . . . . . . . . . . . . 143
3.2.5 Definite Integration (intg) . . . . . . . . . . . . . . . . . . . . . . . 143
3.2.6 Cauchy’s Integration (intc) . . . . . . . . . . . . . . . . . . . . . . 143
3.2.7 Cauchy Integration (intl) . . . . . . . . . . . . . . . . . . . . . . . 146
3.3 Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
3.3.1 Ordinary Differential Equation (ode) . . . . . . . . . . . . . . . . . 148
3.3.2 Differential Algebraic System Solver (dassl) . . . . . . . . . . . . . 150
4 Elementary Functions 157
4.1 Data Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
4.1.1 Comparison of Data . . . . . . . . . . . . . . . . . . . . . . . . . . 157
4.1.2 Data Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
4.1.3 Creation of Matrix Cell . . . . . . . . . . . . . . . . . . . . . . . . 158
4.1.4 Creation of List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
4.2 Bitwise operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
4.2.1 Bitwise AND (bitand) . . . . . . . . . . . . . . . . . . . . . . . . . 160
4.2.2 Bitwise Complements (bitcmp) . . . . . . . . . . . . . . . . . . . . 160
4.2.3 Get a Position Bit (bitget) . . . . . . . . . . . . . . . . . . . . . . 161
4.2.4 Bitwise OR (bitor) . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
4.2.5 Set Bit In Position (bitset) . . . . . . . . . . . . . . . . . . . . . . 162
4.2.6 Bitwise Exclusive OR (bitxor) . . . . . . . . . . . . . . . . . . . . 162
4.3 Complex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
4.3.1 Complex Number (complex) . . . . . . . . . . . . . . . . . . . . . . 163
4.3.2 Complex Imaginary (imag) . . . . . . . . . . . . . . . . . . . . . . 163
4.3.3 Iota Multiplication (imult) . . . . . . . . . . . . . . . . . . . . . . 164
7
4.3.4 Is Real (isreal) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
4.3.5 Complex Real (real) . . . . . . . . . . . . . . . . . . . . . . . . . . 164
4.3.6 Complex Conjugate (conj) . . . . . . . . . . . . . . . . . . . . . . . 164
4.4 Discrete mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
4.4.1 Binomials (binomial) . . . . . . . . . . . . . . . . . . . . . . . . . . 165
4.4.2 Factors (factor) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
4.4.3 Factorial (factorial) . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
4.4.4 Permutations (perms) . . . . . . . . . . . . . . . . . . . . . . . . . 166
4.4.5 Primes (primes) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
4.5 Floating point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
4.5.1 Ceiling To (ceil) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
4.5.2 Double (double) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
4.5.3 Number as Integer (int8) . . . . . . . . . . . . . . . . . . . . . . . 167
4.5.4 Fix to Zero (fix) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
4.5.5 Round to Lower Integer (floor) . . . . . . . . . . . . . . . . . . . . 168
4.5.6 Base 2 Exponent (frexp) . . . . . . . . . . . . . . . . . . . . . . . . 169
4.5.7 Integer (int) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
4.5.8 Whether Infinity (isinf) . . . . . . . . . . . . . . . . . . . . . . . . 169
4.5.9 Whether Not a Number (isnan) . . . . . . . . . . . . . . . . . . . . 170
4.5.10 Near Float (nearfloat) . . . . . . . . . . . . . . . . . . . . . . . . . 170
4.5.11 Round (round) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
4.6 Number Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
4.6.1 Conversion About Any Base (base2dec) . . . . . . . . . . . . . . . 170
4.6.2 Binary to Decimal (bin2dec) . . . . . . . . . . . . . . . . . . . . . 171
4.6.3 Decimal to Binary (dec2bin) . . . . . . . . . . . . . . . . . . . . . 171
4.6.4 Decimal To Hexadecimal (dec2hex) . . . . . . . . . . . . . . . . . . 171
4.6.5 Decimal to Octal (dec2oct) . . . . . . . . . . . . . . . . . . . . . . 172
4.6.6 Hexadecimal to Decimal (hex2dec) . . . . . . . . . . . . . . . . . . 172
4.6.7 Octal to Decimal (oct2dec) . . . . . . . . . . . . . . . . . . . . . . 172
4.7 Set operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
4.7.1 Intersect (intersect) . . . . . . . . . . . . . . . . . . . . . . . . . . 173
4.7.2 Sorted Difference (setdiff) . . . . . . . . . . . . . . . . . . . . . . . 173
4.7.3 Union of Sets (union) . . . . . . . . . . . . . . . . . . . . . . . . . 174
4.7.4 Unique Component (unique) . . . . . . . . . . . . . . . . . . . . . 175
4.8 Trigonometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
4.8.1 Inverse Trigonometric Functions . . . . . . . . . . . . . . . . . . . 176
Inverse Sine in Radian (asin) . . . . . . . . . . . . . . . . . . . . . 176
Inverse Sine in Degree (asind) . . . . . . . . . . . . . . . . . . . . . 176
Inverse Hyperbolic Sine (asinh) . . . . . . . . . . . . . . . . . . . . 176
Matrix Inverse Hyperbolic Sine (asinhm) . . . . . . . . . . . . . . 177
Matrix Inverse Sine (asinm) . . . . . . . . . . . . . . . . . . . . . . 177
Inverse Cosine in Radian (acos) . . . . . . . . . . . . . . . . . . . . 177
Inverse Cosine In Degree (acosd) . . . . . . . . . . . . . . . . . . . 177
Inverse Hyperbolic Cosine (acosh) . . . . . . . . . . . . . . . . . . 178
Matrix Inverse Hyperbolic Cosine (acoshm) . . . . . . . . . . . . . 178
Matrix Inverse Cosine (acosm) . . . . . . . . . . . . . . . . . . . . 179
Inverse Tangent in Radian (atan) . . . . . . . . . . . . . . . . . . . 179
8
Inverse Tangent in Degree (atand) . . . . . . . . . . . . . . . . . . 179
Inverse Hyperbolic Tangent (atanh) . . . . . . . . . . . . . . . . . 179
Matrix Inverse Hyperbolic Tangent (atanhm) . . . . . . . . . . . . 180
Matrix Inverse Tangent (atanm) . . . . . . . . . . . . . . . . . . . 180
Inverse Cotangent in Radian(acot) . . . . . . . . . . . . . . . . . . 180
Inverse Cotangent in Degree (acotd) . . . . . . . . . . . . . . . . . 181
Inverse Hyperbolic Cotangent (acoth) . . . . . . . . . . . . . . . . 181
Inverse Secant in Radian (asec) . . . . . . . . . . . . . . . . . . . . 181
Inverse Secant in Degree (asecd) . . . . . . . . . . . . . . . . . . . 182
Inverse Hyperbolic Secant (asech) . . . . . . . . . . . . . . . . . . 182
Inverse Cosecant in Radian (acsc) . . . . . . . . . . . . . . . . . . 182
Inverse Cosecant in Degree (acscd) . . . . . . . . . . . . . . . . . . 183
Inverse Hyperbolic Cosecant (acsch) . . . . . . . . . . . . . . . . . 183
4.8.2 Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . . . . 183
Sine - Argument in Radian (sin) . . . . . . . . . . . . . . . . . . . 183
Cardinal Sine (sinc) . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Sine - Argument in Degree (sind) . . . . . . . . . . . . . . . . . . . 184
Hyperbolic Sine (sinh) . . . . . . . . . . . . . . . . . . . . . . . . . 185
Matrix Hyperbolic Sine (sinhm) . . . . . . . . . . . . . . . . . . . 185
Matrix Sine (sinm) . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Cosine - Argument In Radian (cos) . . . . . . . . . . . . . . . . . . 186
Cosine - Argument In Degree (cosd) . . . . . . . . . . . . . . . . . 186
Hyperbolic Cosine (cosh) . . . . . . . . . . . . . . . . . . . . . . . 186
Matrix Hyperbolic Cosine (coshm) . . . . . . . . . . . . . . . . . . 186
Matrix Cosine (cosm) . . . . . . . . . . . . . . . . . . . . . . . . . 187
Tangent - Argument in Radian (tan) . . . . . . . . . . . . . . . . . 187
Tangent - Argument in Degree (tand) . . . . . . . . . . . . . . . . 187
Hyperbolic Tangent (tanh) . . . . . . . . . . . . . . . . . . . . . . 187
Matrix Hyperbolic Tangent (tanhm) . . . . . . . . . . . . . . . . . 188
Matrix Tangent (tanm) . . . . . . . . . . . . . . . . . . . . . . . . 188
Cotangent - Argument in Degree (cotd) . . . . . . . . . . . . . . . 188
Hyperbolic Cotangent (coth) . . . . . . . . . . . . . . . . . . . . . 188
Matrix Hyperbolic Cotangent (cothm) . . . . . . . . . . . . . . . . 189
Secant - Argument in Radian (sec) . . . . . . . . . . . . . . . . . . 189
Secant - Argument in Degree (secd) . . . . . . . . . . . . . . . . . 189
Hyperbolic Secant (sech) . . . . . . . . . . . . . . . . . . . . . . . 189
Cosecant - Input in Radian (csc) . . . . . . . . . . . . . . . . . . . 190
Cosecant - Input in Degree (cscd) . . . . . . . . . . . . . . . . . . 190
Hyperbolic Cosecant (csch) . . . . . . . . . . . . . . . . . . . . . . 190
4.9 Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
4.9.1 Absolute (abs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
4.9.2 Concatenate (cat) . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
4.9.3 Cell Array to Matrix (cell2mat) . . . . . . . . . . . . . . . . . . . . 191
4.9.4 Cell String (cellstr) . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
4.9.5 Integer to Char (char) . . . . . . . . . . . . . . . . . . . . . . . . . 192
4.9.6 Elliptical Integral (delip) . . . . . . . . . . . . . . . . . . . . . . . 192
4.9.7 Differentiation (diff) . . . . . . . . . . . . . . . . . . . . . . . . . . 193
9
4.9.8 Exponential (exp) . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
4.9.9 Exponential Matrix (expm) . . . . . . . . . . . . . . . . . . . . . . 195
4.9.10 Interpolation (inttrap) . . . . . . . . . . . . . . . . . . . . . . . . . 197
4.9.11 Is Variable Defined (isdef) . . . . . . . . . . . . . . . . . . . . . . . 198
4.9.12 Is Variable Empty (isempty) . . . . . . . . . . . . . . . . . . . . . 198
4.9.13 Variables Are Equal (isequal) . . . . . . . . . . . . . . . . . . . . . 198
4.9.14 Bitwise Equality (isequalbitwise) . . . . . . . . . . . . . . . . . . . 199
4.9.15 Whether Vector (isvector) . . . . . . . . . . . . . . . . . . . . . . . 199
4.9.16 List Size (lstsize) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
4.9.17 Maximum (max) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
4.9.18 Minimum (min) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
4.9.19 Modulus (modulo) . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
4.9.20 Array Dimension (ndims) . . . . . . . . . . . . . . . . . . . . . . . 200
4.9.21 Signum Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Signum of Matrix (sign) . . . . . . . . . . . . . . . . . . . . . . . . 201
Signum Matrix (signm) . . . . . . . . . . . . . . . . . . . . . . . . 202
Complex Sign (csgn) . . . . . . . . . . . . . . . . . . . . . . . . . . 202
4.9.22 Object Size (size) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
4.9.23 Square Root (sqrt) . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
4.9.24 Square Wave (squarewave) . . . . . . . . . . . . . . . . . . . . . . 203
4.9.25 Object Type (typeof) . . . . . . . . . . . . . . . . . . . . . . . . . 204
4.10 Logarithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
4.10.1 Natural Logarithm (log) . . . . . . . . . . . . . . . . . . . . . . . . 205
4.10.2 Logarithm Base ‘10’ (log10) . . . . . . . . . . . . . . . . . . . . . . 205
4.10.3 Increment & Logarithm (log1p) . . . . . . . . . . . . . . . . . . . . 206
4.10.4 Logarithm Base ‘2’ (log2) . . . . . . . . . . . . . . . . . . . . . . . 206
4.10.5 Matrixwise Logarithm (logm) . . . . . . . . . . . . . . . . . . . . . 206
4.11 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
4.11.1 Lineary Interpolation (interp1) . . . . . . . . . . . . . . . . . . . . 207
4.11.2 Two Data Linear Interpolation (interpln) . . . . . . . . . . . . . . 207
4.11.3 Linear Interpolation (linear interpn) . . . . . . . . . . . . . . . . . 208
4.12 Symbolic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
4.12.1 Symbolic Addition (addf) . . . . . . . . . . . . . . . . . . . . . . . 209
4.12.2 Symbolic Left Division (ldivf) . . . . . . . . . . . . . . . . . . . . . 209
4.12.3 Symbolic Multiplication (mulf) . . . . . . . . . . . . . . . . . . . . 209
4.12.4 Symbolic Right Division (rdivf) . . . . . . . . . . . . . . . . . . . . 209
4.12.5 Symbolie Subtraction (subf) . . . . . . . . . . . . . . . . . . . . . . 210
5 Special Functions 211
5.1 Bessel Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
5.1.1 Bessel Function of Second Kind (besselj) . . . . . . . . . . . . . . . 211
5.1.2 Bessel Function of Second Kind (bessely) . . . . . . . . . . . . . . 211
5.1.3 Bessel Function of First Kind (besseli) . . . . . . . . . . . . . . . . 212
5.1.4 Hyperbolic Bessel Function of Second Kind (besselk) . . . . . . . . 212
5.1.5 Bessel Function as Hankel Function (besselh) . . . . . . . . . . . . 213
5.2 Beta Function (beta) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
5.3 Gamma Function (gamma) . . . . . . . . . . . . . . . . . . . . . . . . . . 213
10
5.3.1 Logarithm of Gamma Function (gammaln) . . . . . . . . . . . . . 214
5.4 Legendre Function (legendre) . . . . . . . . . . . . . . . . . . . . . . . . . 214
5.5 Error Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
5.5.1 Calculate Error (calerf) . . . . . . . . . . . . . . . . . . . . . . . . 214
5.5.2 Error Function (erf) . . . . . . . . . . . . . . . . . . . . . . . . . . 215
5.5.3 Complementary Error Function (erfc) . . . . . . . . . . . . . . . . 216
5.5.4 Inverse Error Function (erfinv) . . . . . . . . . . . . . . . . . . . . 216
6 Directory & Files 217
6.1 Directory Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
6.1.1 Change Directory (chdir) . . . . . . . . . . . . . . . . . . . . . . . 217
6.1.2 Create Directory (createdir) . . . . . . . . . . . . . . . . . . . . . . 217
6.1.3 List Current Directory (dir) . . . . . . . . . . . . . . . . . . . . . . 217
6.1.4 Whether A Directory (isdir) . . . . . . . . . . . . . . . . . . . . . . 218
6.1.5 List Current Directory (ls) . . . . . . . . . . . . . . . . . . . . . . 218
6.1.6 Make Directory (mkdir) . . . . . . . . . . . . . . . . . . . . . . . . 218
6.1.7 Present Working Directory (pwd) . . . . . . . . . . . . . . . . . . . 218
6.1.8 Remove Directory (removedir) . . . . . . . . . . . . . . . . . . . . 219
6.1.9 Remove Directory (rmdir) . . . . . . . . . . . . . . . . . . . . . . . 219
6.1.10 Base Name of File (basename) . . . . . . . . . . . . . . . . . . . . 219
6.1.11 Directory name (dirname) . . . . . . . . . . . . . . . . . . . . . . . 219
6.1.12 Extension Name (fileext) . . . . . . . . . . . . . . . . . . . . . . . 220
6.1.13 Parts of File (fileparts) . . . . . . . . . . . . . . . . . . . . . . . . . 220
6.1.14 Path Separator (filesep) . . . . . . . . . . . . . . . . . . . . . . . . 220
6.1.15 Fill File Name (fullfile) . . . . . . . . . . . . . . . . . . . . . . . . 220
6.1.16 Full File Path (fullpath) . . . . . . . . . . . . . . . . . . . . . . . . 221
6.1.17 Drives In System (getdrives) . . . . . . . . . . . . . . . . . . . . . 221
6.1.18 Temporary Name (tempname) . . . . . . . . . . . . . . . . . . . . 221
6.2 file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
6.2.1 Open a file (file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
6.2.2 Close a file (file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
6.2.3 Copy File (copyfile) . . . . . . . . . . . . . . . . . . . . . . . . . . 222
6.2.4 Delete File (deletefile) . . . . . . . . . . . . . . . . . . . . . . . . . 223
6.2.5 File Information (fileinfo) . . . . . . . . . . . . . . . . . . . . . . . 223
6.2.6 Search Files (findfiles) . . . . . . . . . . . . . . . . . . . . . . . . . 223
6.2.7 Write Matrix to File (fprintfMat) . . . . . . . . . . . . . . . . . . . 223
6.2.8 Read Matrix from File (fscanfMat) . . . . . . . . . . . . . . . . . . 223
6.2.9 Is It A File (isfile) . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
6.2.10 Close a File Stream (mclose) . . . . . . . . . . . . . . . . . . . . . 224
6.2.11 Delete a File (mdelete) . . . . . . . . . . . . . . . . . . . . . . . . . 224
6.2.12 Check End of File (meof) . . . . . . . . . . . . . . . . . . . . . . . 224
6.2.13 Write Data to File (mfprintf) . . . . . . . . . . . . . . . . . . . . . 224
6.2.14 Read Data Stream (mfscanf) . . . . . . . . . . . . . . . . . . . . . 225
6.2.15 Read Line By Line (mgetl) . . . . . . . . . . . . . . . . . . . . . . 225
6.2.16 Open File Stream (mopen) . . . . . . . . . . . . . . . . . . . . . . 225
6.2.17 Move File (movefile) . . . . . . . . . . . . . . . . . . . . . . . . . . 226
6.2.18 Write Bytes to Stream (mput) . . . . . . . . . . . . . . . . . . . . 226
11
6.2.19 Current Position of Binary File (mseek) . . . . . . . . . . . . . . . 227
6.2.20 Length of Passed Data (mtell) . . . . . . . . . . . . . . . . . . . . 228
6.2.21 Environment (getenv) . . . . . . . . . . . . . . . . . . . . . . . . . 228
6.2.22 Process ID (getpid) . . . . . . . . . . . . . . . . . . . . . . . . . . 228
6.2.23 Stop Execution (halt) . . . . . . . . . . . . . . . . . . . . . . . . . 229
6.2.24 Prompt The Message (input) . . . . . . . . . . . . . . . . . . . . . 229
6.2.25 Read From a File (read) . . . . . . . . . . . . . . . . . . . . . . . . 229
6.2.26 Set Environment (setenv) . . . . . . . . . . . . . . . . . . . . . . . 229
6.2.27 Write Formatted Output to File (write) . . . . . . . . . . . . . . . 230
7 Strings 231
7.1 String Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
7.1.1 ASCII . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
7.1.2 Blanks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
7.1.3 Convret To String (convstr) . . . . . . . . . . . . . . . . . . . . . . 231
7.1.4 Empty String (emptystr) . . . . . . . . . . . . . . . . . . . . . . . 231
7.1.5 Evaluate (eval) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
7.1.6 Array Index (grep) . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
7.1.7 Is Argument Alphabets or Numeric (isalphanum) . . . . . . . . . . 232
7.1.8 Is Argument Digit (isdigit) . . . . . . . . . . . . . . . . . . . . . . 232
7.1.9 Is Argument Letter (isletter) . . . . . . . . . . . . . . . . . . . . . 233
7.1.10 Is Argument Number (isnum) . . . . . . . . . . . . . . . . . . . . . 233
7.1.11 Length of Object (length) . . . . . . . . . . . . . . . . . . . . . . . 233
7.1.12 Part of String (part) . . . . . . . . . . . . . . . . . . . . . . . . . . 234
7.2 String Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
7.2.1 Concatenate String (strcat) . . . . . . . . . . . . . . . . . . . . . . 235
7.2.2 First Character Matching (strchr) . . . . . . . . . . . . . . . . . . 236
7.2.3 Compare String (strcmp) . . . . . . . . . . . . . . . . . . . . . . . 236
7.2.4 Case Independent Comparing (strcmpi) . . . . . . . . . . . . . . . 237
7.2.5 Trim Blanks (stripblanks) . . . . . . . . . . . . . . . . . . . . . . . 237
7.2.6 Copy Specific Parts (strncpy) . . . . . . . . . . . . . . . . . . . . . 237
7.2.7 Sub-String From Reverse (strrchr) . . . . . . . . . . . . . . . . . . 238
7.2.8 Reverse String (strrev) . . . . . . . . . . . . . . . . . . . . . . . . . 238
7.2.9 Explode String (strsplit) . . . . . . . . . . . . . . . . . . . . . . . . 238
7.2.10 Locate Substring (strstr) . . . . . . . . . . . . . . . . . . . . . . . 239
7.2.11 String to Double (strtod) . . . . . . . . . . . . . . . . . . . . . . . 239
7.2.12 Tokenise Splitting (strtok) . . . . . . . . . . . . . . . . . . . . . . . 240
7.2.13 Position of Token (tokenpos) . . . . . . . . . . . . . . . . . . . . . 240
7.3 Data File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
7.3.1 CSV Default (csvDefault) . . . . . . . . . . . . . . . . . . . . . . . 240
7.3.2 CSV Write (csvWrite) . . . . . . . . . . . . . . . . . . . . . . . . . 241
7.3.3 CSV Read (csvRead) . . . . . . . . . . . . . . . . . . . . . . . . . . 241
7.3.4 Read Excel File (readxls) . . . . . . . . . . . . . . . . . . . . . . . 242
7.3.5 Scan CSV Test (csvTextScan) . . . . . . . . . . . . . . . . . . . . . 242
12
8 GUI 245
8.1 Graphics User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
8.1.1 Add To Menu (addmenu) . . . . . . . . . . . . . . . . . . . . . . . 245
8.1.2 Close Figure (close) . . . . . . . . . . . . . . . . . . . . . . . . . . 247
8.1.3 Delete From Menu (delmenu) . . . . . . . . . . . . . . . . . . . . . 247
8.1.4 Create Window (createWindow) . . . . . . . . . . . . . . . . . . . 247
8.1.5 GUI Controls (uicontrol) . . . . . . . . . . . . . . . . . . . . . . . 248
8.1.6 Open Directory (uigetdir) . . . . . . . . . . . . . . . . . . . . . . . 252
8.1.7 Get Color (uigetcolor) . . . . . . . . . . . . . . . . . . . . . . . . . 252
8.1.8 Create Figure (figure) . . . . . . . . . . . . . . . . . . . . . . . . . 253
8.1.9 Get Value (getvalue) . . . . . . . . . . . . . . . . . . . . . . . . . . 253
8.1.10 Message Box (messagebox) . . . . . . . . . . . . . . . . . . . . . . 255
8.1.11 Print Figure (printfigure) . . . . . . . . . . . . . . . . . . . . . . . 255
8.1.12 Progression Bar (progressionbar) . . . . . . . . . . . . . . . . . . . 255
8.1.13 Set Menu (setmenu) . . . . . . . . . . . . . . . . . . . . . . . . . . 256
8.1.14 Set Unset Toolbar (toolbar) . . . . . . . . . . . . . . . . . . . . . . 256
8.1.15 Un-Set Menu (unsetmenu) . . . . . . . . . . . . . . . . . . . . . . . 256
8.1.16 Create Node (uiCreateNode) . . . . . . . . . . . . . . . . . . . . . 256
8.1.17 Delete Node (uiDeleteNode) . . . . . . . . . . . . . . . . . . . . . . 257
8.1.18 Create Tree (uiCreateTree) . . . . . . . . . . . . . . . . . . . . . . 257
8.1.19 Concate Tree (uiConcatTree) . . . . . . . . . . . . . . . . . . . . . 259
8.1.20 Menu in Figure (uimenu) . . . . . . . . . . . . . . . . . . . . . . . 262
8.1.21 Display Tree (uiDisplayTree) . . . . . . . . . . . . . . . . . . . . . 263
8.1.22 File Open Dialog (uigetfile) . . . . . . . . . . . . . . . . . . . . . . 263
8.1.23 Item of Menu (uimenu) . . . . . . . . . . . . . . . . . . . . . . . . 263
8.1.24 Open File Box (uiputfile) . . . . . . . . . . . . . . . . . . . . . . . 264
8.1.25 Wait Bar (waitbar) . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
8.1.26 Choice Box (x choices) . . . . . . . . . . . . . . . . . . . . . . . . . 265
8.1.27 Input Dialog Box (x dialog) . . . . . . . . . . . . . . . . . . . . . . 265
8.1.28 Matrix Editing Window (x matrix) . . . . . . . . . . . . . . . . . . 266
8.1.29 Matrix Dialog Box (x mdialog) . . . . . . . . . . . . . . . . . . . . 266
9 Graphics 267
9.1 2D Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
9.1.1 Function Plot (plot) . . . . . . . . . . . . . . . . . . . . . . . . . . 267
9.1.2 New Axes (newaxes) . . . . . . . . . . . . . . . . . . . . . . . . . . 267
9.1.3 Line Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
9.1.4 Surface Plot (Sfgrayplot) . . . . . . . . . . . . . . . . . . . . . . . 269
9.1.5 Colour Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Colour Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Colour Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Get Colour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
9.1.6 Coloured Surface Plot (Sgrayplot) . . . . . . . . . . . . . . . . . . 273
9.1.7 Arrow Plot (champ) . . . . . . . . . . . . . . . . . . . . . . . . . . 273
9.1.8 Coloured Arrow Plot (champ1) . . . . . . . . . . . . . . . . . . . . 277
9.1.9 Comet Plot (comet) . . . . . . . . . . . . . . . . . . . . . . . . . . 278
9.1.10 2D Contours (contour2d) . . . . . . . . . . . . . . . . . . . . . . . 278
13
9.1.11 Filled Contour (contourf) . . . . . . . . . . . . . . . . . . . . . . . 283
9.1.12 Error Bar Plot (errbar) . . . . . . . . . . . . . . . . . . . . . . . . 284
9.1.13 Histogram (histplot) . . . . . . . . . . . . . . . . . . . . . . . . . . 285
9.1.14 Animated Parametric Plot (paramfplot2d) . . . . . . . . . . . . . . 287
9.1.15 2D Plot (plot2d) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
9.1.16 2D Step Plot (plot2d2) . . . . . . . . . . . . . . . . . . . . . . . . 290
9.1.17 2D Vertical Plot (plot2d3) . . . . . . . . . . . . . . . . . . . . . . . 291
9.1.18 2D Arrow Plot (plot2d4) . . . . . . . . . . . . . . . . . . . . . . . 292
9.1.19 Polar Plot (polarplot) . . . . . . . . . . . . . . . . . . . . . . . . . 293
9.2 3D Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
9.2.1 3D Function Plot (plot3d) . . . . . . . . . . . . . . . . . . . . . . . 295
9.2.2 3D Level Plot (plot3d1) . . . . . . . . . . . . . . . . . . . . . . . . 298
9.2.3 3D Rectangular Plot (plot3d2) . . . . . . . . . . . . . . . . . . . . 298
9.2.4 3D Surface Plot (plot3d3) . . . . . . . . . . . . . . . . . . . . . . . 298
9.2.5 3D Comet (comet3d) . . . . . . . . . . . . . . . . . . . . . . . . . . 298
9.2.6 3D Contours (contour) . . . . . . . . . . . . . . . . . . . . . . . . . 299
9.2.7 3D Histogram (hist3d) . . . . . . . . . . . . . . . . . . . . . . . . . 299
9.2.8 3D Parametric Plot (param3d) . . . . . . . . . . . . . . . . . . . . 300
9.3 Sub Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
9.4 Annotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
9.4.1 Captions (caption) . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
9.4.2 Legend (legend) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
9.4.3 Title (title) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
9.4.4 Axis Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
9.5 Bar Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
9.5.1 Vertical Bars (bar) . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
9.5.2 Horizontal Bars (barh) . . . . . . . . . . . . . . . . . . . . . . . . . 304
9.6 Geometric Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
9.6.1 Arcs (xarc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
9.6.2 Arrows (xarrows) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
9.6.3 Fill Arcs (xfarc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
9.6.4 Fill Rectangle (xfrect) . . . . . . . . . . . . . . . . . . . . . . . . . 307
9.6.5 Draw Rectangle (xrect) . . . . . . . . . . . . . . . . . . . . . . . . 307
9.7 Pie Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
9.7.1 Pie (pie) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
9.8 Polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
9.8.1 Fill Polygon (xfpoly) . . . . . . . . . . . . . . . . . . . . . . . . . . 309
9.9 Fetching Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
9.9.1 Get Current Figure (gcf) . . . . . . . . . . . . . . . . . . . . . . . 311
9.9.2 Set Current Figure (scf) . . . . . . . . . . . . . . . . . . . . . . . . 311
9.9.3 Delete Current Graphics (xdel) . . . . . . . . . . . . . . . . . . . . 311
9.9.4 Get Default Figure (gdf) . . . . . . . . . . . . . . . . . . . . . . . 312
9.9.5 Set Default Figure (sdf) . . . . . . . . . . . . . . . . . . . . . . . . 312
9.9.6 Get Current Axes (gca) . . . . . . . . . . . . . . . . . . . . . . . . 312
9.9.7 Get Default Axes (gda) . . . . . . . . . . . . . . . . . . . . . . . . 313
9.9.8 Set Default Axes (sda) . . . . . . . . . . . . . . . . . . . . . . . . . 313
9.9.9 Set As Current Axes (sca) . . . . . . . . . . . . . . . . . . . . . . . 313
14
9.9.10 Get Current Entity (gce) . . . . . . . . . . . . . . . . . . . . . . . 314
9.10 Property Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
9.10.1 Set Parameters (set) . . . . . . . . . . . . . . . . . . . . . . . . . . 315
9.10.2 Get Parameters (get) . . . . . . . . . . . . . . . . . . . . . . . . . 315
9.10.3 Move Entity (move) . . . . . . . . . . . . . . . . . . . . . . . . . . 315
9.10.4 Copy Entity (copy) . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
9.10.5 Reset Current Graphics (clf) . . . . . . . . . . . . . . . . . . . . . 316
9.10.6 Twinkle Graphics (twinkle) . . . . . . . . . . . . . . . . . . . . . . 316
Part I
Scilab
15
1.1. INTRODUCTION 17
1Scilab Core
In Scilab there are thousands of the ready-made keywords and functions. We will
discuss these keywords and function with suitable example(s).
1.1 Introduction
Scilab is a strong numerical programming software used for instructions to junior high
school students to graduate students. Scilab is written in ‘C’, ‘C++’ and ‘Java’ and its
applications are similar to the application of other languages. Unlike ‘C’ Scilab does not
required pre-definition of variable. Variables are automatically converted into integer,
character etc forms according to the values assigned to them, i.e. a value is assigned to a
variable by juggling. If a variable ‘a’ is being added with ‘2’ then the variable ‘a’ would be
considered as an integer type variable. But if it is to be added with ‘2.00202201220215’
then variable ‘a’ will be considered as an long type variable i.e. type of a variable is
considered as the use of it. Each statement performed internally should be terminated
by ‘;’. The statement whose result would be display in output window should not end
with ‘;’. Statements, strings and variables are grouped inside a parenthesis brackets, i.e.
‘(’ ... ‘)’. A syntax of a function can be spanned in multiple lines. When a part of syntax
is terminated by ‘..’, Scilab waits for remaining part of the syntax passed to it in second
line until syntax completion is not encountered.
✞
1 --> a=(
--> 1
3 --> 2
--> )
✌
✆
Execution of a function in multiline mode as shown above will produce errors while when
above function is modified as
✞
--> a=( ..
2 --> 1 ..
--> 2 ..
4 --> )
✌
✆
will be executed successfully and result will be
✞
ans =
12
✌
✆
Since Scilab 6, declaration of a number in two line is not supported as shown in above
example. According to the Code Conventions for the Scilab Programming Language it is
recommended:
1. Start each statement on a new line.
18 Scilab Core
2. Write no more than one simple statement per line.
3. Break compound statements over multiple lines.
Following example uses two integers 2, 3 & ‘;’ and prints their result at output window.
✞
--> a=2; // Without pre -identification of
2 --> // variable and terminated by ’;’
--> b=3; // Without pre -identification of
4 --> // variable and terminated by ’;’
--> a+b // Sum of two variables is called
6 --> // and line does not terminated by ’;’
✌
✆
✞
ans =
5.
✌
✆
If result of an operation is not assigned to a variable, then result is automatically assigned
to ‘ans’ variable.
1.1.1 Everything As Matrix
Numerical programming by Scilab is vector or matrix based computation, therefore each
variable has a vector or matrix values. Each element of a variable is identified by its
indices. For example,
✞
--> a = 2 // one dimensional vector
2 --> a = [1,2]
--> a(1) // first element of vector
✌
✆
✞
ans =
1
✌
✆
The indices parameters inside the parentheses of variable ‘a’ may be one dimensional, two
dimensional or three dimensional.
✞
--> a(1) // One dimensional
2 --> a(1, 2) // Two dimensional
--> a(1, 2, 1)// Three dimensional
✌
✆
In the first line of above codes, first element of vector a is returned. In second line of
above codes, element at 1st
row (x) and 2nd
column (y) is returned. In the third line of
above codes, elements at 1st
row (x), 2nd
column (y) and 1st
layer (z) is returned.
✞
1 --> a = [1,2,3;5,8,4]
--> a(2,2)
3 --> b = 56;
--> b(1) // First element
5 --> b(2) // Second element . Error!!!
✌
✆
1.1. INTRODUCTION 19
✞
a =
1. 2. 3.
5. 8. 4.
ans =
8.
ans =
56.
!--error 21
Invalid index.
✌
✆
1.1.2 Approximate Zero
Numerical programming languages use double datatype floating point arithmetic. There-
fore each number is denoted as a float value, i.e. 1 as 1.000000, 0.5 as 0.500000 etc.
Sometime, even zero is represented as 2.5 × 10−18
or as 13.2 × 10−19
etc. These values
are very very small and are close to zero. In floating point arithmetic, zero is taken as
comparative value rather than absolute value. For example, in numerical calculations,
identity matrix is represented as
1 3.5 × 10−12
35 × 10−12
1
where 1 is very large value in comparison to 3.5 × 10−12
or 35 × 10−12
.
1.1.3 Computational Error
Numerical software uses iteration to find the numeric solutions. For example, every one
knew that sin 90◦
is equal to one. But Numerical Software does not use fixed type values.
They uses series solutions, i.e. for sin θ, they uses sine series:
sin α = α −
α3
3!
+
α5
5!
− . . .
Here, α is in radian. This series is valid if infinite number of steps are taken for computa-
tion purpose. Computer does not take infinite terms of this series. It limits the number
of terms for computation. But, how many terms? If number of terms is less, result shall
be other than actual one but computational performance shall be good. And if number of
steps is large then result shall be near accurate value but performance shall be compro-
mised. Now, the question is that, how many steps shall be taken in this series. It depends
on the required significant digits in the result. At the optimal result, the deviation of
computed value from the actual one is called computational error. For the above series,
we shall compute value for three terms and four terms, and corresponding results shall
be compared.
For Three Terms
sin
π
2

=
22
14
−
22
14
3
3!
+
22
14
5
5!
20 Scilab Core
Or
sin
π
2

= 1.5714286 − 0.6467444 + 0.0798531
It gives sin 90◦
= 1.0045373.
For Four Terms
sin
π
2

=
22
14
−
22
14
3
3!
+
22
14
5
5!
−
22
14
7
7!
Or
sin
π
2

= 1.5714286 − 0.6467444 + 0.0798531 − 0.0046950
It gives sin 90◦
= 0.9998423. It is seen here, the value oscillates about one as the number
of terms increases and tends to one when number of terms are infinite. Numerical Software
use sufficient long steps so that result is near to accurate result or upto desired significant
digits. Now, computational error is difference between exact value of sin 90◦
and computed
value. In first case computational error is 1 − 1.0045373, i.e. −0.0045373 and in second
case, computational error is 1 − 0.9998423, i.e. 0.0001577.
Error In Calculus In calculus, definite integration of a function is carried out by two
ways. (i) By using first principle method and (ii) By using direct method. For example,
I =
Z 1
0
x dx
may be solved by two ways. In first method, take dx = 0.1. It gives,
n =
b − a
dx
= 10
and x are computed by a + n × dx where a is lower limit of integration.
I = 0 × 0.1 + 0.1 × 0.1 + . . . + 0.8 × 0.1 + 0.9 × 0.1
On solving it, we have
I = 0 + 0.01 + 0.02 + 0.03 + 0.04 + 0.05 + 0.06 + 0.07 + 0.08 + 0.09 = 0.45
From direct method,
I =
Z 1
0
x dx =
x2
2
1
0
= 0.5
Now, the computational error by two methods is 0.50 − 0.45 = 0.05. So, computational
errors, not only occur due to selection of number of steps but they also occur when we
select different types of solution methods.
1.2 Simple Arithmetic
Before we start the expertise application of Scilab in numerical programming, we first be
hands out with simple mathematical applications like addition, subtraction, multiplica-
tion, division, scoping and application of inbuilt functions.
1.2. SIMPLE ARITHMETIC 21
1.2.1 Addition
Arithmetic addition is the summation of two or more numbers. Scilab obeys the simple
arithmetic rules of addition. In the following example, two variables are declared and
assigned some values. When we called addition by variable method, we got desired
result. Remember, to print the result of a step of operation, it shall not terminated with
‘;’ (semi-colon). If you do so, the result shall be assigned to default answer variable ans
without displaying it in output console.
✞
-- a=10;
2 -- b=10;
-- a+b
✌
✆
✞
ans =
20.
✌
✆
The default output in Scilab is a float or a double. A float number has fraction parts,
i.e. fraction part succeed to decimal symbol (.). Numbers without (.) are pure integers.
int8(x) converts a float or double number (x) into integer number by truncating its fraction
part.
✞
-- a=10.5;
2 -- b=10.3;
-- int8 (a+b)
✌
✆
✞
ans =
20
✌
✆
We can make symbolic addition of two numbers too. But before doing so, string or
characters are defined as variable by using poly function of zero order. The first argument
of poly function is degree of equation and ‘b’ is symbolic variable.
✞
-- a=10;
2 -- // poly (degree of eqn ,symbol )
-- b=poly (0,’b’);
4 -- a+b
✌
✆
✞
ans =
b + 10
✌
✆
sum function does not takes inputs to be summed, but it accepts a vector or matrix as
its argument. It adds vector elements or elements of a matrix cumulatively. Elements of
vector or matrix are constructed by using ‘:’ (colon) loop operator twice. First argument
of colon loop is initial limit of the array, second argument is iteration step increment after
a loop and third argument is upper limit of the array.
✞
-- a=1:1:5
✌
✆
22 Scilab Core
✞
ans =
1. 2. 3. 4. 5.
✌
✆
The sum of array elements
✞
-- a=1:1:10;
2 -- sum(a)
✌
✆
✞
ans =
55
✌
✆
abs function is used to return the absolute value of a number x. When x is complex,
abs(x) is the complex modulus (magnitude) of the elements of x. Mathematically
abs(x) = |x|
1.2.2 Subtraction
Arithmetic subtraction is the difference of two or more numbers. In standard form of
subtraction, second operand is subtracted from first operand of subtraction operator (–
). The result may be positive or negative. If there are several consecutive subtraction
without scope operators then LEFT-TO-RIGHT order of subtraction is followed.
✞
-- a=10;
2 -- b=10;
-- c=10;
4 -- a-b-c
✌
✆
✞
ans =
-10.
✌
✆
We can also make symbolic subtraction of two numbers similar to the symbolic addition
as explained above.
✞
-- a=10;
2 -- // poly (degree of eqn , symbol )
-- b=poly (0,’b’);
4 -- a-b
✌
✆
✞
ans =
-b + 10
✌
✆
1.2.3 Multiplication
Arithmetic multiplication in Scilab is performed by asterisk operator (*). If there are
several consecutive multiplication without scope operators then LEFT-TO-RIGHT order
of multiplication is followed.
1.2. SIMPLE ARITHMETIC 23
✞
-- 2*3*4*5
✌
✆
✞
ans =
120.
✌
✆
Cumulative array product of array elements can be performed by prod() function. See
the example given below:
✞
-- a=1:1:10;
2 -- prod (a)
✌
✆
✞
ans =
3628800.
✌
✆
1.2.4 Division
Arithmetic division in Scilab is denoted by forward slash.
✞
-- 2/3
✌
✆
✞
ans =
0.6666667
✌
✆
The answer is in ten digit form. We can control the decimal places by using the function
format() function by supplying format code and number of fraction digits as its arguments.
✞
-- format(’v’ ,4)
✌
✆
Where ‘v’ is abbreviation of ‘variable’ and integer 4 controls the number of digits in
answer. It does also meant that, the fourth digit shall also be rounded up.
✞
1 -- format(’v’ ,4)
-- 2/3
✌
✆
✞
ans =
0.7
✌
✆
Changing the format of numbers kept in effective until Scilab session is not reset or it is
not restarted.
1.2.5 Scoping
The simple arithmetic, withing same scoping/grouping is performed according to BOD-
MAS rule. It is an acronym for Bracket, Of, Division, Multiplication, Addition and
24 Scilab Core
Subtraction. Mathematical grouping is very essential to set the procedure of arithmetic
operations. For example
1
2
2
= 0.4
But
1
2
2
= 1
Simple use of forward slash as divisor we can’t identify the numerator and denominator
of a rational number or of a fractions. Same fractions represented in different way have
different answers. This is why in Scilab, scoping/grouping of variables becomes necessary.
If scoping/grouping is not in correct form the answer is unpredictable. For example,
withough scoping then division of unity by two is
✞
-- 1/2
✌
✆
✞
ans =
0.5
✌
✆
And division of half by two is
✞
-- 1/2/2
✌
✆
✞
ans =
0.25
✌
✆
Now division of half by half is
✞
-- 1/2/1/2
✌
✆
✞
ans =
0.25
✌
✆
It is not required answer as half divided by half must be unity. By scoping each fraction
according to our requirement, we have correct answer.
✞
-- (1/2) /(1/2)
✌
✆
✞
ans =
1
✌
✆
1.2.6 Square Root (sqrt)
If x is a real number then its square root is given by y =
√
x. In other words, if y is
square root of x, then y2
= x. Roots computed by this function may be real or complex.
Square root of negative numbers returned in complex form. In Scilab, square root is a
scalar operator and it performs elementwise operation. Square root of a number can be
obtained by
1.2. SIMPLE ARITHMETIC 25
✞
-- sqrt (2)
✌
✆
✞
ans =
1.414
✌
✆
If argument is a vector, then square root of the vector is a vector of square root of its
elements. If argument is a matrix then square root of the matrix is a matrix of square
roots of its elements.
✞
-- a=[1 ,2;3 ,4];
2 -- sqrt (a)
✌
✆
✞
ans =
1. 1.4142136
1.7320508 2.
✌
✆
The algorithm used in computation of the square root of a real value, x, is
√
x = e
ln(x)
2
1.2.7 Exponent (ˆ Operator)
ˆ is called exponent operator. If n is an index or a degree, or power of base x then
exponents is represented by xn
. If |n| ≥ 1, then exponent means “base is multiplied by
itself n times”, and if |n|  1, then it is called nth
root of base x. To find the kth
root of
base number x, we use ˆ operator as xk
.
✞
1 -- 2^(0.33)
✌
✆
✞
ans =
1.2570134
✌
✆
The output of exponents depends on the values of base and exponent. For example,
if either base x or exponent n is less than one, then result is convergent, i.e. result is
approaching towards zero. Similarly, if both base x and exponent n are greater than one
then result is divergent. If n is one, then result is always base x itself. If base x is one
and n is whatever value, then result is always one. If exponent is a complex then it is
solved by using logarithm with natural base (e). For example, y = 2i
is simplified as
log y = log 2i
It gives
log y = i log 2 ⇒ y = ei log 2
Now, we can simplify right side using relation eiθ
= cos θ + i sin θ as
y = cos(log 2) + i sin(log 2)
26 Scilab Core
Note that, ˆ acts like both, scalar and vector operator with vectors and matrices. If it is
used like ‘.ˆ’ then it acts as elementwise operator and if it is used without dot, then it
acts as vector operator.
✞
-- a=[1 ,2;3 ,4];
2 -- a^(0.33) // vector operator
✌
✆
✞
ans =
0.6956785 + 0.4728372 i 0.4784401 - 0.2162886 i
0.7176602 - 0.3244328 i 1.4133387 + 0.1484044 i
✌
✆
✞
1 -- a=[1 ,2;3 ,4];
-- a.^(0.33) // scalar operator
✌
✆
✞
ans =
1. 1.2570134
1.4369777 1.5800826
✌
✆
The algorithm used for computation of exponent is explained here. Assume a matrix of
order 2 × 2
A =

1 2
3 4

Now its eigenvalues are given by |A − λI| = 0 i.e.
1 2
3 4

− λ

1 0
0 1
= 0
Or
1 − λ 2
3 4 − λ
= 0
Or
(1 − λ) × (4 − λ) − 6 = 0
On solving it
λ = −0.372281; 5.372281
Or eigenvalues in matrix form, when they are arranged in descending order is
d =

5.372281 0.000000
0.000000 −0.372281

For λ = 5.372281, eigenvector (v1) is (A − λI)v1 = 0. So,

1 − 5.372281 2
3 4 − 5.372281
 
x
y

= 0

−4.372281 2
3 −1.372281
 
x
y

= 0
1.2. SIMPLE ARITHMETIC 27
Or
−4.372281x + 2y = 0; 3x − 1.372281y = 0
To get solutions, put x = 1 in −4.372281x + 2y = 0, we get the value of y = 2.186140.
To get eigenvectors, we shall normalize these two values as
x =
1
√
12 + 2.1861402
; y =
2.186140
√
12 + 2.1861402
It gives, x = 0.415973 and y = 0.909376. As coefficients of above two eigenvector equa-
tions are of opposite signs, hence values of x and y shall be either both negative or both
positive. Now, we shall submit x and y values in equation g = 3x − 1.372281y to get
minimum positive value.
g = 3 × 0.415973 − 1.372281 × 0.909376 = 0.000000407
Taking sign convention, the other possible set of solution be x = −0.415973 and y =
−0.909376.
g = 3 × −0.415973 − 1.372281 × −0.909376 = 0.000000407
When x = −0.415973 and y = −0.909376, we have positive f value. This gives first
eigenvector corresponding to λ = 5.372281.
v1 =

−0.415973
−0.909376

For λ = −0.372281, eigenvector (v2) is (A − λI)v2 = 0. So,

1 − (−0.372281) 2
3 4 − (−0.372281)
 
x
y

= 0

1.372281 2
3 4.372281
 
x
y

= 0
Or
1.372281x + 2y = 0; 3x + 4.372281y = 0
As coefficients of above two eigenvector equations are of same signs, hence values of x
and y shall be in opposite signs. On solving these two algebraic equations, as explained
for λ = 5.372281, we have x = −0.824564 and y = 0.565767 or x = 0.824564 and
y = −0.565767. This gives second eigenvector corresponding to λ = −0.372281.
v2 =

−0.824564
0.565767

The corresponding eigenvector matrix from above two eigenvectors (v1 and v2) is
v =

−0.415973 −0.824564
−0.909376 0.565767

Note that, each column of eignevectors is arranged to the corresponding eigenvalues. Now,
the matrix A can be written as A = v × d × v−1
. The square root of the matrix is given
by
A
1
2 = v × d
1
2 × v−1
28 Scilab Core
1.2.8 Algebraic Equations
Algebraic equations are those equations in which an unknown variable is in linear addition
or in linear subtraction in different degrees. Numerical coefficients are multiplied with
each terms to give a suitable relation for the unknown variable. To form a linear equation,
first define the variable.
✞
1 -- x=poly (0,’x’);
-- f=2*x^2+2
✌
✆
f =
2 + 2x2
This algebraic equation is in symbolic form. All the algebraic function may be applicable
to this equation. In the following example, function roots() is used to algebraic equation
f to gets its all roots.
✞
-- x=poly (0,’x’);
2 -- f=2*x ^2+2;
-- roots(f)
✌
✆
✞
ans =
i
- i
✌
✆
Division of polynomials by a number or by a symbol can also be performed. Note that it
returns only quotient of the division.
✞
1 -- x=poly (0,’x’);// returns only degree 1 polynomial
-- f=2*x ^2+2;
3 -- pdiv (f,x),
✌
✆
✞
ans =
2x
✌
✆
LCM (Least Common Multiplier) and HCF (Highest Common Factor) of two algebraic
functions can also applicable with the algebraic equations.
✞
-- x=poly (0,’x’);
2 -- f=2*x ^2+2;
-- lcm([f,x])
✌
✆
✞
ans =
3
2x + 2x
✌
✆
1.2. SIMPLE ARITHMETIC 29
In Scilab, HCF is named as GCD (Greatest Common Divisor).
✞
1 -- x=poly (0,’x’);
-- f=2*x ^2+2;
3 -- gcd([f,x])
✌
✆
✞
ans =
1
✌
✆
1.2.9 Logarithm
The natural logarithm of number 2 is obtained when this number is supplied as argument
to the log function.
✞
-- log (2)
✌
✆
✞
ans =
0.6931472
✌
✆
Exponential to a number (n) is represented mathematically as en
. In Scilab, it is given
as
✞
-- exp (2)
✌
✆
✞
ans =
7.3890561
✌
✆
We may use different bases for logarithms, i.e. base ‘10’, base ‘2’ or natural base ‘e’.
Logarithm of a number about base ‘10’ is computed as
✞
-- log10 (2)
✌
✆
✞
ans =
0.30103
✌
✆
Solved Problem 1.1 Write Scilab code for finding of natural and base ten logarithm of
number 2.05 and find their difference.
Solution The Scilab codes for the given problem is given below:
✞
-- log (2.05) -log10 (2.05)
✌
✆
✞
ans =
0.4060859
✌
✆
This is output of the given problem.
30 Scilab Core
1.2.10 Index Expression
An index expression allows to scale, select or replace an element from a vector or matrix.
Indices may be scalars, vectors, ranges, or the special operator ‘:’, which may be used to
select entire rows or columns. Row and column indices, i.e. two parameters, are separated
by comma.
✞
-- A(row indices , column indices )
✌
✆
When only one parameter is passed to matrix variable to extract the sub matrix, then at
first, matrix is arranged in vector form in sequence of column vectors. For example,
✞
1 -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3]
-- A(:)
✌
✆
✞
A =
2 3 1 4
5 3 1 8
8 6 7 2
4 5 1 3
ans =
2
5
8
4
3
3
6
5
1
1
7
1
4
8
2
3
✌
✆
Now, only one parameter is supplied to vector variable, it is treated as indices for elements
and it returns a vector of elements present at that indice. Note that, here index counting
started from 1 rather than 0.
✞
-- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3]
2 -- A(2) // element at index 2
✌
✆
✞
A =
2 3 1 4
5 3 1 8
8 6 7 2
4 5 1 3
1.2. SIMPLE ARITHMETIC 31
ans =
5
✌
✆
Similarly, a range of indices can be given to matrix variable to extract a vector of elements
present at that index. In the following example, sub vectors are returned by constructing
elements present at indices from index 1 to index 2. There are two different way to pass
same indices.
✞
1 -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3]
-- A(1:2) // 1st index to 2nd index
3 -- A([1;2]) // 1st index and 2nd index
✌
✆
✞
A =
2 3 1 4
5 3 1 8
8 6 7 2
4 5 1 3
ans =
2
5
ans =
2
5
✌
✆
When both parameters are passed to matrix variable, then first parameter is indices for
rows and second parameter is for columns. Rows or columns may be discrete indices or
range of indices but should not beyond the dimension of the matrix. In this case, matrix
is not arranged in sequeces of elements of column vectors. See the below example.
✞
1 -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3]
-- A(2:4 ,3:4) // Row index from 2nd row to 4th row
3 // col index from 3rd col to 4th col
✌
✆
✞
A =
2 3 1 4
5 3 1 8
8 6 7 2
4 5 1 3
ans =
1 8
7 2
1 3
✌
✆
If both parameters are discrete indices, then row index are recursive for all column indices.
See the following example, in which elements at second and third column of first row, and
elements at second and third column of fourth row forms a sub matrix.
✞
1 -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3]
-- A([1,4], [2 ,3])// 1st row - 2nd  3rd columns
3 // 4th row - 2nd  3rd columns
✌
✆
32 Scilab Core
✞
A =
2 3 1 4
5 3 1 8
8 6 7 2
4 5 1 3
ans =
3 1
5 1
✌
✆
If same index number is used twice or more in row parameter, i.e. as [1,1], then output
sub matrix has two rows as part of row index ‘1’ of the given matrix.
✞
-- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3]
2 -- A([1,1], [2 ,3])// 1st row - 2nd  3rd columns
// 1th row - 2nd  3rd columns
✌
✆
✞
A =
2 3 1 4
5 3 1 8
8 6 7 2
4 5 1 3
ans =
3 1
3 1
✌
✆
end operator is used to denote last index of the vector. For example
✞
-- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3]
2 -- A(end)// last element of vector
✌
✆
✞
A =
2 3 1 4
5 3 1 8
8 6 7 2
4 5 1 3
ans =
3
✌
✆
The parameter of matrix variable may be controlled by range indices. For example, odd
elements of matrix and even elements of matrix can be extracted by
✞
1 -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3]
-- A(1:2: end) // Odd elements vector
3 -- A(2:2: end) // Even elements vector
✌
✆
✞
A =
2 3 1 4
5 3 1 8
1.3. ARITHMETICAL KEYWORDS 33
8 6 7 2
4 5 1 3
ans =
2 8 3 6 1 7 4 2
ans =
5 4 3 5 1 1 8 3
✌
✆
1.3 Arithmetical Keywords
Followings are the main keywords used in Scilab. The key by key explanation is given
below.
1.3.1 Result Variable (ans)
ans means “answer”. This variable is created automatically when expressions are not
assigned to any other variable. It is the last un-assigned evaluated value.
✞
1 -- a=10;
-- b=5;
3 -- a+b
✌
✆
✞
ans =
15
✌
✆
1.3.2 Left Matrix Division ()
‘’ is used for left matrix division. Let A ∗ x = b has a solution of x = Ab. In this
expression, succeeding variable to ‘’ is divided by the preceding one.
✞
-- a=10;
2 -- b=5;
-- ab
✌
✆
✞
ans =
0.5
✌
✆
The second example of the backslash command is
✞
-- A=2;
2 -- b=[1;1;1];
-- x=Ab
✌
✆
✞
x =
0.5
0.5
0.5
✌
✆
34 Scilab Core
1.3.3 Square Brackets ([...])
Square brackets are used to define a vector or a matrix. Each row of a vector or matrix
is separated by ‘;’ and each element of a row is separated by ‘,’ (comma) or space.
✞
-- x=[1;2;3]
✌
✆
✞
x =
1
2
3
✌
✆
A 3 × 3 matrix is written as
✞
-- x=[1 ,2 ,3;4 ,5 ,6;7 ,8 ,9]
✌
✆
✞
x =
1 2 3
4 5 6
7 8 9
✌
✆
In a row matrix or in a column matrix, elements of the row or matrix may be numbers or
function. The elements may be separated by comma or space. In otherwords, functions
may be part of the matrix elements. The exact element value of function element is its
return value.
✞
-- x=[1 sqrt (-1) 2 -sqrt (-1) 3]
✌
✆
✞
x =
1. i 2. - i 3.
✌
✆
Elements of a vector may contains text or strings too. See the following Scilab codes.
✞
-- [’This is’;’string’;’matrix’]
✌
✆
✞
ans =
!This is !
! !
!string !
! !
!matrix !
✌
✆
A new row of a matrix can also be started by adding row elements in new line.
✞
-- mat = [
2 Row A1
Row B1
4 Row C1
Row D1
6 ]
✌
✆
1.3. ARITHMETICAL KEYWORDS 35
Consistency of columns for each rows should be maintained to avoid the row/cols consis-
tence error. Following example gives error.
✞
-- mat = [
2 Row A1,Row A2
Row B1,
4 Row C1
Row D1
6 ]
✌
✆
While this example will give a matrix of four rows and two columns.
✞
-- mat = [
2 Row A1,Row A2
Row B1,Row B2
4 Row C1,Row C2
Row D1,Row D2
6 ]
✌
✆
1.3.4 Element-Wise Operation
Element-wise operation is performed on each element of a supplied argument to a function.
The structural properties of the supplied arguments are not considered. For example,
A = [1] is a scalar while B = [1, 4] is a vector/matrix but in element wise operations,
both are considered as scalars. It means only elements are meaningful in elementwise
operation while structures of A and B are ignored.
1.3.5 Matrix-Wise Operation
In matrix-wise operation, elements are accepted as element of a matrix and their result
is put in the similar matrix form in output window.
1.3.6 Colon (Range Operator)
This operator (:) is used to define a range of variable. Normally, it creates a vector/set
of elements. It is used by two ways.
✞
-- ll : ul
2 -- ll : inc : ul
✌
✆
Increment may be a positive value, or a negative value. If it is positive value then range
is in ascending order, if it is negative value then range is in descending order. In first
method of application, initial and final values are declared by user and suitable increment
value is selected by Scilab itself. By default increment is ‘1’.
✞
-- a = 1:10
✌
✆
36 Scilab Core
✞
a =
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
✌
✆
✞
-- a = 1:-10
✌
✆
✞
a =
[]
✌
✆
In second method of application (i.e. more than one colons (:) are used) first element
is initial value, second element is increment and third element is the upper level limit of
range. The last value of range does not exceed to the upper limit. After each increment,
initial value becomes equal to the sum of initial value and increment. This iteration is
followed until it becomes equal or more than the finale range of iteration.
✞
-- a = 1:2:10
✌
✆
✞
a =
1. 3. 5. 7. 9.
✌
✆
✞
-- a = 1:-2:-10
✌
✆
✞
a =
1. - 1. - 3. - 5. - 7. - 9.
✌
✆
The colon can be used for defining a rang into a matrix form. Each argument of this
function is comma separated. First argument is matrix range, second argument is number
of rows and third argument is the number of columns.
✞
-- a = matrix (1:12 ,6 ,2)
2 -- a
✌
✆
✞
a =
1. 7.
2. 8.
3. 9.
4. 10.
5. 11.
6. 12.
✌
✆
Elements of a matrix are retrieved by calling the matrix object as shown below:
✞
1 -- a(:)
✌
✆
1.3. ARITHMETICAL KEYWORDS 37
✞
ans =
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
✌
✆
The specific columns of matrices can be accessed by using first argument as colon symbol
and second argument as column index. See the example below:
✞
1 -- a = matrix (1:12 ,6 ,2)
-- b=a(:,1) //1 = first column
3 -- c=a(:,2) //2 = second column
✌
✆
✞
a =
1. 7.
2. 8.
3. 9.
4. 10.
5. 11.
6. 12.
b =
1.
2.
3.
4.
5.
6.
c =
7.
8.
9.
10.
11.
12.
✌
✆
We can use row or column index vectors for accessing multiple rows or columns.
✞
1 -- m=[1 ,2 ,3;4 ,5 ,6;7 ,8 ,9]
-- m(: ,[1 ,2]) // for multiple column indices
✌
✆
✞
m =
38 Scilab Core
1. 2. 3.
4. 5. 6.
7. 8. 9.
ans =
1. 2.
4. 5.
7. 8.
✌
✆
Specific rows can be retrieved if argument location of range operator and index number
is interchanged as given in following code snippets.
✞
-- a = matrix (1:12 ,6 ,2)
2 -- b=a(1,:) //1 = first row
-- c=a(5,:) //2 = fifth row
✌
✆
✞
a =
1. 7.
2. 8.
3. 9.
4. 10.
5. 11.
6. 12.
b =
1. 7.
c =
5. 11.
✌
✆
A single colon as argument to matrix handle means full range of the matrix elements.
We can limit the range operator (:) for specific indices if colon is used as incremental
operator.
✞
1 -- (initial limit  : increments /decrements  : final limit )
✌
✆
There is an increment or decrement, it is depends on the sign of increment/decrement
(second element in the range operator). Increments is always a positive integer and
decrements is always a negative integer. For example
✞
1 -- a(12: -3:1)
✌
✆
✞
a =
12.
9.
6.
3.
✌
✆
✞
1 -- a(1:2:10)
✌
✆
1.3. ARITHMETICAL KEYWORDS 39
✞
a =
1.
3.
5.
7.
9.
✌
✆
We can extract a part of matrix by using colon operator within parentheses as shown in
below example.
✞
-- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3]
2 -- A(2:4 ,3:4) //A(row range , col range )
✌
✆
✞
A =
2 3 1 4
5 3 1 8
8 6 7 2
ans =
1 8
7 2
1 3
✌
✆
We can use the colon operator to print integer numbers from 0 to n with special purposes.
In the following example, n is restricted to 5, i.e. integers from 0 to 5 are printed in output.
✞
-- %i : 5
✌
✆
✞
ans =
0. 1. 2. 3. 4. 5.
✌
✆
This method of implementation is removed since Scilab 6.0 version.
1.3.7 Comma
Comma operator (,) is used as the identifier for column, instruction and used as argument
separator. A 3 × 3 matrix is represented in vector form as
✞
-- [1,2,3;4,5,6;7,8,9]
✌
✆
✞
x =
1 2 3
4 5 6
7 8 9
✌
✆
Space operator “ ” is also used as separator of the elements in a row of the matrix.
40 Scilab Core
1.3.8 Comments
Comments are the statements which explains to mathematical operations, numerical cal-
culations and special functions. Comments are embedded within the program codes. The
comments are never executed by the Scilab and they are simply skipped by the Scilab.
Symbol ‘//’ is used for the commenting of a line.
✞
-- a=5;
2 -- b=10;
-- a+b // summation of two variable .
✌
✆
✞
ans =
15
✌
✆
1.3.9 Dot
Dot symbol is used to represent the end of a sentence or the decimal fraction. It is also
used for element-wise dot product (.*) of two vectors or matrices. If A = aij and B = bij
are two matrices of n × n size then
[A · ∗B]ij = aij × bij
It is always true that [A ∗ B] = [B ∗ A]. If, A and B are 2 × 2 matrices as given by
A =

1 2
3 2

; B =

2 1
3 4

Then
C = A · ∗B =

1 × 2 2 × 1
3 × 3 2 × 4

=

2 2
9 8

✞
-- a=[1 ,2;3 ,2];
2 -- b=[2 ,1;3 ,4];
-- a.*b
✌
✆
✞
ans =
2. 2.
9. 8.
✌
✆
1.3.10 Empty
An empty vector or an empty matrix is represented by ‘[]’. Empty square brackets
represent to the empty set of matrix. White spaces inside the square brackets do not
affect the meaning of empty matrix.
✞
1 -- []
-- [ ]
✌
✆
1.3. ARITHMETICAL KEYWORDS 41
✞
ans =
[]
ans =
[]
✌
✆
1.3.11 Equal Sign
Equal operator (==) compares two values numerically and returns the ‘true’ if both
values are equal otherwise returns ‘false’. Remember that symbol ‘=’ is not same as to
‘==’. Symbol ‘=’ assigns a value to a variable while ‘==’ compares two values.
✞
-- i = 5;
2 -- j = 10;
-- if(i==j)
4 -- disp (E);
-- elseif(ij)
6 -- disp (N);
-- end
✌
✆
✞
N
✌
✆
1.3.12 global
It declares a variable as a global variable. The variable defined global can be called from
everywhere.
1.3.13 Hat Symbol
It (ˆ) represents to the exponent, i.e. bn
. It raises base (number at the left side to the
hat) to the power of n (number at the right side to the hat). It is also sometime refers as
power.
✞
1 -- 2^4
✌
✆
✞
ans =
16
✌
✆
Hat symbol (ˆ) can be also used to find the nth
root of a number.
✞
-- x^(1/ n)
✌
✆
✞
1 -- 2^(1/4)
✌
✆
✞
ans =
1.1892071
✌
✆
42 Scilab Core
1.3.14 Less Than
() is a comparative operator. It tells that the left hand value is lesser than the right
hand value. If left hand side value is less than the right hand side, then comparison is
true otherwise false. It returns “yes” on true state and “no” in false state.
✞
-- if (12)
2 -- disp (yes);
-- end
✌
✆
✞
ans =
yes
✌
✆
1.3.15 Minus
(–) sign is used to subtract right hand value from the left hand value. Subtraction is
algebraic. If right hand value is larger than left hand value then result is negative.
✞
-- 2-3
✌
✆
✞
ans =
-1
✌
✆
The two variables using minus may be a vector or a matrix. In case of vectors, subraction
takes place element-wise. Subtraction of vectors is a vector of similar size.
✞
-- [1 ,2] -[3 ,4]
✌
✆
✞
ans =
-2. -2.
✌
✆
In vector subtraction, size of two vectors must be equal.
1.3.16 Not
Symbol, ∼, is a logical NOT operator. It compares the two values and access them
according “value a is not equal to value b”. If the comparison is true according to this
statement, then it returns true otherwise it returns false.
✞
-- 2 ~= 3 //2 is not equal to 3.
✌
✆
✞
ans =
T
✌
✆
1.3. ARITHMETICAL KEYWORDS 43
1.3.17 Parenthesis
Parenthesis, i.e. ‘(...)’ brackets are used to group the statements, operations  executions.
A variable or function initiated inside the parenthesis has local scope.
1.3.18 Percent
(%) is a special character. When it is prepend to string, literals are considered as with
special meaning as shown in the following table.
Symbol Meaning
%pi π
%i:n Integer from 0 to n
%i
√
−1
The functions whose names begin with % character are special functions. They are
used as primitives and used in operator’s overloading.
1.3.19 Plus
(+) is an addition operator. It returns sum of two or more values. It also concatenates
two or more strings. Its operands may be vectors, scalars or strings.
✞
-- 2+3
2 -- This is my + country .
✌
✆
✞
ans =
5
ans =
This is mycountry .
✌
✆
The two variables may be a vector or a matrices. In case of vector operands, addition
takes place element-by-element wise.
✞
--[1,2]+[3,4]
✌
✆
✞
ans =
4. 6.
✌
✆
In vector subtraction, size of two vectors must be equal.
1.3.20 Quote
There are two types of quotes, called single quotes (’) and double quotes (”). In Scilab,
single quotes and double quotes have different meaning. The contents written between
single quotes or double quotes are considered as strings. See the following example:
44 Scilab Core
✞
-- x = ‘The Good Boy ’
2 -- y = The Good Boy
✌
✆
✞
x =
The Good Boy
y =
The Good Boy
✌
✆
Single quote is also used as string delimiter (”), i.e. string within string. As string
delimiter, the single quote is used in a group of twice.
✞
-- x = ‘disp (‘‘Boy ’’)’
2 -- y = disp (‘‘Boy ’’)
-- z = disp (‘‘disp (‘‘disp (‘‘Boy ’’) ’’) ’’)
✌
✆
✞
x =
disp (‘Boy ’)
y =
disp (‘Boy ’)
z =
disp (‘disp (‘disp (‘Boy ’) ’) ’)
✌
✆
Single quote is also used in mathematics, specially in matrix. If a matrix is real matrix
then single quotes converts row vector into column vector and vice-versa. See the example
given below:
✞
-- a=[1 ,2]
2 -- a’
✌
✆
✞
a =
1. 2.
ans =
1.
2.
✌
✆
If matrix is a complex matrix then (’) is a complex conjugate transpose operator. It is
used in a matrix for conjugate transpose of the matrix. It is also used as string delimiter.
Assume a complex matrix of order 2 × 2 as
A =

1 + i 2
3 2 + i

Conjugate transpose of this matrix (A) will be
A =

1 − i 3
2 2 − i
1.3. ARITHMETICAL KEYWORDS 45
✞
1 -- [1+%i , 2; 3, 2+%i]’
✌
✆
✞
ans =
1. - i 3.
2. 2. - i
✌
✆
If a dot (.) is applied before (’), then the matrix transpose is called non-conjugate
transpose of matrix. Assume a complex matrix of order 2 × 2 as
A =

3 + i 2
1 2 + i

Then non-conjugate transpose of the matrix will be
A =

3 + i 1
2 2 + i

✞
1 -- [1+%i ,2; 3,2+ %i].’
✌
✆
✞
ans =
1. + i 3
2. 2. + i
✌
✆
1.3.21 Return
return assigns local variables to the calling variable.
✞
1 -- [a,b]= return (1,2)
✌
✆
✞
b =
2.
a =
1.
✌
✆
It is also used to return a value from inside of a function. A function is terminated in
execution, when keyword return is encountered.
✞
-- function [y]= myFunc(i, j)
2 -- y=i+j;
-- return 0;
4 -- y=i^j; // Not executed
-- endfunction
6 -- myFunc (2, 3)
✌
✆
✞
ans =
5.
✌
✆
46 Scilab Core
✞
-- function [y]= myFunc(i, j)
2 -- y=i+j;
-- // return 0;
4 -- y=i^j; // Executed and overloaded
-- // to previous result
6 -- endfunction
-- myFunc (2, 3)
✌
✆
✞
ans =
8.
✌
✆
1.3.22 Semicolon
Semicolon ‘;’ is used as a row separator in a matrix. It is also used to end a statement
line. Application of semicolon as a row separator is shown below:
✞
-- [1,2,3;4,5,6;7,8,9]
✌
✆
✞
x =
1 2 3
4 5 6
7 8 9
✌
✆
Application of semicolon as a end of line is shown in the following example.
✞
-- i = 5; // end of first line
2 -- j = 10; // end of second line
-- if(ij)
4 -- disp (L);
-- elseif(ij)
6 -- disp (G);
-- elseif(i==j)
8 -- disp (E);
-- end
✌
✆
✞
L
✌
✆
End-of-line application of semicolon (;) does not mean the skip of contents by the Scilab
or commenting of the rest of contents in the line. It only separates the two statements
written in a single line. Again, when a statement is terminated with semicolon, then the
output or result is stored in memory and it is not visible in the output console. The
output is obtained only when the object is called without terminating by semicolon.
✞
1 -- a=5+5; b=6+5;
-- a
3 -- b
✌
✆
1.3. ARITHMETICAL KEYWORDS 47
✞
a =
10.
b =
11.
✌
✆
1.3.23 Forward Slash
Slash (/) is used in division. The left side value to the forward slash is divided by its
right side value. When forward slash is used in pair, it acts as a commenting symbol. In
Scilab, line commenting symbol is ‘//’.
✞
-- i = 5; // end of first line
2 -- j = 10; // end of second line
-- i/j
✌
✆
✞
ans =
0.5
✌
✆
1.3.24 Space
Space operator (“ ”) is used as the identifier for columns in a matrix or in a vector. A
3 × 3 matrix is represented in vector form as
✞
-- [1 2 3;4 5 6;7 8 9]
✌
✆
✞
x =
1 2 3
4 5 6
7 8 9
✌
✆
Comma operator (,) is also used as separator of the elements in a row.
1.3.25 Asterisk
Star (*), i.e. asterisk is used as multiplier between two variables from left to right.
Multiplication of two vectors are allowed if number of rows in first vector is equals to the
number of columns in second vector. If A = aij and B = bij are two matrices of size
n × n then
[A ∗ B]kj =
n
X
i,k=0
aki × bik
It is not always true that [A ∗ B] = [B ∗ A]. If two inputs are integers then it performs
simple arithmetic.
48 Scilab Core
✞
-- i = 5; // end of first line
2 -- j = 10; // end of second line
-- i*j
✌
✆
✞
ans =
50
✌
✆
Multiplication of vector and scalar:
✞
-- [1 ,2]*4
✌
✆
✞
ans =
4. 8.
✌
✆
Asterisk performs multiplication of matrices. A matrix multiplication is performed if the
matrix product conditions are satisfied. For two vectors or matrices, if number of columns
of first matrix is equal to the number of rows of second matrix then matrix multiplication
is carried out. See the following example.
✞
-- [1 ,2]*[4;3] // 1x2 matrix by 2x1 matrix
✌
✆
✞
ans =
10.
✌
✆
If, A and B are 2 × 2 matrices as given by
A =

1 2
3 2

; B =

2 1
3 4

Then
C = A ∗ B =

1 × 2 + 2 × 3 1 × 1 + 2 × 4
3 × 2 + 2 × 3 3 × 1 + 2 × 4

=

8 9
12 11

✞
-- a=[1 ,2;3 ,2];
2 -- b=[2 ,1;3 ,4];
-- a*b
✌
✆
✞
ans =
8. 9.
12. 11.
✌
✆
If two matrices are not equal in size then they are taken as vectors and vector multiplica-
tion is performed. It happens when second matrix is 1 × 1 type matrix. Second operand
may be a scalar too as seen above in the product of vector and scalar. See the following
example.
✞
1 -- [1 ,2]*[4]
✌
✆
1.4. CORE KEYWORDS 49
✞
ans =
4. 8.
✌
✆
Consistency shall be maintained while performing vector or matrix multiplication. For
example, if second operand is a multicolumn vector then it must satisfy the condition
of matrix multiplication. See the following example, in which Scilab failed to give desire
result due to inconsistent multiplication.
✞
-- [1 ,2]*[3 ,4]
✌
✆
✞
!--error 10
Inconsistent multiplication .
✌
✆
1.3.26 Tilda
Tilda, (!) is a logical NOT. It is also used like (∼=) i.e. not equals to. It is an boolean
expression for NOT Gate.
✞
-- 2 != 3 //2 is not equal to 3.
✌
✆
✞
ans =
T
✌
✆
1.4 Core Keywords
1.4.1 Abort Process (abort)
abort interrupts current evaluation and gives the prompt. Within a pause level abort
return to level 0 prompt.
✞
-- i = 0;
2 -- while i10 do
-- disp (i);
4 -- i = i + 1;
-- if(i5)
6 -- abort;// abort key word
-- end
8 -- end
✌
✆
✞
0.
1.
2.
3.
4.
5.
✌
✆
50 Scilab Core
1.4.2 Add a Demo (add demo)
This function, add demo, is used to add user define file or codes into Scilab demos.
✞
-- // Create a simple demo script
2 -- path = TMPDIR+’/foo.sce ’;
-- mputl(’disp Hello’,path )
4 -- add_demo (’My first demo ’,path )
-- // Demo can be run using Demos menu .
✌
✆
We can find ‘My first demo’ in Demos options of ’Scilab Demonstrations’.
1.4.3 Number of Arguments (argn)
argn is similar to the argc command in ‘C’. It returns the number of input/output argu-
ments in a function call. Scilab uses ‘lhs’ and ‘rhs’ for identification of inputs arguments
and output arguments. For example, in the following function
y = f(x)
left hand side (lhs) argument is y while right hand side (rhs) argument is x. Actually for
this relation, x is input argument and y is output argument. argn has three arguments.
‘0’ for both lhs (output arguments) and rhs (input arguments) strings. ‘1’ for lhs (output
arguments) only and ‘2’ for rhs (input arguments) only. Its syntax are
✞
1 -- [lhs , rhs] = argn () // for both input/output arguments
-- lhs=argn (1) // for output arguments only
3 -- rhs=argn (2) // for input arguments only
✌
✆
The given example is
✞
1 -- funcprot (0);
-- function [t] = myf(a,b,c)
3 -- [lhs , rhs] = argn (0);
-- mprintf (Nos of outputs : %dn,lhs);
5 -- mprintf (Nos of inputs : %dn,rhs);
-- outs = argn (1);
7 -- ins = argn (2);
-- mprintf (Nos of outputs : %dn,outs );
9 -- mprintf (Nos of inputs : %dn,ins);
-- endfunction
11 -- x=myf (2,2,3)
✌
✆
✞
Nos of outputs : 1
Nos of inputs : 3
Nos of outputs : 1
Nos of inputs : 3
✌
✆
1.4. CORE KEYWORDS 51
1.4.4 Banner
It shows the default banner of Scilab.
✞
-- banner ()
✌
✆
1.4.5 Boolean
Boolean operators , | and ∼ are used to express the boolean relation between two
variables. These operators are used as logical AND, logical OR and logical NOT as short
cuts and as element-wise.
Shortcut  And Elementwise 
Before, Scilab 6.0, shortcut and elementwise boolean AND operators were same and both
were represented by . Since Scilab 6.0, shortcut and element-wise boolean operators are
now distinct.  is shortcut boolean AND, while  is element-wise AND operations.
Both shortcut and element-wise operators are evaluated from left to right.
✞
1 -- [1,3]  [5,2] //  is not defined before scilab 6.0
-- // Error shows in Scilab  v 6.0
✌
✆
✞
[1,3]  [5,2]
!-- error 2
Invalid factor.
✌
✆
✞
1 --[1,3]  [5,2] // Works in all version of scilab
✌
✆
✞
ans =
T T
✌
✆
Shortcut || And Elementwise |
Before, Scilab 6.0, shortcut and elementwise boolean OR operators were same and both
were represented by . Since Scilab 6.0, shortcut and element-wise boolean operators
are now distinct. || is shortcut boolean OR, while | is element-wise OR operations. Both
shortcut and element-wise operators are evaluated from left to right.
✞
-- [1,3] || [5,2] //  is not defined before scilab 6.0
2 -- // Error in scilab  v 6.0
✌
✆
✞
[1,3] || [5,2]
!-- error 2
Invalid factor.
✌
✆
52 Scilab Core
✞
1 --[1,3] | [5,2] // Works in all version of scilab
✌
✆
✞
ans =
T T
✌
✆
1.4.6 Break a Process (break)
break keyword interrupt a current loop. It is always used inside the loop functions or
switch functions.
✞
-- i = 0;
2 -- while i10 do
-- disp (i);
4 -- i = i + 1;
-- if(i5)
6 -- break;// break the loop
-- end
8 -- end
✌
✆
✞
0.
1.
2.
3.
4.
5.
✌
✆
1.4.7 Case
case is used to compare a select value with arbitrary chosen value. If select value is equal
to case value, statement inside the case is executed.
✞
-- A = 2
2 -- select A
-- case 1 then
4 -- disp (1)
-- case 2 then
6 -- disp (2)
-- else
8 -- disp (3)
-- end
✌
✆
✞
2
✌
✆
1.4. CORE KEYWORDS 53
1.4.8 Kill the Value (clear)
clear kills the value of a variable. If a variable is cleared inside the loop, an error is
displayed as undefined variable.
✞
1 --i = 0;
--while i5 do
3 -- disp (i);
-- i = i + 1;
5 -- if(i2)
-- // Clear variable i. Now , in next loop variable
7 -- // i shall not be identified inside while loop .
-- clear i;
9 -- end
--end
✌
✆
✞
0.
1.
2.
while i5 do
!--error 4
Undefined variable : i
✌
✆
1.4.9 Remove a Function (clearfun)
clearfun is used to remove a function name in the table of Scilab functions.
✞
-- // Get the func ptr associated with the abs function
2 -- absptr=funptr(abs);
-- // Create an alias of the abs function
4 -- newfun(abs_bis,absptr);
-- clearfun (abs)
✌
✆
✞
ans =
T
✌
✆
1.4.10 Clear Global
clearglobal clears the global variable defined previously.
1.4.11 Compile Scilab Function (comp)
comp compiles a function in Scilab. If a function is already compiled then it gives warning.
✞
-- comp (abs ,0)
✌
✆
✞
Warning : Function is already compiled .
✌
✆
54 Scilab Core
There are three options of compilation of function. Default is ‘0’ and others are ‘1’ and
‘2’.
Options Meaning
0 Default compilation value.
1 Obsolete, similar to option ‘0’.
2 Function to be compiled “for profiling”.
1.4.12 Continue
continue pass the control to the next iteration of loop. To understand the working of
continue keyword, we use same example in three different methods. In following example
two for loops are used.
✞
1 -- for j =1:1:3
-- for k=3: -1:1
3 -- if jk then
-- disp (j*k);
5 -- end
-- end
7 -- end
✌
✆
✞
2.
6.
3.
✌
✆
Now we put the continue command after disp(j*k) as
✞
1 -- for j =1:1:3
-- for k=3: -1:1
3 -- if jk then
-- disp (j*k);
5 -- continue ;
-- end
7 -- end
-- end
✌
✆
✞
2.
6.
3.
✌
✆
There is no change in output as disp put the result before continue encountered. Again
if we put the continue command before disp(j*k) as
✞
1 -- for j =1:1:3
-- for k=3: -1:1
3 -- if jk then
-- continue ;
1.4. CORE KEYWORDS 55
5 -- disp (j*k);
-- end
7 -- end
-- end
✌
✆
There is no output as continue pushes to the next iterator before disp put the result in
output window.
1.4.13 Debug
debug is used to find the errors and bad scripting in a code script. There are five levels
of debugging, ranged from -1 to 4. This range defines the level of debugging.
✞
-- debug(-1)
✌
✆
✞
ans =
1
✌
✆
1.4.14 Delete Break
delbpt is used to delete a break point from the function. To set a breakpoint for function
‘foo’, we use setbpt. The setbpt sets break point one over other as stack in setbpt list. On
call of delbpt the top most breakpoint is deleted from the stack.
✞
-- setbpt(’foo’ ,1); // set first break point at 1
2 -- setbpt(’foo’ ,10);// set second break point at 10
-- delbpt(’foo’ ,10);// deleted second break point at 10
4 -- dispbpt () // show first break point at 1
✌
✆
✞
Breakpoints of function : foo
1
✌
✆
1.4.15 Display Break Points (dispbpt)
dispbpt is used to show a break point of a function from the setbpt list.
✞
-- setbpt(’foo’ ,1); // set first break point at 1
2 -- setbpt(’foo’ ,10);// set second break point at 10
-- delbpt(’foo’ ,10);// deleted second break point at 10
4 -- dispbpt () // show first break point at 1
✌
✆
✞
Breakpoints of function : foo
1
✌
✆
56 Scilab Core
1.4.16 Do
do keyword is used to execute a group of statements or programming script until unless
a condition is being satisfied. do keyword is always used with while function. The scope
of do keyword is from the next line of statement to the corresponding end keyword.
✞
-- i = 0
2 -- while i5 do
-- disp (i);
4 -- i = i + 1;
-- end
✌
✆
✞
ans =
0
1
2
3
4
✌
✆
1.4.17 Edit
Function edit is used to open a existing file or existing function in the Scilab editor or
open editor for definition of new function.
✞
-- // open editor with text of existing function
2 -- edit (’edit ’)
-- // open editor for a new function
4 -- edit (’myF’)
✌
✆
The argument of this function is either a function name or a file name as absolute path.
✞
-- // open the file bar.sci in TMPDIR directory
2 -- edit ( fullfile (TMPDIR+’bar.sci’))
✌
✆
An existing file may be open in the Scilab editor with reaching to specific line of the
script. The script line is specified by the second argument. Second argument is a pure
integer value.
✞
-- edit (’test_run ’, 123)
✌
✆
User defined function can also be open in default Scilab editor with the function scripts.
✞
1 -- function a=b(c)
-- c=1;
3 -- endfunction
-- edit (’b’)
✌
✆
This will open function ’b’ in Scilab editor.
1.4. CORE KEYWORDS 57
1.4.18 Else
else is the false case of if condition. If a condition is not satisfied, statement in else
section are executed. Another if-else loop can be initiated in the statement section of
else as a nested loop.
✞
-- i = 5;
2 -- j = 10;
-- if(i==j)
4 -- disp (T);
-- else
6 -- disp (F);
-- end
✌
✆
✞
T
✌
✆
1.4.19 Else-If
elseif is used as false case of if with new if conditions. It is also used as chain conditional
case. A nested loop can also be used within the elseif statement portion.
✞
1 -- i = 5;
-- j = 10;
3 -- if(ij)
-- disp (L);
5 -- elseif(ij)
-- disp (G);
7 -- elseif(i==j)
-- disp (E);
9 -- end
✌
✆
✞
L
✌
✆
1.4.20 End
end keyword is used to terminate a conditional statement. end is used for the following
purposes
1. To finish a condition.
2. To finish a function definition by using endfunction for Scilab version 5.5 and prior
or using end only since Scilab 6.0 and later.
3. To finish a statement.
✞
1 -- i = 5;
-- j = 10;
3 -- if(ij)
58 Scilab Core
-- disp (L);
5 -- elseif(ij)
-- disp (G);
7 -- elseif(i==j)
-- disp (E);
9 -- end
✌
✆
✞
L
✌
✆
1.4.21 Catch Error (errcatch)
errcatch is used to trap an error. This function is removed since Scilab 6.
✞
1 -- errcatch (1,’pause’);
✌
✆
The first variable in errcatch is number that is used to trap an error. If it is less than 0
then all errors are catch and if it is grater than 0 then errcatch traps that specific error
assigned to this number. Second variable is action in string form that is to be performed
if error catches. The actions are either ‘pause’, ‘continue’, ‘kill’ or ‘stop’.
1.4.22 Clear The Error (errclear)
In scilab, error table contains the list of all errors being rose during the operation. errclear
is used to clear a specific or all errors from the error list. It is used like
✞
1 -- errclear (n);
✌
✆
Where ‘n’ is the error number. If ‘n’ is positive (n  0), it is the number of the cleared
error. If (n ≤ 0) then all errors are cleared (default case).
1.4.23 Error
error function is standard way of printing errors during the process by Scilab. A cus-
tomised error may also be constructed by using this function. It accepts two arguments,
in which first argument is message and second argument is error number associated with
message. It is used like
✞
1 -- error(message )
-- error(message , n)
3 -- error(n)
-- error(n, message )
5 -- error(n, pos )
✌
✆
Here ‘message’ is the error message. ‘n’ is error number and ‘pos’ is a parameter of error
message. By default ‘n’ is ‘10000’.
✞
1 -- error(! This value must be an integer !, 10)
✌
✆
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions
Scilab Introduction: Core Features and Functions

More Related Content

What's hot

Introduction to MPI
Introduction to MPI Introduction to MPI
Introduction to MPI Hanif Durad
 
An Optimized Implementation Of 64-Bit MAC Unit For DSP Applications Using SPST
An Optimized Implementation Of 64-Bit MAC Unit For DSP Applications Using SPSTAn Optimized Implementation Of 64-Bit MAC Unit For DSP Applications Using SPST
An Optimized Implementation Of 64-Bit MAC Unit For DSP Applications Using SPSTPatnam Shruthi
 
Fixed point and floating-point numbers
Fixed point and  floating-point numbersFixed point and  floating-point numbers
Fixed point and floating-point numbersMOHAN MOHAN
 
Introduction to linux containers
Introduction to linux containersIntroduction to linux containers
Introduction to linux containersGoogle
 
MPI message passing interface
MPI message passing interfaceMPI message passing interface
MPI message passing interfaceMohit Raghuvanshi
 
Gsm Protocoles & ProcéDures
Gsm   Protocoles & ProcéDuresGsm   Protocoles & ProcéDures
Gsm Protocoles & ProcéDuresAnouar Loukili
 
Travaux dirigés Réseau Ethernet
Travaux dirigés Réseau EthernetTravaux dirigés Réseau Ethernet
Travaux dirigés Réseau EthernetInes Kechiche
 
Summer training embedded system and its scope
Summer training  embedded system and its scopeSummer training  embedded system and its scope
Summer training embedded system and its scopeArshit Rai
 
Pipelining of Processors
Pipelining of ProcessorsPipelining of Processors
Pipelining of ProcessorsGaditek
 
Chapter 01 Basic Principles of Digital Systems
Chapter 01 Basic Principles of Digital SystemsChapter 01 Basic Principles of Digital Systems
Chapter 01 Basic Principles of Digital SystemsSSE_AndyLi
 
Chap3 liaison de données
Chap3 liaison de donnéesChap3 liaison de données
Chap3 liaison de donnéesEns Kouba
 

What's hot (20)

Introduction to MPI
Introduction to MPI Introduction to MPI
Introduction to MPI
 
Rtos ss
Rtos ssRtos ss
Rtos ss
 
An Optimized Implementation Of 64-Bit MAC Unit For DSP Applications Using SPST
An Optimized Implementation Of 64-Bit MAC Unit For DSP Applications Using SPSTAn Optimized Implementation Of 64-Bit MAC Unit For DSP Applications Using SPST
An Optimized Implementation Of 64-Bit MAC Unit For DSP Applications Using SPST
 
Message passing interface
Message passing interfaceMessage passing interface
Message passing interface
 
Combinational circuit
Combinational circuitCombinational circuit
Combinational circuit
 
Fixed point and floating-point numbers
Fixed point and  floating-point numbersFixed point and  floating-point numbers
Fixed point and floating-point numbers
 
Ch19
Ch19Ch19
Ch19
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Introduction to linux containers
Introduction to linux containersIntroduction to linux containers
Introduction to linux containers
 
MPI message passing interface
MPI message passing interfaceMPI message passing interface
MPI message passing interface
 
Gsm Protocoles & ProcéDures
Gsm   Protocoles & ProcéDuresGsm   Protocoles & ProcéDures
Gsm Protocoles & ProcéDures
 
4 bit uni shift reg
4 bit uni shift reg4 bit uni shift reg
4 bit uni shift reg
 
Travaux dirigés Réseau Ethernet
Travaux dirigés Réseau EthernetTravaux dirigés Réseau Ethernet
Travaux dirigés Réseau Ethernet
 
MinGw Compiler
MinGw CompilerMinGw Compiler
MinGw Compiler
 
Rpc
RpcRpc
Rpc
 
Summer training embedded system and its scope
Summer training  embedded system and its scopeSummer training  embedded system and its scope
Summer training embedded system and its scope
 
Different addressing mode and risc, cisc microprocessor
Different addressing mode and risc, cisc microprocessorDifferent addressing mode and risc, cisc microprocessor
Different addressing mode and risc, cisc microprocessor
 
Pipelining of Processors
Pipelining of ProcessorsPipelining of Processors
Pipelining of Processors
 
Chapter 01 Basic Principles of Digital Systems
Chapter 01 Basic Principles of Digital SystemsChapter 01 Basic Principles of Digital Systems
Chapter 01 Basic Principles of Digital Systems
 
Chap3 liaison de données
Chap3 liaison de donnéesChap3 liaison de données
Chap3 liaison de données
 

Similar to Scilab Introduction: Core Features and Functions

Modlica an introduction by Arun Umrao
Modlica an introduction by Arun UmraoModlica an introduction by Arun Umrao
Modlica an introduction by Arun Umraossuserd6b1fd
 
Modelica programming help book
Modelica programming help bookModelica programming help book
Modelica programming help bookArun Umrao
 
Notes and Description for Xcos Scilab Block Simulation with Suitable Examples...
Notes and Description for Xcos Scilab Block Simulation with Suitable Examples...Notes and Description for Xcos Scilab Block Simulation with Suitable Examples...
Notes and Description for Xcos Scilab Block Simulation with Suitable Examples...ssuserd6b1fd
 
Xcos simulation
Xcos simulationXcos simulation
Xcos simulationArun Umrao
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
 
Introduction to c++ (cpp)
Introduction to c++ (cpp)Introduction to c++ (cpp)
Introduction to c++ (cpp)Arun Umrao
 
Fortran programming help book
Fortran programming help bookFortran programming help book
Fortran programming help bookArun Umrao
 
Basic ForTran Programming - for Beginners - An Introduction by Arun Umrao
Basic ForTran Programming - for Beginners - An Introduction by Arun UmraoBasic ForTran Programming - for Beginners - An Introduction by Arun Umrao
Basic ForTran Programming - for Beginners - An Introduction by Arun Umraossuserd6b1fd
 
The C Preprocessor
The C PreprocessorThe C Preprocessor
The C Preprocessoriuui
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 1 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 1 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 1 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 1 of 5 by...ssuserd6b1fd
 
Notes for c programming for mca, bca, b. tech cse, ece and msc (cs) 1 of 5 by...
Notes for c programming for mca, bca, b. tech cse, ece and msc (cs) 1 of 5 by...Notes for c programming for mca, bca, b. tech cse, ece and msc (cs) 1 of 5 by...
Notes for c programming for mca, bca, b. tech cse, ece and msc (cs) 1 of 5 by...ssuserd6b1fd
 
Java Programming Notes for Beginners by Arun Umrao
Java Programming Notes for Beginners by Arun UmraoJava Programming Notes for Beginners by Arun Umrao
Java Programming Notes for Beginners by Arun Umraossuserd6b1fd
 
A_Practical_Introduction_to_Python_Programming_Heinold.pdf
A_Practical_Introduction_to_Python_Programming_Heinold.pdfA_Practical_Introduction_to_Python_Programming_Heinold.pdf
A_Practical_Introduction_to_Python_Programming_Heinold.pdfssuser7fcce2
 
A practical introduction_to_python_programming_heinold
A practical introduction_to_python_programming_heinoldA practical introduction_to_python_programming_heinold
A practical introduction_to_python_programming_heinoldthe_matrix
 
A Practical Introduction To Python Programming
A Practical Introduction To Python ProgrammingA Practical Introduction To Python Programming
A Practical Introduction To Python ProgrammingNat Rice
 
A practical introduction_to_python_programming_heinold
A practical introduction_to_python_programming_heinoldA practical introduction_to_python_programming_heinold
A practical introduction_to_python_programming_heinoldFaruqolayinkaSalako
 
A_Practical_Introduction_to_Python_Programming_Heinold.pdf
A_Practical_Introduction_to_Python_Programming_Heinold.pdfA_Practical_Introduction_to_Python_Programming_Heinold.pdf
A_Practical_Introduction_to_Python_Programming_Heinold.pdfTariqSaeed80
 

Similar to Scilab Introduction: Core Features and Functions (20)

Thats How We C
Thats How We CThats How We C
Thats How We C
 
Modlica an introduction by Arun Umrao
Modlica an introduction by Arun UmraoModlica an introduction by Arun Umrao
Modlica an introduction by Arun Umrao
 
Modelica programming help book
Modelica programming help bookModelica programming help book
Modelica programming help book
 
Notes and Description for Xcos Scilab Block Simulation with Suitable Examples...
Notes and Description for Xcos Scilab Block Simulation with Suitable Examples...Notes and Description for Xcos Scilab Block Simulation with Suitable Examples...
Notes and Description for Xcos Scilab Block Simulation with Suitable Examples...
 
Xcos simulation
Xcos simulationXcos simulation
Xcos simulation
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Introduction to c++ (cpp)
Introduction to c++ (cpp)Introduction to c++ (cpp)
Introduction to c++ (cpp)
 
Fortran programming help book
Fortran programming help bookFortran programming help book
Fortran programming help book
 
Basic ForTran Programming - for Beginners - An Introduction by Arun Umrao
Basic ForTran Programming - for Beginners - An Introduction by Arun UmraoBasic ForTran Programming - for Beginners - An Introduction by Arun Umrao
Basic ForTran Programming - for Beginners - An Introduction by Arun Umrao
 
The C Preprocessor
The C PreprocessorThe C Preprocessor
The C Preprocessor
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 1 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 1 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 1 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 1 of 5 by...
 
c programming
c programmingc programming
c programming
 
Notes for c programming for mca, bca, b. tech cse, ece and msc (cs) 1 of 5 by...
Notes for c programming for mca, bca, b. tech cse, ece and msc (cs) 1 of 5 by...Notes for c programming for mca, bca, b. tech cse, ece and msc (cs) 1 of 5 by...
Notes for c programming for mca, bca, b. tech cse, ece and msc (cs) 1 of 5 by...
 
Notes of Java
Notes of JavaNotes of Java
Notes of Java
 
Java Programming Notes for Beginners by Arun Umrao
Java Programming Notes for Beginners by Arun UmraoJava Programming Notes for Beginners by Arun Umrao
Java Programming Notes for Beginners by Arun Umrao
 
A_Practical_Introduction_to_Python_Programming_Heinold.pdf
A_Practical_Introduction_to_Python_Programming_Heinold.pdfA_Practical_Introduction_to_Python_Programming_Heinold.pdf
A_Practical_Introduction_to_Python_Programming_Heinold.pdf
 
A practical introduction_to_python_programming_heinold
A practical introduction_to_python_programming_heinoldA practical introduction_to_python_programming_heinold
A practical introduction_to_python_programming_heinold
 
A Practical Introduction To Python Programming
A Practical Introduction To Python ProgrammingA Practical Introduction To Python Programming
A Practical Introduction To Python Programming
 
A practical introduction_to_python_programming_heinold
A practical introduction_to_python_programming_heinoldA practical introduction_to_python_programming_heinold
A practical introduction_to_python_programming_heinold
 
A_Practical_Introduction_to_Python_Programming_Heinold.pdf
A_Practical_Introduction_to_Python_Programming_Heinold.pdfA_Practical_Introduction_to_Python_Programming_Heinold.pdf
A_Practical_Introduction_to_Python_Programming_Heinold.pdf
 

More from ssuserd6b1fd

Decreasing increasing functions by arun umrao
Decreasing increasing functions by arun umraoDecreasing increasing functions by arun umrao
Decreasing increasing functions by arun umraossuserd6b1fd
 
Distribution of normal data understanding it numerical way by arun umrao
Distribution of normal data   understanding it numerical way by arun umraoDistribution of normal data   understanding it numerical way by arun umrao
Distribution of normal data understanding it numerical way by arun umraossuserd6b1fd
 
Decreasing and increasing functions by arun umrao
Decreasing and increasing functions by arun umraoDecreasing and increasing functions by arun umrao
Decreasing and increasing functions by arun umraossuserd6b1fd
 
What is meaning of epsilon and delta in limits of a function by Arun Umrao
What is meaning of epsilon and delta in limits of a function by Arun UmraoWhat is meaning of epsilon and delta in limits of a function by Arun Umrao
What is meaning of epsilon and delta in limits of a function by Arun Umraossuserd6b1fd
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...ssuserd6b1fd
 
Notes for GNU Octave - Numerical Programming - for Students 01 of 02 by Arun ...
Notes for GNU Octave - Numerical Programming - for Students 01 of 02 by Arun ...Notes for GNU Octave - Numerical Programming - for Students 01 of 02 by Arun ...
Notes for GNU Octave - Numerical Programming - for Students 01 of 02 by Arun ...ssuserd6b1fd
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
 
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...ssuserd6b1fd
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...ssuserd6b1fd
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...ssuserd6b1fd
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...ssuserd6b1fd
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...ssuserd6b1fd
 
Work and Energy Notes by Arun Umrao
Work and Energy Notes by Arun UmraoWork and Energy Notes by Arun Umrao
Work and Energy Notes by Arun Umraossuserd6b1fd
 
Notes of Units, Dimensions & Errors for IIT JEE by Arun Umrao
Notes of Units, Dimensions & Errors for IIT JEE by Arun UmraoNotes of Units, Dimensions & Errors for IIT JEE by Arun Umrao
Notes of Units, Dimensions & Errors for IIT JEE by Arun Umraossuserd6b1fd
 
Physics dictionary for CBSE, ISCE, Class X Students by Arun Umrao
Physics dictionary for CBSE, ISCE, Class X Students by Arun UmraoPhysics dictionary for CBSE, ISCE, Class X Students by Arun Umrao
Physics dictionary for CBSE, ISCE, Class X Students by Arun Umraossuserd6b1fd
 
Notes of 8085 micro processor Programming for BCA, MCA, MSC (CS), MSC (IT) &...
Notes of 8085 micro processor Programming  for BCA, MCA, MSC (CS), MSC (IT) &...Notes of 8085 micro processor Programming  for BCA, MCA, MSC (CS), MSC (IT) &...
Notes of 8085 micro processor Programming for BCA, MCA, MSC (CS), MSC (IT) &...ssuserd6b1fd
 
Notes of 8051 Micro Controller for BCA, MCA, MSC (CS), MSC (IT) & AMIE IEI- b...
Notes of 8051 Micro Controller for BCA, MCA, MSC (CS), MSC (IT) & AMIE IEI- b...Notes of 8051 Micro Controller for BCA, MCA, MSC (CS), MSC (IT) & AMIE IEI- b...
Notes of 8051 Micro Controller for BCA, MCA, MSC (CS), MSC (IT) & AMIE IEI- b...ssuserd6b1fd
 
Maxima CAS an introduction
Maxima CAS an introductionMaxima CAS an introduction
Maxima CAS an introductionssuserd6b1fd
 
Maxima & Minima of Functions - Differential Calculus by Arun Umrao
Maxima & Minima of Functions - Differential Calculus by Arun UmraoMaxima & Minima of Functions - Differential Calculus by Arun Umrao
Maxima & Minima of Functions - Differential Calculus by Arun Umraossuserd6b1fd
 
Principles of Linear Motion of Objects - Physics - Explained by Arun Umrao
Principles of Linear Motion of Objects - Physics - Explained by Arun UmraoPrinciples of Linear Motion of Objects - Physics - Explained by Arun Umrao
Principles of Linear Motion of Objects - Physics - Explained by Arun Umraossuserd6b1fd
 

More from ssuserd6b1fd (20)

Decreasing increasing functions by arun umrao
Decreasing increasing functions by arun umraoDecreasing increasing functions by arun umrao
Decreasing increasing functions by arun umrao
 
Distribution of normal data understanding it numerical way by arun umrao
Distribution of normal data   understanding it numerical way by arun umraoDistribution of normal data   understanding it numerical way by arun umrao
Distribution of normal data understanding it numerical way by arun umrao
 
Decreasing and increasing functions by arun umrao
Decreasing and increasing functions by arun umraoDecreasing and increasing functions by arun umrao
Decreasing and increasing functions by arun umrao
 
What is meaning of epsilon and delta in limits of a function by Arun Umrao
What is meaning of epsilon and delta in limits of a function by Arun UmraoWhat is meaning of epsilon and delta in limits of a function by Arun Umrao
What is meaning of epsilon and delta in limits of a function by Arun Umrao
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
 
Notes for GNU Octave - Numerical Programming - for Students 01 of 02 by Arun ...
Notes for GNU Octave - Numerical Programming - for Students 01 of 02 by Arun ...Notes for GNU Octave - Numerical Programming - for Students 01 of 02 by Arun ...
Notes for GNU Octave - Numerical Programming - for Students 01 of 02 by Arun ...
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
 
Work and Energy Notes by Arun Umrao
Work and Energy Notes by Arun UmraoWork and Energy Notes by Arun Umrao
Work and Energy Notes by Arun Umrao
 
Notes of Units, Dimensions & Errors for IIT JEE by Arun Umrao
Notes of Units, Dimensions & Errors for IIT JEE by Arun UmraoNotes of Units, Dimensions & Errors for IIT JEE by Arun Umrao
Notes of Units, Dimensions & Errors for IIT JEE by Arun Umrao
 
Physics dictionary for CBSE, ISCE, Class X Students by Arun Umrao
Physics dictionary for CBSE, ISCE, Class X Students by Arun UmraoPhysics dictionary for CBSE, ISCE, Class X Students by Arun Umrao
Physics dictionary for CBSE, ISCE, Class X Students by Arun Umrao
 
Notes of 8085 micro processor Programming for BCA, MCA, MSC (CS), MSC (IT) &...
Notes of 8085 micro processor Programming  for BCA, MCA, MSC (CS), MSC (IT) &...Notes of 8085 micro processor Programming  for BCA, MCA, MSC (CS), MSC (IT) &...
Notes of 8085 micro processor Programming for BCA, MCA, MSC (CS), MSC (IT) &...
 
Notes of 8051 Micro Controller for BCA, MCA, MSC (CS), MSC (IT) & AMIE IEI- b...
Notes of 8051 Micro Controller for BCA, MCA, MSC (CS), MSC (IT) & AMIE IEI- b...Notes of 8051 Micro Controller for BCA, MCA, MSC (CS), MSC (IT) & AMIE IEI- b...
Notes of 8051 Micro Controller for BCA, MCA, MSC (CS), MSC (IT) & AMIE IEI- b...
 
Maxima CAS an introduction
Maxima CAS an introductionMaxima CAS an introduction
Maxima CAS an introduction
 
Maxima & Minima of Functions - Differential Calculus by Arun Umrao
Maxima & Minima of Functions - Differential Calculus by Arun UmraoMaxima & Minima of Functions - Differential Calculus by Arun Umrao
Maxima & Minima of Functions - Differential Calculus by Arun Umrao
 
Principles of Linear Motion of Objects - Physics - Explained by Arun Umrao
Principles of Linear Motion of Objects - Physics - Explained by Arun UmraoPrinciples of Linear Motion of Objects - Physics - Explained by Arun Umrao
Principles of Linear Motion of Objects - Physics - Explained by Arun Umrao
 

Recently uploaded

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 

Scilab Introduction: Core Features and Functions

  • 2. 2 Contents I Scilab 7 1 Scilab Core 9 1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.1.1 Everything As Matrix . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.1.2 Approximate Zero . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.1.3 Computational Error . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.2 Simple Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.2.1 Addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.2.2 Subtraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 1.2.3 Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 1.2.4 Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.2.5 Scoping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.2.6 Square Root (sqrt) . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.2.7 Exponent (ˆ Operator) . . . . . . . . . . . . . . . . . . . . . . . . 17 1.2.8 Algebraic Equations . . . . . . . . . . . . . . . . . . . . . . . . . . 20 1.2.9 Logarithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.2.10 Index Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 1.3 Arithmetical Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 1.3.1 Result Variable (ans) . . . . . . . . . . . . . . . . . . . . . . . . . . 25 1.3.2 Left Matrix Division () . . . . . . . . . . . . . . . . . . . . . . . . 25 1.3.3 Square Brackets ([...]) . . . . . . . . . . . . . . . . . . . . . . . . . 26 1.3.4 Element-Wise Operation . . . . . . . . . . . . . . . . . . . . . . . . 27 1.3.5 Matrix-Wise Operation . . . . . . . . . . . . . . . . . . . . . . . . 27 1.3.6 Colon (Range Operator) . . . . . . . . . . . . . . . . . . . . . . . . 27 1.3.7 Comma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 1.3.8 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 1.3.9 Dot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 1.3.10 Empty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 1.3.11 Equal Sign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 1.3.12 global . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 1.3.13 Hat Symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 1.3.14 Less Than . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 1.3.15 Minus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 1.3.16 Not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 1.3.17 Parenthesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 1.3.18 Percent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 1.3.19 Plus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 1.3.20 Quote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 1.3.21 Return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 1.3.22 Semicolon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 1.3.23 Forward Slash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 1.3.24 Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 1.3.25 Asterisk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
  • 3. 3 1.3.26 Tilda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 1.4 Core Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 1.4.1 Abort Process (abort) . . . . . . . . . . . . . . . . . . . . . . . . . 41 1.4.2 Add a Demo (add demo) . . . . . . . . . . . . . . . . . . . . . . . 42 1.4.3 Number of Arguments (argn) . . . . . . . . . . . . . . . . . . . . . 42 1.4.4 Banner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 1.4.5 Boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Shortcut && And Elementwise & . . . . . . . . . . . . . . . . . . . 43 Shortcut || And Elementwise | . . . . . . . . . . . . . . . . . . . . . 43 1.4.6 Break a Process (break) . . . . . . . . . . . . . . . . . . . . . . . . 44 1.4.7 Case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 1.4.8 Kill the Value (clear) . . . . . . . . . . . . . . . . . . . . . . . . . . 45 1.4.9 Remove a Function (clearfun) . . . . . . . . . . . . . . . . . . . . . 45 1.4.10 Clear Global . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 1.4.11 Compile Scilab Function (comp) . . . . . . . . . . . . . . . . . . . 45 1.4.12 Continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 1.4.13 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 1.4.14 Delete Break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 1.4.15 Display Break Points (dispbpt) . . . . . . . . . . . . . . . . . . . . 47 1.4.16 Do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 1.4.17 Edit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 1.4.18 Else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 1.4.19 Else-If . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 1.4.20 End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 1.4.21 Catch Error (errcatch) . . . . . . . . . . . . . . . . . . . . . . . . . 50 1.4.22 Clear The Error (errclear) . . . . . . . . . . . . . . . . . . . . . . . 50 1.4.23 Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 1.4.24 Exists a Variable (exists) . . . . . . . . . . . . . . . . . . . . . . . 51 1.4.25 Exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 1.4.26 Extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 1.4.27 For . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 1.4.28 Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 1.4.29 MD5 Hash (getmd5) . . . . . . . . . . . . . . . . . . . . . . . . . . 54 1.4.30 Get Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 1.4.31 Get Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 1.4.32 Get Operating System . . . . . . . . . . . . . . . . . . . . . . . . . 55 1.4.33 Get Scilab Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 1.4.34 Get Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 1.4.35 Get Variale Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 1.4.36 Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 1.4.37 Insertion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 1.4.38 Interface Properties (intppty) . . . . . . . . . . . . . . . . . . . . . 57 1.4.39 Inverse Coefficients (inv coeff) . . . . . . . . . . . . . . . . . . . . 57 1.4.40 Is Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 1.4.41 Is Global . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 1.4.42 Line Spacing (linspace) . . . . . . . . . . . . . . . . . . . . . . . . 58 1.4.43 Last Error (lasterror) . . . . . . . . . . . . . . . . . . . . . . . . . 59
  • 4. 4 1.4.44 Macro To List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 1.4.45 Macro To Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 1.4.46 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 1.4.47 Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 1.4.48 Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 1.4.49 Matlab Mode (mtlb mode) . . . . . . . . . . . . . . . . . . . . . . 62 1.4.50 Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 1.4.51 New Function (newfun) . . . . . . . . . . . . . . . . . . . . . . . . 63 1.4.52 Null . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 1.4.53 Pause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 1.4.54 Predefined Variables (predef) . . . . . . . . . . . . . . . . . . . . . 64 1.4.55 Print Output in L A TEX (prettyprint) . . . . . . . . . . . . . . . . . 65 1.4.56 Quit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 1.4.57 Random Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 1.4.58 Read Gateway . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 1.4.59 Resume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 1.4.60 Select . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 1.4.61 Set Break Points (setbpt) . . . . . . . . . . . . . . . . . . . . . . . 67 1.4.62 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 1.4.63 Temporary Directory (TMPDIR) . . . . . . . . . . . . . . . . . . . 68 1.4.64 Test Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 1.4.65 Then . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 1.4.66 Try . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 1.4.67 Type (type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 1.4.68 Integer Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 1.4.69 Varn (varn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 1.4.70 Warning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 1.4.71 With tk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 1.4.72 While . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 1.5 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 1.5.1 Defining Own Function . . . . . . . . . . . . . . . . . . . . . . . . 73 1.5.2 Rewriting Own Function . . . . . . . . . . . . . . . . . . . . . . . . 74 1.5.3 Redefining Function Error . . . . . . . . . . . . . . . . . . . . . . . 75 1.5.4 Compilation Warning . . . . . . . . . . . . . . . . . . . . . . . . . 76 1.5.5 Undefined Variable Error . . . . . . . . . . . . . . . . . . . . . . . 76 1.5.6 Implementation Error . . . . . . . . . . . . . . . . . . . . . . . . . 77 1.5.7 Change Function in Prototype (funcprot) . . . . . . . . . . . . . . 77 1.5.8 Function Pointer (funptr) . . . . . . . . . . . . . . . . . . . . . . . 78 2 Linear Algebra 79 2.1 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 2.1.1 Simultaneous Solution . . . . . . . . . . . . . . . . . . . . . . . . . 79 2.1.2 Mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 2.1.3 Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 2.1.4 Data Frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 2.1.5 Tabulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 2.2 Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
  • 5. 5 2.2.1 Clean (clean) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 2.2.2 Degree of Polynomial (degree) . . . . . . . . . . . . . . . . . . . . 83 2.2.3 Solve Algebraic Equations (fsolve) . . . . . . . . . . . . . . . . . . 84 2.2.4 Denominator (denom) . . . . . . . . . . . . . . . . . . . . . . . . . 85 2.2.5 Derivative (derivat) . . . . . . . . . . . . . . . . . . . . . . . . . . 86 2.2.6 Determinant (determ) . . . . . . . . . . . . . . . . . . . . . . . . . 86 2.2.7 Determinant (detr) . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 2.2.8 Factors (factors) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 2.2.9 Greatest Common Divisor (gcd) . . . . . . . . . . . . . . . . . . . 88 2.2.10 Inverse of Matrix (invr) . . . . . . . . . . . . . . . . . . . . . . . . 88 2.2.11 Least Common Multiple (lcm) . . . . . . . . . . . . . . . . . . . . 89 2.2.12 LCM By Diagonalization (lcmdiag) . . . . . . . . . . . . . . . . . . 89 2.2.13 Numerator (numer) . . . . . . . . . . . . . . . . . . . . . . . . . . 90 2.2.14 Polynomial (poly) . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 2.2.15 Polynomial Division (pdiv) . . . . . . . . . . . . . . . . . . . . . . 91 2.2.16 Residue (residu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 2.2.17 Roots of Polynomial (roots) . . . . . . . . . . . . . . . . . . . . . . 93 Roots of Quadratic Equation . . . . . . . . . . . . . . . . . . . . . 93 Roots of Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . 94 2.2.18 Simplification (simp) . . . . . . . . . . . . . . . . . . . . . . . . . . 95 2.2.19 Flip Matrix Dimension (flipdim) . . . . . . . . . . . . . . . . . . . 95 2.2.20 Permutation (permute) . . . . . . . . . . . . . . . . . . . . . . . . 96 2.2.21 Matrix Replication (repmat) . . . . . . . . . . . . . . . . . . . . . 96 2.2.22 Cumulative Product (cumprod) . . . . . . . . . . . . . . . . . . . . 96 2.2.23 Cumulative Summation (cumsum) . . . . . . . . . . . . . . . . . . 98 2.2.24 Kronekar Product (kron) . . . . . . . . . . . . . . . . . . . . . . . 99 2.2.25 Product (prod) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 2.2.26 Summation (sum) . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 2.3 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 2.3.1 Determinant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 2.3.2 Transpose Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 2.3.3 Diagonal Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 2.3.4 Identity Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 2.3.5 Inverse of Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 2.3.6 Normalization of Matrix . . . . . . . . . . . . . . . . . . . . . . . . 110 2.3.7 Normalzation Factor (norm) . . . . . . . . . . . . . . . . . . . . . . 111 2.3.8 Permutation & Transposition (pertrans) . . . . . . . . . . . . . . . 112 2.3.9 Orthogonal Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 2.3.10 Complex Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 2.3.11 Matrix Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 2.3.12 Eigenvalues of Matrix . . . . . . . . . . . . . . . . . . . . . . . . . 115 2.3.13 Triangular Lower Matrix (tril) . . . . . . . . . . . . . . . . . . . . 116 2.3.14 Triangular Upper Matrix (triu) . . . . . . . . . . . . . . . . . . . . 116 2.3.15 Lower Upper Matrix (lu) . . . . . . . . . . . . . . . . . . . . . . . 117 2.3.16 Diagonal Matrix (diag) . . . . . . . . . . . . . . . . . . . . . . . . 117 2.3.17 Jordan Canonical Form (bdiag) . . . . . . . . . . . . . . . . . . . . 119 2.3.18 Cholensky Factorization (chol) . . . . . . . . . . . . . . . . . . . . 120
  • 6. 6 2.3.19 Determinant of Matrix (det) . . . . . . . . . . . . . . . . . . . . . 121 2.3.20 Inverse Matrix (inv) . . . . . . . . . . . . . . . . . . . . . . . . . . 122 2.3.21 Orthogonal Matrix (orth) . . . . . . . . . . . . . . . . . . . . . . . 123 2.3.22 Rank of Matrix (rank) . . . . . . . . . . . . . . . . . . . . . . . . . 125 2.3.23 Eigenvalues & Eigenvectors (spec) . . . . . . . . . . . . . . . . . . 126 2.3.24 Square Root of Matrix . . . . . . . . . . . . . . . . . . . . . . . . . 128 2.3.25 Hermitian Factorisation (sqroot) . . . . . . . . . . . . . . . . . . . 130 2.3.26 Signaular Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 2.3.27 Singular Value Approximation (sva) . . . . . . . . . . . . . . . . . 131 2.3.28 Singular Value Decomposition (svd) . . . . . . . . . . . . . . . . . 131 2.3.29 Trace of Matrix (trace) . . . . . . . . . . . . . . . . . . . . . . . . 135 3 Calculus 137 3.1 Derivative Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 3.1.1 Derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 3.1.2 Numeric Derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 3.1.3 Numeric Difference . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 3.1.4 Function Evaluation (feval) . . . . . . . . . . . . . . . . . . . . . . 138 3.2 Integral Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 3.2.1 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 3.2.2 Double Integral (int2d) . . . . . . . . . . . . . . . . . . . . . . . . 140 3.2.3 Tripple Integration (int3d) . . . . . . . . . . . . . . . . . . . . . . 141 3.2.4 Integrate (integrate) . . . . . . . . . . . . . . . . . . . . . . . . . . 143 3.2.5 Definite Integration (intg) . . . . . . . . . . . . . . . . . . . . . . . 143 3.2.6 Cauchy’s Integration (intc) . . . . . . . . . . . . . . . . . . . . . . 143 3.2.7 Cauchy Integration (intl) . . . . . . . . . . . . . . . . . . . . . . . 146 3.3 Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 3.3.1 Ordinary Differential Equation (ode) . . . . . . . . . . . . . . . . . 148 3.3.2 Differential Algebraic System Solver (dassl) . . . . . . . . . . . . . 150 4 Elementary Functions 157 4.1 Data Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 4.1.1 Comparison of Data . . . . . . . . . . . . . . . . . . . . . . . . . . 157 4.1.2 Data Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 4.1.3 Creation of Matrix Cell . . . . . . . . . . . . . . . . . . . . . . . . 158 4.1.4 Creation of List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 4.2 Bitwise operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 4.2.1 Bitwise AND (bitand) . . . . . . . . . . . . . . . . . . . . . . . . . 160 4.2.2 Bitwise Complements (bitcmp) . . . . . . . . . . . . . . . . . . . . 160 4.2.3 Get a Position Bit (bitget) . . . . . . . . . . . . . . . . . . . . . . 161 4.2.4 Bitwise OR (bitor) . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 4.2.5 Set Bit In Position (bitset) . . . . . . . . . . . . . . . . . . . . . . 162 4.2.6 Bitwise Exclusive OR (bitxor) . . . . . . . . . . . . . . . . . . . . 162 4.3 Complex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 4.3.1 Complex Number (complex) . . . . . . . . . . . . . . . . . . . . . . 163 4.3.2 Complex Imaginary (imag) . . . . . . . . . . . . . . . . . . . . . . 163 4.3.3 Iota Multiplication (imult) . . . . . . . . . . . . . . . . . . . . . . 164
  • 7. 7 4.3.4 Is Real (isreal) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 4.3.5 Complex Real (real) . . . . . . . . . . . . . . . . . . . . . . . . . . 164 4.3.6 Complex Conjugate (conj) . . . . . . . . . . . . . . . . . . . . . . . 164 4.4 Discrete mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 4.4.1 Binomials (binomial) . . . . . . . . . . . . . . . . . . . . . . . . . . 165 4.4.2 Factors (factor) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 4.4.3 Factorial (factorial) . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 4.4.4 Permutations (perms) . . . . . . . . . . . . . . . . . . . . . . . . . 166 4.4.5 Primes (primes) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 4.5 Floating point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 4.5.1 Ceiling To (ceil) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 4.5.2 Double (double) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 4.5.3 Number as Integer (int8) . . . . . . . . . . . . . . . . . . . . . . . 167 4.5.4 Fix to Zero (fix) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 4.5.5 Round to Lower Integer (floor) . . . . . . . . . . . . . . . . . . . . 168 4.5.6 Base 2 Exponent (frexp) . . . . . . . . . . . . . . . . . . . . . . . . 169 4.5.7 Integer (int) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 4.5.8 Whether Infinity (isinf) . . . . . . . . . . . . . . . . . . . . . . . . 169 4.5.9 Whether Not a Number (isnan) . . . . . . . . . . . . . . . . . . . . 170 4.5.10 Near Float (nearfloat) . . . . . . . . . . . . . . . . . . . . . . . . . 170 4.5.11 Round (round) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 4.6 Number Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 4.6.1 Conversion About Any Base (base2dec) . . . . . . . . . . . . . . . 170 4.6.2 Binary to Decimal (bin2dec) . . . . . . . . . . . . . . . . . . . . . 171 4.6.3 Decimal to Binary (dec2bin) . . . . . . . . . . . . . . . . . . . . . 171 4.6.4 Decimal To Hexadecimal (dec2hex) . . . . . . . . . . . . . . . . . . 171 4.6.5 Decimal to Octal (dec2oct) . . . . . . . . . . . . . . . . . . . . . . 172 4.6.6 Hexadecimal to Decimal (hex2dec) . . . . . . . . . . . . . . . . . . 172 4.6.7 Octal to Decimal (oct2dec) . . . . . . . . . . . . . . . . . . . . . . 172 4.7 Set operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 4.7.1 Intersect (intersect) . . . . . . . . . . . . . . . . . . . . . . . . . . 173 4.7.2 Sorted Difference (setdiff) . . . . . . . . . . . . . . . . . . . . . . . 173 4.7.3 Union of Sets (union) . . . . . . . . . . . . . . . . . . . . . . . . . 174 4.7.4 Unique Component (unique) . . . . . . . . . . . . . . . . . . . . . 175 4.8 Trigonometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 4.8.1 Inverse Trigonometric Functions . . . . . . . . . . . . . . . . . . . 176 Inverse Sine in Radian (asin) . . . . . . . . . . . . . . . . . . . . . 176 Inverse Sine in Degree (asind) . . . . . . . . . . . . . . . . . . . . . 176 Inverse Hyperbolic Sine (asinh) . . . . . . . . . . . . . . . . . . . . 176 Matrix Inverse Hyperbolic Sine (asinhm) . . . . . . . . . . . . . . 177 Matrix Inverse Sine (asinm) . . . . . . . . . . . . . . . . . . . . . . 177 Inverse Cosine in Radian (acos) . . . . . . . . . . . . . . . . . . . . 177 Inverse Cosine In Degree (acosd) . . . . . . . . . . . . . . . . . . . 177 Inverse Hyperbolic Cosine (acosh) . . . . . . . . . . . . . . . . . . 178 Matrix Inverse Hyperbolic Cosine (acoshm) . . . . . . . . . . . . . 178 Matrix Inverse Cosine (acosm) . . . . . . . . . . . . . . . . . . . . 179 Inverse Tangent in Radian (atan) . . . . . . . . . . . . . . . . . . . 179
  • 8. 8 Inverse Tangent in Degree (atand) . . . . . . . . . . . . . . . . . . 179 Inverse Hyperbolic Tangent (atanh) . . . . . . . . . . . . . . . . . 179 Matrix Inverse Hyperbolic Tangent (atanhm) . . . . . . . . . . . . 180 Matrix Inverse Tangent (atanm) . . . . . . . . . . . . . . . . . . . 180 Inverse Cotangent in Radian(acot) . . . . . . . . . . . . . . . . . . 180 Inverse Cotangent in Degree (acotd) . . . . . . . . . . . . . . . . . 181 Inverse Hyperbolic Cotangent (acoth) . . . . . . . . . . . . . . . . 181 Inverse Secant in Radian (asec) . . . . . . . . . . . . . . . . . . . . 181 Inverse Secant in Degree (asecd) . . . . . . . . . . . . . . . . . . . 182 Inverse Hyperbolic Secant (asech) . . . . . . . . . . . . . . . . . . 182 Inverse Cosecant in Radian (acsc) . . . . . . . . . . . . . . . . . . 182 Inverse Cosecant in Degree (acscd) . . . . . . . . . . . . . . . . . . 183 Inverse Hyperbolic Cosecant (acsch) . . . . . . . . . . . . . . . . . 183 4.8.2 Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . . . . 183 Sine - Argument in Radian (sin) . . . . . . . . . . . . . . . . . . . 183 Cardinal Sine (sinc) . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Sine - Argument in Degree (sind) . . . . . . . . . . . . . . . . . . . 184 Hyperbolic Sine (sinh) . . . . . . . . . . . . . . . . . . . . . . . . . 185 Matrix Hyperbolic Sine (sinhm) . . . . . . . . . . . . . . . . . . . 185 Matrix Sine (sinm) . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Cosine - Argument In Radian (cos) . . . . . . . . . . . . . . . . . . 186 Cosine - Argument In Degree (cosd) . . . . . . . . . . . . . . . . . 186 Hyperbolic Cosine (cosh) . . . . . . . . . . . . . . . . . . . . . . . 186 Matrix Hyperbolic Cosine (coshm) . . . . . . . . . . . . . . . . . . 186 Matrix Cosine (cosm) . . . . . . . . . . . . . . . . . . . . . . . . . 187 Tangent - Argument in Radian (tan) . . . . . . . . . . . . . . . . . 187 Tangent - Argument in Degree (tand) . . . . . . . . . . . . . . . . 187 Hyperbolic Tangent (tanh) . . . . . . . . . . . . . . . . . . . . . . 187 Matrix Hyperbolic Tangent (tanhm) . . . . . . . . . . . . . . . . . 188 Matrix Tangent (tanm) . . . . . . . . . . . . . . . . . . . . . . . . 188 Cotangent - Argument in Degree (cotd) . . . . . . . . . . . . . . . 188 Hyperbolic Cotangent (coth) . . . . . . . . . . . . . . . . . . . . . 188 Matrix Hyperbolic Cotangent (cothm) . . . . . . . . . . . . . . . . 189 Secant - Argument in Radian (sec) . . . . . . . . . . . . . . . . . . 189 Secant - Argument in Degree (secd) . . . . . . . . . . . . . . . . . 189 Hyperbolic Secant (sech) . . . . . . . . . . . . . . . . . . . . . . . 189 Cosecant - Input in Radian (csc) . . . . . . . . . . . . . . . . . . . 190 Cosecant - Input in Degree (cscd) . . . . . . . . . . . . . . . . . . 190 Hyperbolic Cosecant (csch) . . . . . . . . . . . . . . . . . . . . . . 190 4.9 Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 4.9.1 Absolute (abs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 4.9.2 Concatenate (cat) . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 4.9.3 Cell Array to Matrix (cell2mat) . . . . . . . . . . . . . . . . . . . . 191 4.9.4 Cell String (cellstr) . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 4.9.5 Integer to Char (char) . . . . . . . . . . . . . . . . . . . . . . . . . 192 4.9.6 Elliptical Integral (delip) . . . . . . . . . . . . . . . . . . . . . . . 192 4.9.7 Differentiation (diff) . . . . . . . . . . . . . . . . . . . . . . . . . . 193
  • 9. 9 4.9.8 Exponential (exp) . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 4.9.9 Exponential Matrix (expm) . . . . . . . . . . . . . . . . . . . . . . 195 4.9.10 Interpolation (inttrap) . . . . . . . . . . . . . . . . . . . . . . . . . 197 4.9.11 Is Variable Defined (isdef) . . . . . . . . . . . . . . . . . . . . . . . 198 4.9.12 Is Variable Empty (isempty) . . . . . . . . . . . . . . . . . . . . . 198 4.9.13 Variables Are Equal (isequal) . . . . . . . . . . . . . . . . . . . . . 198 4.9.14 Bitwise Equality (isequalbitwise) . . . . . . . . . . . . . . . . . . . 199 4.9.15 Whether Vector (isvector) . . . . . . . . . . . . . . . . . . . . . . . 199 4.9.16 List Size (lstsize) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 4.9.17 Maximum (max) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 4.9.18 Minimum (min) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 4.9.19 Modulus (modulo) . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 4.9.20 Array Dimension (ndims) . . . . . . . . . . . . . . . . . . . . . . . 200 4.9.21 Signum Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 Signum of Matrix (sign) . . . . . . . . . . . . . . . . . . . . . . . . 201 Signum Matrix (signm) . . . . . . . . . . . . . . . . . . . . . . . . 202 Complex Sign (csgn) . . . . . . . . . . . . . . . . . . . . . . . . . . 202 4.9.22 Object Size (size) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 4.9.23 Square Root (sqrt) . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 4.9.24 Square Wave (squarewave) . . . . . . . . . . . . . . . . . . . . . . 203 4.9.25 Object Type (typeof) . . . . . . . . . . . . . . . . . . . . . . . . . 204 4.10 Logarithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 4.10.1 Natural Logarithm (log) . . . . . . . . . . . . . . . . . . . . . . . . 205 4.10.2 Logarithm Base ‘10’ (log10) . . . . . . . . . . . . . . . . . . . . . . 205 4.10.3 Increment & Logarithm (log1p) . . . . . . . . . . . . . . . . . . . . 206 4.10.4 Logarithm Base ‘2’ (log2) . . . . . . . . . . . . . . . . . . . . . . . 206 4.10.5 Matrixwise Logarithm (logm) . . . . . . . . . . . . . . . . . . . . . 206 4.11 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 4.11.1 Lineary Interpolation (interp1) . . . . . . . . . . . . . . . . . . . . 207 4.11.2 Two Data Linear Interpolation (interpln) . . . . . . . . . . . . . . 207 4.11.3 Linear Interpolation (linear interpn) . . . . . . . . . . . . . . . . . 208 4.12 Symbolic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 4.12.1 Symbolic Addition (addf) . . . . . . . . . . . . . . . . . . . . . . . 209 4.12.2 Symbolic Left Division (ldivf) . . . . . . . . . . . . . . . . . . . . . 209 4.12.3 Symbolic Multiplication (mulf) . . . . . . . . . . . . . . . . . . . . 209 4.12.4 Symbolic Right Division (rdivf) . . . . . . . . . . . . . . . . . . . . 209 4.12.5 Symbolie Subtraction (subf) . . . . . . . . . . . . . . . . . . . . . . 210 5 Special Functions 211 5.1 Bessel Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 5.1.1 Bessel Function of Second Kind (besselj) . . . . . . . . . . . . . . . 211 5.1.2 Bessel Function of Second Kind (bessely) . . . . . . . . . . . . . . 211 5.1.3 Bessel Function of First Kind (besseli) . . . . . . . . . . . . . . . . 212 5.1.4 Hyperbolic Bessel Function of Second Kind (besselk) . . . . . . . . 212 5.1.5 Bessel Function as Hankel Function (besselh) . . . . . . . . . . . . 213 5.2 Beta Function (beta) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 5.3 Gamma Function (gamma) . . . . . . . . . . . . . . . . . . . . . . . . . . 213
  • 10. 10 5.3.1 Logarithm of Gamma Function (gammaln) . . . . . . . . . . . . . 214 5.4 Legendre Function (legendre) . . . . . . . . . . . . . . . . . . . . . . . . . 214 5.5 Error Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 5.5.1 Calculate Error (calerf) . . . . . . . . . . . . . . . . . . . . . . . . 214 5.5.2 Error Function (erf) . . . . . . . . . . . . . . . . . . . . . . . . . . 215 5.5.3 Complementary Error Function (erfc) . . . . . . . . . . . . . . . . 216 5.5.4 Inverse Error Function (erfinv) . . . . . . . . . . . . . . . . . . . . 216 6 Directory & Files 217 6.1 Directory Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 6.1.1 Change Directory (chdir) . . . . . . . . . . . . . . . . . . . . . . . 217 6.1.2 Create Directory (createdir) . . . . . . . . . . . . . . . . . . . . . . 217 6.1.3 List Current Directory (dir) . . . . . . . . . . . . . . . . . . . . . . 217 6.1.4 Whether A Directory (isdir) . . . . . . . . . . . . . . . . . . . . . . 218 6.1.5 List Current Directory (ls) . . . . . . . . . . . . . . . . . . . . . . 218 6.1.6 Make Directory (mkdir) . . . . . . . . . . . . . . . . . . . . . . . . 218 6.1.7 Present Working Directory (pwd) . . . . . . . . . . . . . . . . . . . 218 6.1.8 Remove Directory (removedir) . . . . . . . . . . . . . . . . . . . . 219 6.1.9 Remove Directory (rmdir) . . . . . . . . . . . . . . . . . . . . . . . 219 6.1.10 Base Name of File (basename) . . . . . . . . . . . . . . . . . . . . 219 6.1.11 Directory name (dirname) . . . . . . . . . . . . . . . . . . . . . . . 219 6.1.12 Extension Name (fileext) . . . . . . . . . . . . . . . . . . . . . . . 220 6.1.13 Parts of File (fileparts) . . . . . . . . . . . . . . . . . . . . . . . . . 220 6.1.14 Path Separator (filesep) . . . . . . . . . . . . . . . . . . . . . . . . 220 6.1.15 Fill File Name (fullfile) . . . . . . . . . . . . . . . . . . . . . . . . 220 6.1.16 Full File Path (fullpath) . . . . . . . . . . . . . . . . . . . . . . . . 221 6.1.17 Drives In System (getdrives) . . . . . . . . . . . . . . . . . . . . . 221 6.1.18 Temporary Name (tempname) . . . . . . . . . . . . . . . . . . . . 221 6.2 file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 6.2.1 Open a file (file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 6.2.2 Close a file (file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 6.2.3 Copy File (copyfile) . . . . . . . . . . . . . . . . . . . . . . . . . . 222 6.2.4 Delete File (deletefile) . . . . . . . . . . . . . . . . . . . . . . . . . 223 6.2.5 File Information (fileinfo) . . . . . . . . . . . . . . . . . . . . . . . 223 6.2.6 Search Files (findfiles) . . . . . . . . . . . . . . . . . . . . . . . . . 223 6.2.7 Write Matrix to File (fprintfMat) . . . . . . . . . . . . . . . . . . . 223 6.2.8 Read Matrix from File (fscanfMat) . . . . . . . . . . . . . . . . . . 223 6.2.9 Is It A File (isfile) . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 6.2.10 Close a File Stream (mclose) . . . . . . . . . . . . . . . . . . . . . 224 6.2.11 Delete a File (mdelete) . . . . . . . . . . . . . . . . . . . . . . . . . 224 6.2.12 Check End of File (meof) . . . . . . . . . . . . . . . . . . . . . . . 224 6.2.13 Write Data to File (mfprintf) . . . . . . . . . . . . . . . . . . . . . 224 6.2.14 Read Data Stream (mfscanf) . . . . . . . . . . . . . . . . . . . . . 225 6.2.15 Read Line By Line (mgetl) . . . . . . . . . . . . . . . . . . . . . . 225 6.2.16 Open File Stream (mopen) . . . . . . . . . . . . . . . . . . . . . . 225 6.2.17 Move File (movefile) . . . . . . . . . . . . . . . . . . . . . . . . . . 226 6.2.18 Write Bytes to Stream (mput) . . . . . . . . . . . . . . . . . . . . 226
  • 11. 11 6.2.19 Current Position of Binary File (mseek) . . . . . . . . . . . . . . . 227 6.2.20 Length of Passed Data (mtell) . . . . . . . . . . . . . . . . . . . . 228 6.2.21 Environment (getenv) . . . . . . . . . . . . . . . . . . . . . . . . . 228 6.2.22 Process ID (getpid) . . . . . . . . . . . . . . . . . . . . . . . . . . 228 6.2.23 Stop Execution (halt) . . . . . . . . . . . . . . . . . . . . . . . . . 229 6.2.24 Prompt The Message (input) . . . . . . . . . . . . . . . . . . . . . 229 6.2.25 Read From a File (read) . . . . . . . . . . . . . . . . . . . . . . . . 229 6.2.26 Set Environment (setenv) . . . . . . . . . . . . . . . . . . . . . . . 229 6.2.27 Write Formatted Output to File (write) . . . . . . . . . . . . . . . 230 7 Strings 231 7.1 String Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 7.1.1 ASCII . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 7.1.2 Blanks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 7.1.3 Convret To String (convstr) . . . . . . . . . . . . . . . . . . . . . . 231 7.1.4 Empty String (emptystr) . . . . . . . . . . . . . . . . . . . . . . . 231 7.1.5 Evaluate (eval) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 7.1.6 Array Index (grep) . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 7.1.7 Is Argument Alphabets or Numeric (isalphanum) . . . . . . . . . . 232 7.1.8 Is Argument Digit (isdigit) . . . . . . . . . . . . . . . . . . . . . . 232 7.1.9 Is Argument Letter (isletter) . . . . . . . . . . . . . . . . . . . . . 233 7.1.10 Is Argument Number (isnum) . . . . . . . . . . . . . . . . . . . . . 233 7.1.11 Length of Object (length) . . . . . . . . . . . . . . . . . . . . . . . 233 7.1.12 Part of String (part) . . . . . . . . . . . . . . . . . . . . . . . . . . 234 7.2 String Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 7.2.1 Concatenate String (strcat) . . . . . . . . . . . . . . . . . . . . . . 235 7.2.2 First Character Matching (strchr) . . . . . . . . . . . . . . . . . . 236 7.2.3 Compare String (strcmp) . . . . . . . . . . . . . . . . . . . . . . . 236 7.2.4 Case Independent Comparing (strcmpi) . . . . . . . . . . . . . . . 237 7.2.5 Trim Blanks (stripblanks) . . . . . . . . . . . . . . . . . . . . . . . 237 7.2.6 Copy Specific Parts (strncpy) . . . . . . . . . . . . . . . . . . . . . 237 7.2.7 Sub-String From Reverse (strrchr) . . . . . . . . . . . . . . . . . . 238 7.2.8 Reverse String (strrev) . . . . . . . . . . . . . . . . . . . . . . . . . 238 7.2.9 Explode String (strsplit) . . . . . . . . . . . . . . . . . . . . . . . . 238 7.2.10 Locate Substring (strstr) . . . . . . . . . . . . . . . . . . . . . . . 239 7.2.11 String to Double (strtod) . . . . . . . . . . . . . . . . . . . . . . . 239 7.2.12 Tokenise Splitting (strtok) . . . . . . . . . . . . . . . . . . . . . . . 240 7.2.13 Position of Token (tokenpos) . . . . . . . . . . . . . . . . . . . . . 240 7.3 Data File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 7.3.1 CSV Default (csvDefault) . . . . . . . . . . . . . . . . . . . . . . . 240 7.3.2 CSV Write (csvWrite) . . . . . . . . . . . . . . . . . . . . . . . . . 241 7.3.3 CSV Read (csvRead) . . . . . . . . . . . . . . . . . . . . . . . . . . 241 7.3.4 Read Excel File (readxls) . . . . . . . . . . . . . . . . . . . . . . . 242 7.3.5 Scan CSV Test (csvTextScan) . . . . . . . . . . . . . . . . . . . . . 242
  • 12. 12 8 GUI 245 8.1 Graphics User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 8.1.1 Add To Menu (addmenu) . . . . . . . . . . . . . . . . . . . . . . . 245 8.1.2 Close Figure (close) . . . . . . . . . . . . . . . . . . . . . . . . . . 247 8.1.3 Delete From Menu (delmenu) . . . . . . . . . . . . . . . . . . . . . 247 8.1.4 Create Window (createWindow) . . . . . . . . . . . . . . . . . . . 247 8.1.5 GUI Controls (uicontrol) . . . . . . . . . . . . . . . . . . . . . . . 248 8.1.6 Open Directory (uigetdir) . . . . . . . . . . . . . . . . . . . . . . . 252 8.1.7 Get Color (uigetcolor) . . . . . . . . . . . . . . . . . . . . . . . . . 252 8.1.8 Create Figure (figure) . . . . . . . . . . . . . . . . . . . . . . . . . 253 8.1.9 Get Value (getvalue) . . . . . . . . . . . . . . . . . . . . . . . . . . 253 8.1.10 Message Box (messagebox) . . . . . . . . . . . . . . . . . . . . . . 255 8.1.11 Print Figure (printfigure) . . . . . . . . . . . . . . . . . . . . . . . 255 8.1.12 Progression Bar (progressionbar) . . . . . . . . . . . . . . . . . . . 255 8.1.13 Set Menu (setmenu) . . . . . . . . . . . . . . . . . . . . . . . . . . 256 8.1.14 Set Unset Toolbar (toolbar) . . . . . . . . . . . . . . . . . . . . . . 256 8.1.15 Un-Set Menu (unsetmenu) . . . . . . . . . . . . . . . . . . . . . . . 256 8.1.16 Create Node (uiCreateNode) . . . . . . . . . . . . . . . . . . . . . 256 8.1.17 Delete Node (uiDeleteNode) . . . . . . . . . . . . . . . . . . . . . . 257 8.1.18 Create Tree (uiCreateTree) . . . . . . . . . . . . . . . . . . . . . . 257 8.1.19 Concate Tree (uiConcatTree) . . . . . . . . . . . . . . . . . . . . . 259 8.1.20 Menu in Figure (uimenu) . . . . . . . . . . . . . . . . . . . . . . . 262 8.1.21 Display Tree (uiDisplayTree) . . . . . . . . . . . . . . . . . . . . . 263 8.1.22 File Open Dialog (uigetfile) . . . . . . . . . . . . . . . . . . . . . . 263 8.1.23 Item of Menu (uimenu) . . . . . . . . . . . . . . . . . . . . . . . . 263 8.1.24 Open File Box (uiputfile) . . . . . . . . . . . . . . . . . . . . . . . 264 8.1.25 Wait Bar (waitbar) . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 8.1.26 Choice Box (x choices) . . . . . . . . . . . . . . . . . . . . . . . . . 265 8.1.27 Input Dialog Box (x dialog) . . . . . . . . . . . . . . . . . . . . . . 265 8.1.28 Matrix Editing Window (x matrix) . . . . . . . . . . . . . . . . . . 266 8.1.29 Matrix Dialog Box (x mdialog) . . . . . . . . . . . . . . . . . . . . 266 9 Graphics 267 9.1 2D Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 9.1.1 Function Plot (plot) . . . . . . . . . . . . . . . . . . . . . . . . . . 267 9.1.2 New Axes (newaxes) . . . . . . . . . . . . . . . . . . . . . . . . . . 267 9.1.3 Line Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 9.1.4 Surface Plot (Sfgrayplot) . . . . . . . . . . . . . . . . . . . . . . . 269 9.1.5 Colour Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 Colour Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 Colour Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 Get Colour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273 9.1.6 Coloured Surface Plot (Sgrayplot) . . . . . . . . . . . . . . . . . . 273 9.1.7 Arrow Plot (champ) . . . . . . . . . . . . . . . . . . . . . . . . . . 273 9.1.8 Coloured Arrow Plot (champ1) . . . . . . . . . . . . . . . . . . . . 277 9.1.9 Comet Plot (comet) . . . . . . . . . . . . . . . . . . . . . . . . . . 278 9.1.10 2D Contours (contour2d) . . . . . . . . . . . . . . . . . . . . . . . 278
  • 13. 13 9.1.11 Filled Contour (contourf) . . . . . . . . . . . . . . . . . . . . . . . 283 9.1.12 Error Bar Plot (errbar) . . . . . . . . . . . . . . . . . . . . . . . . 284 9.1.13 Histogram (histplot) . . . . . . . . . . . . . . . . . . . . . . . . . . 285 9.1.14 Animated Parametric Plot (paramfplot2d) . . . . . . . . . . . . . . 287 9.1.15 2D Plot (plot2d) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288 9.1.16 2D Step Plot (plot2d2) . . . . . . . . . . . . . . . . . . . . . . . . 290 9.1.17 2D Vertical Plot (plot2d3) . . . . . . . . . . . . . . . . . . . . . . . 291 9.1.18 2D Arrow Plot (plot2d4) . . . . . . . . . . . . . . . . . . . . . . . 292 9.1.19 Polar Plot (polarplot) . . . . . . . . . . . . . . . . . . . . . . . . . 293 9.2 3D Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 9.2.1 3D Function Plot (plot3d) . . . . . . . . . . . . . . . . . . . . . . . 295 9.2.2 3D Level Plot (plot3d1) . . . . . . . . . . . . . . . . . . . . . . . . 298 9.2.3 3D Rectangular Plot (plot3d2) . . . . . . . . . . . . . . . . . . . . 298 9.2.4 3D Surface Plot (plot3d3) . . . . . . . . . . . . . . . . . . . . . . . 298 9.2.5 3D Comet (comet3d) . . . . . . . . . . . . . . . . . . . . . . . . . . 298 9.2.6 3D Contours (contour) . . . . . . . . . . . . . . . . . . . . . . . . . 299 9.2.7 3D Histogram (hist3d) . . . . . . . . . . . . . . . . . . . . . . . . . 299 9.2.8 3D Parametric Plot (param3d) . . . . . . . . . . . . . . . . . . . . 300 9.3 Sub Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 9.4 Annotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 9.4.1 Captions (caption) . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 9.4.2 Legend (legend) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 9.4.3 Title (title) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 9.4.4 Axis Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 9.5 Bar Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 9.5.1 Vertical Bars (bar) . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 9.5.2 Horizontal Bars (barh) . . . . . . . . . . . . . . . . . . . . . . . . . 304 9.6 Geometric Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 9.6.1 Arcs (xarc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 9.6.2 Arrows (xarrows) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 9.6.3 Fill Arcs (xfarc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 9.6.4 Fill Rectangle (xfrect) . . . . . . . . . . . . . . . . . . . . . . . . . 307 9.6.5 Draw Rectangle (xrect) . . . . . . . . . . . . . . . . . . . . . . . . 307 9.7 Pie Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 9.7.1 Pie (pie) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 9.8 Polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 9.8.1 Fill Polygon (xfpoly) . . . . . . . . . . . . . . . . . . . . . . . . . . 309 9.9 Fetching Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 9.9.1 Get Current Figure (gcf) . . . . . . . . . . . . . . . . . . . . . . . 311 9.9.2 Set Current Figure (scf) . . . . . . . . . . . . . . . . . . . . . . . . 311 9.9.3 Delete Current Graphics (xdel) . . . . . . . . . . . . . . . . . . . . 311 9.9.4 Get Default Figure (gdf) . . . . . . . . . . . . . . . . . . . . . . . 312 9.9.5 Set Default Figure (sdf) . . . . . . . . . . . . . . . . . . . . . . . . 312 9.9.6 Get Current Axes (gca) . . . . . . . . . . . . . . . . . . . . . . . . 312 9.9.7 Get Default Axes (gda) . . . . . . . . . . . . . . . . . . . . . . . . 313 9.9.8 Set Default Axes (sda) . . . . . . . . . . . . . . . . . . . . . . . . . 313 9.9.9 Set As Current Axes (sca) . . . . . . . . . . . . . . . . . . . . . . . 313
  • 14. 14 9.9.10 Get Current Entity (gce) . . . . . . . . . . . . . . . . . . . . . . . 314 9.10 Property Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 9.10.1 Set Parameters (set) . . . . . . . . . . . . . . . . . . . . . . . . . . 315 9.10.2 Get Parameters (get) . . . . . . . . . . . . . . . . . . . . . . . . . 315 9.10.3 Move Entity (move) . . . . . . . . . . . . . . . . . . . . . . . . . . 315 9.10.4 Copy Entity (copy) . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 9.10.5 Reset Current Graphics (clf) . . . . . . . . . . . . . . . . . . . . . 316 9.10.6 Twinkle Graphics (twinkle) . . . . . . . . . . . . . . . . . . . . . . 316
  • 16.
  • 17. 1.1. INTRODUCTION 17 1Scilab Core In Scilab there are thousands of the ready-made keywords and functions. We will discuss these keywords and function with suitable example(s). 1.1 Introduction Scilab is a strong numerical programming software used for instructions to junior high school students to graduate students. Scilab is written in ‘C’, ‘C++’ and ‘Java’ and its applications are similar to the application of other languages. Unlike ‘C’ Scilab does not required pre-definition of variable. Variables are automatically converted into integer, character etc forms according to the values assigned to them, i.e. a value is assigned to a variable by juggling. If a variable ‘a’ is being added with ‘2’ then the variable ‘a’ would be considered as an integer type variable. But if it is to be added with ‘2.00202201220215’ then variable ‘a’ will be considered as an long type variable i.e. type of a variable is considered as the use of it. Each statement performed internally should be terminated by ‘;’. The statement whose result would be display in output window should not end with ‘;’. Statements, strings and variables are grouped inside a parenthesis brackets, i.e. ‘(’ ... ‘)’. A syntax of a function can be spanned in multiple lines. When a part of syntax is terminated by ‘..’, Scilab waits for remaining part of the syntax passed to it in second line until syntax completion is not encountered. ✞ 1 --> a=( --> 1 3 --> 2 --> ) ✌ ✆ Execution of a function in multiline mode as shown above will produce errors while when above function is modified as ✞ --> a=( .. 2 --> 1 .. --> 2 .. 4 --> ) ✌ ✆ will be executed successfully and result will be ✞ ans = 12 ✌ ✆ Since Scilab 6, declaration of a number in two line is not supported as shown in above example. According to the Code Conventions for the Scilab Programming Language it is recommended: 1. Start each statement on a new line.
  • 18. 18 Scilab Core 2. Write no more than one simple statement per line. 3. Break compound statements over multiple lines. Following example uses two integers 2, 3 & ‘;’ and prints their result at output window. ✞ --> a=2; // Without pre -identification of 2 --> // variable and terminated by ’;’ --> b=3; // Without pre -identification of 4 --> // variable and terminated by ’;’ --> a+b // Sum of two variables is called 6 --> // and line does not terminated by ’;’ ✌ ✆ ✞ ans = 5. ✌ ✆ If result of an operation is not assigned to a variable, then result is automatically assigned to ‘ans’ variable. 1.1.1 Everything As Matrix Numerical programming by Scilab is vector or matrix based computation, therefore each variable has a vector or matrix values. Each element of a variable is identified by its indices. For example, ✞ --> a = 2 // one dimensional vector 2 --> a = [1,2] --> a(1) // first element of vector ✌ ✆ ✞ ans = 1 ✌ ✆ The indices parameters inside the parentheses of variable ‘a’ may be one dimensional, two dimensional or three dimensional. ✞ --> a(1) // One dimensional 2 --> a(1, 2) // Two dimensional --> a(1, 2, 1)// Three dimensional ✌ ✆ In the first line of above codes, first element of vector a is returned. In second line of above codes, element at 1st row (x) and 2nd column (y) is returned. In the third line of above codes, elements at 1st row (x), 2nd column (y) and 1st layer (z) is returned. ✞ 1 --> a = [1,2,3;5,8,4] --> a(2,2) 3 --> b = 56; --> b(1) // First element 5 --> b(2) // Second element . Error!!! ✌ ✆
  • 19. 1.1. INTRODUCTION 19 ✞ a = 1. 2. 3. 5. 8. 4. ans = 8. ans = 56. !--error 21 Invalid index. ✌ ✆ 1.1.2 Approximate Zero Numerical programming languages use double datatype floating point arithmetic. There- fore each number is denoted as a float value, i.e. 1 as 1.000000, 0.5 as 0.500000 etc. Sometime, even zero is represented as 2.5 × 10−18 or as 13.2 × 10−19 etc. These values are very very small and are close to zero. In floating point arithmetic, zero is taken as comparative value rather than absolute value. For example, in numerical calculations, identity matrix is represented as
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. 1 3.5 × 10−12 35 × 10−12 1
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33. where 1 is very large value in comparison to 3.5 × 10−12 or 35 × 10−12 . 1.1.3 Computational Error Numerical software uses iteration to find the numeric solutions. For example, every one knew that sin 90◦ is equal to one. But Numerical Software does not use fixed type values. They uses series solutions, i.e. for sin θ, they uses sine series: sin α = α − α3 3! + α5 5! − . . . Here, α is in radian. This series is valid if infinite number of steps are taken for computa- tion purpose. Computer does not take infinite terms of this series. It limits the number of terms for computation. But, how many terms? If number of terms is less, result shall be other than actual one but computational performance shall be good. And if number of steps is large then result shall be near accurate value but performance shall be compro- mised. Now, the question is that, how many steps shall be taken in this series. It depends on the required significant digits in the result. At the optimal result, the deviation of computed value from the actual one is called computational error. For the above series, we shall compute value for three terms and four terms, and corresponding results shall be compared. For Three Terms sin π 2 = 22 14 − 22 14 3 3! + 22 14 5 5!
  • 34. 20 Scilab Core Or sin π 2 = 1.5714286 − 0.6467444 + 0.0798531 It gives sin 90◦ = 1.0045373. For Four Terms sin π 2 = 22 14 − 22 14 3 3! + 22 14 5 5! − 22 14 7 7! Or sin π 2 = 1.5714286 − 0.6467444 + 0.0798531 − 0.0046950 It gives sin 90◦ = 0.9998423. It is seen here, the value oscillates about one as the number of terms increases and tends to one when number of terms are infinite. Numerical Software use sufficient long steps so that result is near to accurate result or upto desired significant digits. Now, computational error is difference between exact value of sin 90◦ and computed value. In first case computational error is 1 − 1.0045373, i.e. −0.0045373 and in second case, computational error is 1 − 0.9998423, i.e. 0.0001577. Error In Calculus In calculus, definite integration of a function is carried out by two ways. (i) By using first principle method and (ii) By using direct method. For example, I = Z 1 0 x dx may be solved by two ways. In first method, take dx = 0.1. It gives, n = b − a dx = 10 and x are computed by a + n × dx where a is lower limit of integration. I = 0 × 0.1 + 0.1 × 0.1 + . . . + 0.8 × 0.1 + 0.9 × 0.1 On solving it, we have I = 0 + 0.01 + 0.02 + 0.03 + 0.04 + 0.05 + 0.06 + 0.07 + 0.08 + 0.09 = 0.45 From direct method, I = Z 1 0 x dx = x2 2
  • 35.
  • 36.
  • 37.
  • 38. 1 0 = 0.5 Now, the computational error by two methods is 0.50 − 0.45 = 0.05. So, computational errors, not only occur due to selection of number of steps but they also occur when we select different types of solution methods. 1.2 Simple Arithmetic Before we start the expertise application of Scilab in numerical programming, we first be hands out with simple mathematical applications like addition, subtraction, multiplica- tion, division, scoping and application of inbuilt functions.
  • 39. 1.2. SIMPLE ARITHMETIC 21 1.2.1 Addition Arithmetic addition is the summation of two or more numbers. Scilab obeys the simple arithmetic rules of addition. In the following example, two variables are declared and assigned some values. When we called addition by variable method, we got desired result. Remember, to print the result of a step of operation, it shall not terminated with ‘;’ (semi-colon). If you do so, the result shall be assigned to default answer variable ans without displaying it in output console. ✞ -- a=10; 2 -- b=10; -- a+b ✌ ✆ ✞ ans = 20. ✌ ✆ The default output in Scilab is a float or a double. A float number has fraction parts, i.e. fraction part succeed to decimal symbol (.). Numbers without (.) are pure integers. int8(x) converts a float or double number (x) into integer number by truncating its fraction part. ✞ -- a=10.5; 2 -- b=10.3; -- int8 (a+b) ✌ ✆ ✞ ans = 20 ✌ ✆ We can make symbolic addition of two numbers too. But before doing so, string or characters are defined as variable by using poly function of zero order. The first argument of poly function is degree of equation and ‘b’ is symbolic variable. ✞ -- a=10; 2 -- // poly (degree of eqn ,symbol ) -- b=poly (0,’b’); 4 -- a+b ✌ ✆ ✞ ans = b + 10 ✌ ✆ sum function does not takes inputs to be summed, but it accepts a vector or matrix as its argument. It adds vector elements or elements of a matrix cumulatively. Elements of vector or matrix are constructed by using ‘:’ (colon) loop operator twice. First argument of colon loop is initial limit of the array, second argument is iteration step increment after a loop and third argument is upper limit of the array. ✞ -- a=1:1:5 ✌ ✆
  • 40. 22 Scilab Core ✞ ans = 1. 2. 3. 4. 5. ✌ ✆ The sum of array elements ✞ -- a=1:1:10; 2 -- sum(a) ✌ ✆ ✞ ans = 55 ✌ ✆ abs function is used to return the absolute value of a number x. When x is complex, abs(x) is the complex modulus (magnitude) of the elements of x. Mathematically abs(x) = |x| 1.2.2 Subtraction Arithmetic subtraction is the difference of two or more numbers. In standard form of subtraction, second operand is subtracted from first operand of subtraction operator (– ). The result may be positive or negative. If there are several consecutive subtraction without scope operators then LEFT-TO-RIGHT order of subtraction is followed. ✞ -- a=10; 2 -- b=10; -- c=10; 4 -- a-b-c ✌ ✆ ✞ ans = -10. ✌ ✆ We can also make symbolic subtraction of two numbers similar to the symbolic addition as explained above. ✞ -- a=10; 2 -- // poly (degree of eqn , symbol ) -- b=poly (0,’b’); 4 -- a-b ✌ ✆ ✞ ans = -b + 10 ✌ ✆ 1.2.3 Multiplication Arithmetic multiplication in Scilab is performed by asterisk operator (*). If there are several consecutive multiplication without scope operators then LEFT-TO-RIGHT order of multiplication is followed.
  • 41. 1.2. SIMPLE ARITHMETIC 23 ✞ -- 2*3*4*5 ✌ ✆ ✞ ans = 120. ✌ ✆ Cumulative array product of array elements can be performed by prod() function. See the example given below: ✞ -- a=1:1:10; 2 -- prod (a) ✌ ✆ ✞ ans = 3628800. ✌ ✆ 1.2.4 Division Arithmetic division in Scilab is denoted by forward slash. ✞ -- 2/3 ✌ ✆ ✞ ans = 0.6666667 ✌ ✆ The answer is in ten digit form. We can control the decimal places by using the function format() function by supplying format code and number of fraction digits as its arguments. ✞ -- format(’v’ ,4) ✌ ✆ Where ‘v’ is abbreviation of ‘variable’ and integer 4 controls the number of digits in answer. It does also meant that, the fourth digit shall also be rounded up. ✞ 1 -- format(’v’ ,4) -- 2/3 ✌ ✆ ✞ ans = 0.7 ✌ ✆ Changing the format of numbers kept in effective until Scilab session is not reset or it is not restarted. 1.2.5 Scoping The simple arithmetic, withing same scoping/grouping is performed according to BOD- MAS rule. It is an acronym for Bracket, Of, Division, Multiplication, Addition and
  • 42. 24 Scilab Core Subtraction. Mathematical grouping is very essential to set the procedure of arithmetic operations. For example 1 2 2 = 0.4 But 1 2 2 = 1 Simple use of forward slash as divisor we can’t identify the numerator and denominator of a rational number or of a fractions. Same fractions represented in different way have different answers. This is why in Scilab, scoping/grouping of variables becomes necessary. If scoping/grouping is not in correct form the answer is unpredictable. For example, withough scoping then division of unity by two is ✞ -- 1/2 ✌ ✆ ✞ ans = 0.5 ✌ ✆ And division of half by two is ✞ -- 1/2/2 ✌ ✆ ✞ ans = 0.25 ✌ ✆ Now division of half by half is ✞ -- 1/2/1/2 ✌ ✆ ✞ ans = 0.25 ✌ ✆ It is not required answer as half divided by half must be unity. By scoping each fraction according to our requirement, we have correct answer. ✞ -- (1/2) /(1/2) ✌ ✆ ✞ ans = 1 ✌ ✆ 1.2.6 Square Root (sqrt) If x is a real number then its square root is given by y = √ x. In other words, if y is square root of x, then y2 = x. Roots computed by this function may be real or complex. Square root of negative numbers returned in complex form. In Scilab, square root is a scalar operator and it performs elementwise operation. Square root of a number can be obtained by
  • 43. 1.2. SIMPLE ARITHMETIC 25 ✞ -- sqrt (2) ✌ ✆ ✞ ans = 1.414 ✌ ✆ If argument is a vector, then square root of the vector is a vector of square root of its elements. If argument is a matrix then square root of the matrix is a matrix of square roots of its elements. ✞ -- a=[1 ,2;3 ,4]; 2 -- sqrt (a) ✌ ✆ ✞ ans = 1. 1.4142136 1.7320508 2. ✌ ✆ The algorithm used in computation of the square root of a real value, x, is √ x = e ln(x) 2 1.2.7 Exponent (ˆ Operator) ˆ is called exponent operator. If n is an index or a degree, or power of base x then exponents is represented by xn . If |n| ≥ 1, then exponent means “base is multiplied by itself n times”, and if |n| 1, then it is called nth root of base x. To find the kth root of base number x, we use ˆ operator as xk . ✞ 1 -- 2^(0.33) ✌ ✆ ✞ ans = 1.2570134 ✌ ✆ The output of exponents depends on the values of base and exponent. For example, if either base x or exponent n is less than one, then result is convergent, i.e. result is approaching towards zero. Similarly, if both base x and exponent n are greater than one then result is divergent. If n is one, then result is always base x itself. If base x is one and n is whatever value, then result is always one. If exponent is a complex then it is solved by using logarithm with natural base (e). For example, y = 2i is simplified as log y = log 2i It gives log y = i log 2 ⇒ y = ei log 2 Now, we can simplify right side using relation eiθ = cos θ + i sin θ as y = cos(log 2) + i sin(log 2)
  • 44. 26 Scilab Core Note that, ˆ acts like both, scalar and vector operator with vectors and matrices. If it is used like ‘.ˆ’ then it acts as elementwise operator and if it is used without dot, then it acts as vector operator. ✞ -- a=[1 ,2;3 ,4]; 2 -- a^(0.33) // vector operator ✌ ✆ ✞ ans = 0.6956785 + 0.4728372 i 0.4784401 - 0.2162886 i 0.7176602 - 0.3244328 i 1.4133387 + 0.1484044 i ✌ ✆ ✞ 1 -- a=[1 ,2;3 ,4]; -- a.^(0.33) // scalar operator ✌ ✆ ✞ ans = 1. 1.2570134 1.4369777 1.5800826 ✌ ✆ The algorithm used for computation of exponent is explained here. Assume a matrix of order 2 × 2 A = 1 2 3 4 Now its eigenvalues are given by |A − λI| = 0 i.e.
  • 45.
  • 46.
  • 47.
  • 48. 1 2 3 4 − λ 1 0 0 1
  • 49.
  • 50.
  • 51.
  • 53.
  • 54.
  • 55.
  • 56. 1 − λ 2 3 4 − λ
  • 57.
  • 58.
  • 59.
  • 60. = 0 Or (1 − λ) × (4 − λ) − 6 = 0 On solving it λ = −0.372281; 5.372281 Or eigenvalues in matrix form, when they are arranged in descending order is d = 5.372281 0.000000 0.000000 −0.372281 For λ = 5.372281, eigenvector (v1) is (A − λI)v1 = 0. So, 1 − 5.372281 2 3 4 − 5.372281 x y = 0 −4.372281 2 3 −1.372281 x y = 0
  • 61. 1.2. SIMPLE ARITHMETIC 27 Or −4.372281x + 2y = 0; 3x − 1.372281y = 0 To get solutions, put x = 1 in −4.372281x + 2y = 0, we get the value of y = 2.186140. To get eigenvectors, we shall normalize these two values as x = 1 √ 12 + 2.1861402 ; y = 2.186140 √ 12 + 2.1861402 It gives, x = 0.415973 and y = 0.909376. As coefficients of above two eigenvector equa- tions are of opposite signs, hence values of x and y shall be either both negative or both positive. Now, we shall submit x and y values in equation g = 3x − 1.372281y to get minimum positive value. g = 3 × 0.415973 − 1.372281 × 0.909376 = 0.000000407 Taking sign convention, the other possible set of solution be x = −0.415973 and y = −0.909376. g = 3 × −0.415973 − 1.372281 × −0.909376 = 0.000000407 When x = −0.415973 and y = −0.909376, we have positive f value. This gives first eigenvector corresponding to λ = 5.372281. v1 = −0.415973 −0.909376 For λ = −0.372281, eigenvector (v2) is (A − λI)v2 = 0. So, 1 − (−0.372281) 2 3 4 − (−0.372281) x y = 0 1.372281 2 3 4.372281 x y = 0 Or 1.372281x + 2y = 0; 3x + 4.372281y = 0 As coefficients of above two eigenvector equations are of same signs, hence values of x and y shall be in opposite signs. On solving these two algebraic equations, as explained for λ = 5.372281, we have x = −0.824564 and y = 0.565767 or x = 0.824564 and y = −0.565767. This gives second eigenvector corresponding to λ = −0.372281. v2 = −0.824564 0.565767 The corresponding eigenvector matrix from above two eigenvectors (v1 and v2) is v = −0.415973 −0.824564 −0.909376 0.565767 Note that, each column of eignevectors is arranged to the corresponding eigenvalues. Now, the matrix A can be written as A = v × d × v−1 . The square root of the matrix is given by A 1 2 = v × d 1 2 × v−1
  • 62. 28 Scilab Core 1.2.8 Algebraic Equations Algebraic equations are those equations in which an unknown variable is in linear addition or in linear subtraction in different degrees. Numerical coefficients are multiplied with each terms to give a suitable relation for the unknown variable. To form a linear equation, first define the variable. ✞ 1 -- x=poly (0,’x’); -- f=2*x^2+2 ✌ ✆ f = 2 + 2x2 This algebraic equation is in symbolic form. All the algebraic function may be applicable to this equation. In the following example, function roots() is used to algebraic equation f to gets its all roots. ✞ -- x=poly (0,’x’); 2 -- f=2*x ^2+2; -- roots(f) ✌ ✆ ✞ ans = i - i ✌ ✆ Division of polynomials by a number or by a symbol can also be performed. Note that it returns only quotient of the division. ✞ 1 -- x=poly (0,’x’);// returns only degree 1 polynomial -- f=2*x ^2+2; 3 -- pdiv (f,x), ✌ ✆ ✞ ans = 2x ✌ ✆ LCM (Least Common Multiplier) and HCF (Highest Common Factor) of two algebraic functions can also applicable with the algebraic equations. ✞ -- x=poly (0,’x’); 2 -- f=2*x ^2+2; -- lcm([f,x]) ✌ ✆ ✞ ans = 3 2x + 2x ✌ ✆
  • 63. 1.2. SIMPLE ARITHMETIC 29 In Scilab, HCF is named as GCD (Greatest Common Divisor). ✞ 1 -- x=poly (0,’x’); -- f=2*x ^2+2; 3 -- gcd([f,x]) ✌ ✆ ✞ ans = 1 ✌ ✆ 1.2.9 Logarithm The natural logarithm of number 2 is obtained when this number is supplied as argument to the log function. ✞ -- log (2) ✌ ✆ ✞ ans = 0.6931472 ✌ ✆ Exponential to a number (n) is represented mathematically as en . In Scilab, it is given as ✞ -- exp (2) ✌ ✆ ✞ ans = 7.3890561 ✌ ✆ We may use different bases for logarithms, i.e. base ‘10’, base ‘2’ or natural base ‘e’. Logarithm of a number about base ‘10’ is computed as ✞ -- log10 (2) ✌ ✆ ✞ ans = 0.30103 ✌ ✆ Solved Problem 1.1 Write Scilab code for finding of natural and base ten logarithm of number 2.05 and find their difference. Solution The Scilab codes for the given problem is given below: ✞ -- log (2.05) -log10 (2.05) ✌ ✆ ✞ ans = 0.4060859 ✌ ✆ This is output of the given problem.
  • 64. 30 Scilab Core 1.2.10 Index Expression An index expression allows to scale, select or replace an element from a vector or matrix. Indices may be scalars, vectors, ranges, or the special operator ‘:’, which may be used to select entire rows or columns. Row and column indices, i.e. two parameters, are separated by comma. ✞ -- A(row indices , column indices ) ✌ ✆ When only one parameter is passed to matrix variable to extract the sub matrix, then at first, matrix is arranged in vector form in sequence of column vectors. For example, ✞ 1 -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3] -- A(:) ✌ ✆ ✞ A = 2 3 1 4 5 3 1 8 8 6 7 2 4 5 1 3 ans = 2 5 8 4 3 3 6 5 1 1 7 1 4 8 2 3 ✌ ✆ Now, only one parameter is supplied to vector variable, it is treated as indices for elements and it returns a vector of elements present at that indice. Note that, here index counting started from 1 rather than 0. ✞ -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3] 2 -- A(2) // element at index 2 ✌ ✆ ✞ A = 2 3 1 4 5 3 1 8 8 6 7 2 4 5 1 3
  • 65. 1.2. SIMPLE ARITHMETIC 31 ans = 5 ✌ ✆ Similarly, a range of indices can be given to matrix variable to extract a vector of elements present at that index. In the following example, sub vectors are returned by constructing elements present at indices from index 1 to index 2. There are two different way to pass same indices. ✞ 1 -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3] -- A(1:2) // 1st index to 2nd index 3 -- A([1;2]) // 1st index and 2nd index ✌ ✆ ✞ A = 2 3 1 4 5 3 1 8 8 6 7 2 4 5 1 3 ans = 2 5 ans = 2 5 ✌ ✆ When both parameters are passed to matrix variable, then first parameter is indices for rows and second parameter is for columns. Rows or columns may be discrete indices or range of indices but should not beyond the dimension of the matrix. In this case, matrix is not arranged in sequeces of elements of column vectors. See the below example. ✞ 1 -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3] -- A(2:4 ,3:4) // Row index from 2nd row to 4th row 3 // col index from 3rd col to 4th col ✌ ✆ ✞ A = 2 3 1 4 5 3 1 8 8 6 7 2 4 5 1 3 ans = 1 8 7 2 1 3 ✌ ✆ If both parameters are discrete indices, then row index are recursive for all column indices. See the following example, in which elements at second and third column of first row, and elements at second and third column of fourth row forms a sub matrix. ✞ 1 -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3] -- A([1,4], [2 ,3])// 1st row - 2nd 3rd columns 3 // 4th row - 2nd 3rd columns ✌ ✆
  • 66. 32 Scilab Core ✞ A = 2 3 1 4 5 3 1 8 8 6 7 2 4 5 1 3 ans = 3 1 5 1 ✌ ✆ If same index number is used twice or more in row parameter, i.e. as [1,1], then output sub matrix has two rows as part of row index ‘1’ of the given matrix. ✞ -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3] 2 -- A([1,1], [2 ,3])// 1st row - 2nd 3rd columns // 1th row - 2nd 3rd columns ✌ ✆ ✞ A = 2 3 1 4 5 3 1 8 8 6 7 2 4 5 1 3 ans = 3 1 3 1 ✌ ✆ end operator is used to denote last index of the vector. For example ✞ -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3] 2 -- A(end)// last element of vector ✌ ✆ ✞ A = 2 3 1 4 5 3 1 8 8 6 7 2 4 5 1 3 ans = 3 ✌ ✆ The parameter of matrix variable may be controlled by range indices. For example, odd elements of matrix and even elements of matrix can be extracted by ✞ 1 -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3] -- A(1:2: end) // Odd elements vector 3 -- A(2:2: end) // Even elements vector ✌ ✆ ✞ A = 2 3 1 4 5 3 1 8
  • 67. 1.3. ARITHMETICAL KEYWORDS 33 8 6 7 2 4 5 1 3 ans = 2 8 3 6 1 7 4 2 ans = 5 4 3 5 1 1 8 3 ✌ ✆ 1.3 Arithmetical Keywords Followings are the main keywords used in Scilab. The key by key explanation is given below. 1.3.1 Result Variable (ans) ans means “answer”. This variable is created automatically when expressions are not assigned to any other variable. It is the last un-assigned evaluated value. ✞ 1 -- a=10; -- b=5; 3 -- a+b ✌ ✆ ✞ ans = 15 ✌ ✆ 1.3.2 Left Matrix Division () ‘’ is used for left matrix division. Let A ∗ x = b has a solution of x = Ab. In this expression, succeeding variable to ‘’ is divided by the preceding one. ✞ -- a=10; 2 -- b=5; -- ab ✌ ✆ ✞ ans = 0.5 ✌ ✆ The second example of the backslash command is ✞ -- A=2; 2 -- b=[1;1;1]; -- x=Ab ✌ ✆ ✞ x = 0.5 0.5 0.5 ✌ ✆
  • 68. 34 Scilab Core 1.3.3 Square Brackets ([...]) Square brackets are used to define a vector or a matrix. Each row of a vector or matrix is separated by ‘;’ and each element of a row is separated by ‘,’ (comma) or space. ✞ -- x=[1;2;3] ✌ ✆ ✞ x = 1 2 3 ✌ ✆ A 3 × 3 matrix is written as ✞ -- x=[1 ,2 ,3;4 ,5 ,6;7 ,8 ,9] ✌ ✆ ✞ x = 1 2 3 4 5 6 7 8 9 ✌ ✆ In a row matrix or in a column matrix, elements of the row or matrix may be numbers or function. The elements may be separated by comma or space. In otherwords, functions may be part of the matrix elements. The exact element value of function element is its return value. ✞ -- x=[1 sqrt (-1) 2 -sqrt (-1) 3] ✌ ✆ ✞ x = 1. i 2. - i 3. ✌ ✆ Elements of a vector may contains text or strings too. See the following Scilab codes. ✞ -- [’This is’;’string’;’matrix’] ✌ ✆ ✞ ans = !This is ! ! ! !string ! ! ! !matrix ! ✌ ✆ A new row of a matrix can also be started by adding row elements in new line. ✞ -- mat = [ 2 Row A1 Row B1 4 Row C1 Row D1 6 ] ✌ ✆
  • 69. 1.3. ARITHMETICAL KEYWORDS 35 Consistency of columns for each rows should be maintained to avoid the row/cols consis- tence error. Following example gives error. ✞ -- mat = [ 2 Row A1,Row A2 Row B1, 4 Row C1 Row D1 6 ] ✌ ✆ While this example will give a matrix of four rows and two columns. ✞ -- mat = [ 2 Row A1,Row A2 Row B1,Row B2 4 Row C1,Row C2 Row D1,Row D2 6 ] ✌ ✆ 1.3.4 Element-Wise Operation Element-wise operation is performed on each element of a supplied argument to a function. The structural properties of the supplied arguments are not considered. For example, A = [1] is a scalar while B = [1, 4] is a vector/matrix but in element wise operations, both are considered as scalars. It means only elements are meaningful in elementwise operation while structures of A and B are ignored. 1.3.5 Matrix-Wise Operation In matrix-wise operation, elements are accepted as element of a matrix and their result is put in the similar matrix form in output window. 1.3.6 Colon (Range Operator) This operator (:) is used to define a range of variable. Normally, it creates a vector/set of elements. It is used by two ways. ✞ -- ll : ul 2 -- ll : inc : ul ✌ ✆ Increment may be a positive value, or a negative value. If it is positive value then range is in ascending order, if it is negative value then range is in descending order. In first method of application, initial and final values are declared by user and suitable increment value is selected by Scilab itself. By default increment is ‘1’. ✞ -- a = 1:10 ✌ ✆
  • 70. 36 Scilab Core ✞ a = 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. ✌ ✆ ✞ -- a = 1:-10 ✌ ✆ ✞ a = [] ✌ ✆ In second method of application (i.e. more than one colons (:) are used) first element is initial value, second element is increment and third element is the upper level limit of range. The last value of range does not exceed to the upper limit. After each increment, initial value becomes equal to the sum of initial value and increment. This iteration is followed until it becomes equal or more than the finale range of iteration. ✞ -- a = 1:2:10 ✌ ✆ ✞ a = 1. 3. 5. 7. 9. ✌ ✆ ✞ -- a = 1:-2:-10 ✌ ✆ ✞ a = 1. - 1. - 3. - 5. - 7. - 9. ✌ ✆ The colon can be used for defining a rang into a matrix form. Each argument of this function is comma separated. First argument is matrix range, second argument is number of rows and third argument is the number of columns. ✞ -- a = matrix (1:12 ,6 ,2) 2 -- a ✌ ✆ ✞ a = 1. 7. 2. 8. 3. 9. 4. 10. 5. 11. 6. 12. ✌ ✆ Elements of a matrix are retrieved by calling the matrix object as shown below: ✞ 1 -- a(:) ✌ ✆
  • 71. 1.3. ARITHMETICAL KEYWORDS 37 ✞ ans = 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. ✌ ✆ The specific columns of matrices can be accessed by using first argument as colon symbol and second argument as column index. See the example below: ✞ 1 -- a = matrix (1:12 ,6 ,2) -- b=a(:,1) //1 = first column 3 -- c=a(:,2) //2 = second column ✌ ✆ ✞ a = 1. 7. 2. 8. 3. 9. 4. 10. 5. 11. 6. 12. b = 1. 2. 3. 4. 5. 6. c = 7. 8. 9. 10. 11. 12. ✌ ✆ We can use row or column index vectors for accessing multiple rows or columns. ✞ 1 -- m=[1 ,2 ,3;4 ,5 ,6;7 ,8 ,9] -- m(: ,[1 ,2]) // for multiple column indices ✌ ✆ ✞ m =
  • 72. 38 Scilab Core 1. 2. 3. 4. 5. 6. 7. 8. 9. ans = 1. 2. 4. 5. 7. 8. ✌ ✆ Specific rows can be retrieved if argument location of range operator and index number is interchanged as given in following code snippets. ✞ -- a = matrix (1:12 ,6 ,2) 2 -- b=a(1,:) //1 = first row -- c=a(5,:) //2 = fifth row ✌ ✆ ✞ a = 1. 7. 2. 8. 3. 9. 4. 10. 5. 11. 6. 12. b = 1. 7. c = 5. 11. ✌ ✆ A single colon as argument to matrix handle means full range of the matrix elements. We can limit the range operator (:) for specific indices if colon is used as incremental operator. ✞ 1 -- (initial limit : increments /decrements : final limit ) ✌ ✆ There is an increment or decrement, it is depends on the sign of increment/decrement (second element in the range operator). Increments is always a positive integer and decrements is always a negative integer. For example ✞ 1 -- a(12: -3:1) ✌ ✆ ✞ a = 12. 9. 6. 3. ✌ ✆ ✞ 1 -- a(1:2:10) ✌ ✆
  • 73. 1.3. ARITHMETICAL KEYWORDS 39 ✞ a = 1. 3. 5. 7. 9. ✌ ✆ We can extract a part of matrix by using colon operator within parentheses as shown in below example. ✞ -- A = [2 3 1 4; 5 3 1 8; 8 6 7 2; 4 5 1 3] 2 -- A(2:4 ,3:4) //A(row range , col range ) ✌ ✆ ✞ A = 2 3 1 4 5 3 1 8 8 6 7 2 ans = 1 8 7 2 1 3 ✌ ✆ We can use the colon operator to print integer numbers from 0 to n with special purposes. In the following example, n is restricted to 5, i.e. integers from 0 to 5 are printed in output. ✞ -- %i : 5 ✌ ✆ ✞ ans = 0. 1. 2. 3. 4. 5. ✌ ✆ This method of implementation is removed since Scilab 6.0 version. 1.3.7 Comma Comma operator (,) is used as the identifier for column, instruction and used as argument separator. A 3 × 3 matrix is represented in vector form as ✞ -- [1,2,3;4,5,6;7,8,9] ✌ ✆ ✞ x = 1 2 3 4 5 6 7 8 9 ✌ ✆ Space operator “ ” is also used as separator of the elements in a row of the matrix.
  • 74. 40 Scilab Core 1.3.8 Comments Comments are the statements which explains to mathematical operations, numerical cal- culations and special functions. Comments are embedded within the program codes. The comments are never executed by the Scilab and they are simply skipped by the Scilab. Symbol ‘//’ is used for the commenting of a line. ✞ -- a=5; 2 -- b=10; -- a+b // summation of two variable . ✌ ✆ ✞ ans = 15 ✌ ✆ 1.3.9 Dot Dot symbol is used to represent the end of a sentence or the decimal fraction. It is also used for element-wise dot product (.*) of two vectors or matrices. If A = aij and B = bij are two matrices of n × n size then [A · ∗B]ij = aij × bij It is always true that [A ∗ B] = [B ∗ A]. If, A and B are 2 × 2 matrices as given by A = 1 2 3 2 ; B = 2 1 3 4 Then C = A · ∗B = 1 × 2 2 × 1 3 × 3 2 × 4 = 2 2 9 8 ✞ -- a=[1 ,2;3 ,2]; 2 -- b=[2 ,1;3 ,4]; -- a.*b ✌ ✆ ✞ ans = 2. 2. 9. 8. ✌ ✆ 1.3.10 Empty An empty vector or an empty matrix is represented by ‘[]’. Empty square brackets represent to the empty set of matrix. White spaces inside the square brackets do not affect the meaning of empty matrix. ✞ 1 -- [] -- [ ] ✌ ✆
  • 75. 1.3. ARITHMETICAL KEYWORDS 41 ✞ ans = [] ans = [] ✌ ✆ 1.3.11 Equal Sign Equal operator (==) compares two values numerically and returns the ‘true’ if both values are equal otherwise returns ‘false’. Remember that symbol ‘=’ is not same as to ‘==’. Symbol ‘=’ assigns a value to a variable while ‘==’ compares two values. ✞ -- i = 5; 2 -- j = 10; -- if(i==j) 4 -- disp (E); -- elseif(ij) 6 -- disp (N); -- end ✌ ✆ ✞ N ✌ ✆ 1.3.12 global It declares a variable as a global variable. The variable defined global can be called from everywhere. 1.3.13 Hat Symbol It (ˆ) represents to the exponent, i.e. bn . It raises base (number at the left side to the hat) to the power of n (number at the right side to the hat). It is also sometime refers as power. ✞ 1 -- 2^4 ✌ ✆ ✞ ans = 16 ✌ ✆ Hat symbol (ˆ) can be also used to find the nth root of a number. ✞ -- x^(1/ n) ✌ ✆ ✞ 1 -- 2^(1/4) ✌ ✆ ✞ ans = 1.1892071 ✌ ✆
  • 76. 42 Scilab Core 1.3.14 Less Than () is a comparative operator. It tells that the left hand value is lesser than the right hand value. If left hand side value is less than the right hand side, then comparison is true otherwise false. It returns “yes” on true state and “no” in false state. ✞ -- if (12) 2 -- disp (yes); -- end ✌ ✆ ✞ ans = yes ✌ ✆ 1.3.15 Minus (–) sign is used to subtract right hand value from the left hand value. Subtraction is algebraic. If right hand value is larger than left hand value then result is negative. ✞ -- 2-3 ✌ ✆ ✞ ans = -1 ✌ ✆ The two variables using minus may be a vector or a matrix. In case of vectors, subraction takes place element-wise. Subtraction of vectors is a vector of similar size. ✞ -- [1 ,2] -[3 ,4] ✌ ✆ ✞ ans = -2. -2. ✌ ✆ In vector subtraction, size of two vectors must be equal. 1.3.16 Not Symbol, ∼, is a logical NOT operator. It compares the two values and access them according “value a is not equal to value b”. If the comparison is true according to this statement, then it returns true otherwise it returns false. ✞ -- 2 ~= 3 //2 is not equal to 3. ✌ ✆ ✞ ans = T ✌ ✆
  • 77. 1.3. ARITHMETICAL KEYWORDS 43 1.3.17 Parenthesis Parenthesis, i.e. ‘(...)’ brackets are used to group the statements, operations executions. A variable or function initiated inside the parenthesis has local scope. 1.3.18 Percent (%) is a special character. When it is prepend to string, literals are considered as with special meaning as shown in the following table. Symbol Meaning %pi π %i:n Integer from 0 to n %i √ −1 The functions whose names begin with % character are special functions. They are used as primitives and used in operator’s overloading. 1.3.19 Plus (+) is an addition operator. It returns sum of two or more values. It also concatenates two or more strings. Its operands may be vectors, scalars or strings. ✞ -- 2+3 2 -- This is my + country . ✌ ✆ ✞ ans = 5 ans = This is mycountry . ✌ ✆ The two variables may be a vector or a matrices. In case of vector operands, addition takes place element-by-element wise. ✞ --[1,2]+[3,4] ✌ ✆ ✞ ans = 4. 6. ✌ ✆ In vector subtraction, size of two vectors must be equal. 1.3.20 Quote There are two types of quotes, called single quotes (’) and double quotes (”). In Scilab, single quotes and double quotes have different meaning. The contents written between single quotes or double quotes are considered as strings. See the following example:
  • 78. 44 Scilab Core ✞ -- x = ‘The Good Boy ’ 2 -- y = The Good Boy ✌ ✆ ✞ x = The Good Boy y = The Good Boy ✌ ✆ Single quote is also used as string delimiter (”), i.e. string within string. As string delimiter, the single quote is used in a group of twice. ✞ -- x = ‘disp (‘‘Boy ’’)’ 2 -- y = disp (‘‘Boy ’’) -- z = disp (‘‘disp (‘‘disp (‘‘Boy ’’) ’’) ’’) ✌ ✆ ✞ x = disp (‘Boy ’) y = disp (‘Boy ’) z = disp (‘disp (‘disp (‘Boy ’) ’) ’) ✌ ✆ Single quote is also used in mathematics, specially in matrix. If a matrix is real matrix then single quotes converts row vector into column vector and vice-versa. See the example given below: ✞ -- a=[1 ,2] 2 -- a’ ✌ ✆ ✞ a = 1. 2. ans = 1. 2. ✌ ✆ If matrix is a complex matrix then (’) is a complex conjugate transpose operator. It is used in a matrix for conjugate transpose of the matrix. It is also used as string delimiter. Assume a complex matrix of order 2 × 2 as A = 1 + i 2 3 2 + i Conjugate transpose of this matrix (A) will be A = 1 − i 3 2 2 − i
  • 79. 1.3. ARITHMETICAL KEYWORDS 45 ✞ 1 -- [1+%i , 2; 3, 2+%i]’ ✌ ✆ ✞ ans = 1. - i 3. 2. 2. - i ✌ ✆ If a dot (.) is applied before (’), then the matrix transpose is called non-conjugate transpose of matrix. Assume a complex matrix of order 2 × 2 as A = 3 + i 2 1 2 + i Then non-conjugate transpose of the matrix will be A = 3 + i 1 2 2 + i ✞ 1 -- [1+%i ,2; 3,2+ %i].’ ✌ ✆ ✞ ans = 1. + i 3 2. 2. + i ✌ ✆ 1.3.21 Return return assigns local variables to the calling variable. ✞ 1 -- [a,b]= return (1,2) ✌ ✆ ✞ b = 2. a = 1. ✌ ✆ It is also used to return a value from inside of a function. A function is terminated in execution, when keyword return is encountered. ✞ -- function [y]= myFunc(i, j) 2 -- y=i+j; -- return 0; 4 -- y=i^j; // Not executed -- endfunction 6 -- myFunc (2, 3) ✌ ✆ ✞ ans = 5. ✌ ✆
  • 80. 46 Scilab Core ✞ -- function [y]= myFunc(i, j) 2 -- y=i+j; -- // return 0; 4 -- y=i^j; // Executed and overloaded -- // to previous result 6 -- endfunction -- myFunc (2, 3) ✌ ✆ ✞ ans = 8. ✌ ✆ 1.3.22 Semicolon Semicolon ‘;’ is used as a row separator in a matrix. It is also used to end a statement line. Application of semicolon as a row separator is shown below: ✞ -- [1,2,3;4,5,6;7,8,9] ✌ ✆ ✞ x = 1 2 3 4 5 6 7 8 9 ✌ ✆ Application of semicolon as a end of line is shown in the following example. ✞ -- i = 5; // end of first line 2 -- j = 10; // end of second line -- if(ij) 4 -- disp (L); -- elseif(ij) 6 -- disp (G); -- elseif(i==j) 8 -- disp (E); -- end ✌ ✆ ✞ L ✌ ✆ End-of-line application of semicolon (;) does not mean the skip of contents by the Scilab or commenting of the rest of contents in the line. It only separates the two statements written in a single line. Again, when a statement is terminated with semicolon, then the output or result is stored in memory and it is not visible in the output console. The output is obtained only when the object is called without terminating by semicolon. ✞ 1 -- a=5+5; b=6+5; -- a 3 -- b ✌ ✆
  • 81. 1.3. ARITHMETICAL KEYWORDS 47 ✞ a = 10. b = 11. ✌ ✆ 1.3.23 Forward Slash Slash (/) is used in division. The left side value to the forward slash is divided by its right side value. When forward slash is used in pair, it acts as a commenting symbol. In Scilab, line commenting symbol is ‘//’. ✞ -- i = 5; // end of first line 2 -- j = 10; // end of second line -- i/j ✌ ✆ ✞ ans = 0.5 ✌ ✆ 1.3.24 Space Space operator (“ ”) is used as the identifier for columns in a matrix or in a vector. A 3 × 3 matrix is represented in vector form as ✞ -- [1 2 3;4 5 6;7 8 9] ✌ ✆ ✞ x = 1 2 3 4 5 6 7 8 9 ✌ ✆ Comma operator (,) is also used as separator of the elements in a row. 1.3.25 Asterisk Star (*), i.e. asterisk is used as multiplier between two variables from left to right. Multiplication of two vectors are allowed if number of rows in first vector is equals to the number of columns in second vector. If A = aij and B = bij are two matrices of size n × n then [A ∗ B]kj = n X i,k=0 aki × bik It is not always true that [A ∗ B] = [B ∗ A]. If two inputs are integers then it performs simple arithmetic.
  • 82. 48 Scilab Core ✞ -- i = 5; // end of first line 2 -- j = 10; // end of second line -- i*j ✌ ✆ ✞ ans = 50 ✌ ✆ Multiplication of vector and scalar: ✞ -- [1 ,2]*4 ✌ ✆ ✞ ans = 4. 8. ✌ ✆ Asterisk performs multiplication of matrices. A matrix multiplication is performed if the matrix product conditions are satisfied. For two vectors or matrices, if number of columns of first matrix is equal to the number of rows of second matrix then matrix multiplication is carried out. See the following example. ✞ -- [1 ,2]*[4;3] // 1x2 matrix by 2x1 matrix ✌ ✆ ✞ ans = 10. ✌ ✆ If, A and B are 2 × 2 matrices as given by A = 1 2 3 2 ; B = 2 1 3 4 Then C = A ∗ B = 1 × 2 + 2 × 3 1 × 1 + 2 × 4 3 × 2 + 2 × 3 3 × 1 + 2 × 4 = 8 9 12 11 ✞ -- a=[1 ,2;3 ,2]; 2 -- b=[2 ,1;3 ,4]; -- a*b ✌ ✆ ✞ ans = 8. 9. 12. 11. ✌ ✆ If two matrices are not equal in size then they are taken as vectors and vector multiplica- tion is performed. It happens when second matrix is 1 × 1 type matrix. Second operand may be a scalar too as seen above in the product of vector and scalar. See the following example. ✞ 1 -- [1 ,2]*[4] ✌ ✆
  • 83. 1.4. CORE KEYWORDS 49 ✞ ans = 4. 8. ✌ ✆ Consistency shall be maintained while performing vector or matrix multiplication. For example, if second operand is a multicolumn vector then it must satisfy the condition of matrix multiplication. See the following example, in which Scilab failed to give desire result due to inconsistent multiplication. ✞ -- [1 ,2]*[3 ,4] ✌ ✆ ✞ !--error 10 Inconsistent multiplication . ✌ ✆ 1.3.26 Tilda Tilda, (!) is a logical NOT. It is also used like (∼=) i.e. not equals to. It is an boolean expression for NOT Gate. ✞ -- 2 != 3 //2 is not equal to 3. ✌ ✆ ✞ ans = T ✌ ✆ 1.4 Core Keywords 1.4.1 Abort Process (abort) abort interrupts current evaluation and gives the prompt. Within a pause level abort return to level 0 prompt. ✞ -- i = 0; 2 -- while i10 do -- disp (i); 4 -- i = i + 1; -- if(i5) 6 -- abort;// abort key word -- end 8 -- end ✌ ✆ ✞ 0. 1. 2. 3. 4. 5. ✌ ✆
  • 84. 50 Scilab Core 1.4.2 Add a Demo (add demo) This function, add demo, is used to add user define file or codes into Scilab demos. ✞ -- // Create a simple demo script 2 -- path = TMPDIR+’/foo.sce ’; -- mputl(’disp Hello’,path ) 4 -- add_demo (’My first demo ’,path ) -- // Demo can be run using Demos menu . ✌ ✆ We can find ‘My first demo’ in Demos options of ’Scilab Demonstrations’. 1.4.3 Number of Arguments (argn) argn is similar to the argc command in ‘C’. It returns the number of input/output argu- ments in a function call. Scilab uses ‘lhs’ and ‘rhs’ for identification of inputs arguments and output arguments. For example, in the following function y = f(x) left hand side (lhs) argument is y while right hand side (rhs) argument is x. Actually for this relation, x is input argument and y is output argument. argn has three arguments. ‘0’ for both lhs (output arguments) and rhs (input arguments) strings. ‘1’ for lhs (output arguments) only and ‘2’ for rhs (input arguments) only. Its syntax are ✞ 1 -- [lhs , rhs] = argn () // for both input/output arguments -- lhs=argn (1) // for output arguments only 3 -- rhs=argn (2) // for input arguments only ✌ ✆ The given example is ✞ 1 -- funcprot (0); -- function [t] = myf(a,b,c) 3 -- [lhs , rhs] = argn (0); -- mprintf (Nos of outputs : %dn,lhs); 5 -- mprintf (Nos of inputs : %dn,rhs); -- outs = argn (1); 7 -- ins = argn (2); -- mprintf (Nos of outputs : %dn,outs ); 9 -- mprintf (Nos of inputs : %dn,ins); -- endfunction 11 -- x=myf (2,2,3) ✌ ✆ ✞ Nos of outputs : 1 Nos of inputs : 3 Nos of outputs : 1 Nos of inputs : 3 ✌ ✆
  • 85. 1.4. CORE KEYWORDS 51 1.4.4 Banner It shows the default banner of Scilab. ✞ -- banner () ✌ ✆ 1.4.5 Boolean Boolean operators , | and ∼ are used to express the boolean relation between two variables. These operators are used as logical AND, logical OR and logical NOT as short cuts and as element-wise. Shortcut And Elementwise Before, Scilab 6.0, shortcut and elementwise boolean AND operators were same and both were represented by . Since Scilab 6.0, shortcut and element-wise boolean operators are now distinct. is shortcut boolean AND, while is element-wise AND operations. Both shortcut and element-wise operators are evaluated from left to right. ✞ 1 -- [1,3] [5,2] // is not defined before scilab 6.0 -- // Error shows in Scilab v 6.0 ✌ ✆ ✞ [1,3] [5,2] !-- error 2 Invalid factor. ✌ ✆ ✞ 1 --[1,3] [5,2] // Works in all version of scilab ✌ ✆ ✞ ans = T T ✌ ✆ Shortcut || And Elementwise | Before, Scilab 6.0, shortcut and elementwise boolean OR operators were same and both were represented by . Since Scilab 6.0, shortcut and element-wise boolean operators are now distinct. || is shortcut boolean OR, while | is element-wise OR operations. Both shortcut and element-wise operators are evaluated from left to right. ✞ -- [1,3] || [5,2] // is not defined before scilab 6.0 2 -- // Error in scilab v 6.0 ✌ ✆ ✞ [1,3] || [5,2] !-- error 2 Invalid factor. ✌ ✆
  • 86. 52 Scilab Core ✞ 1 --[1,3] | [5,2] // Works in all version of scilab ✌ ✆ ✞ ans = T T ✌ ✆ 1.4.6 Break a Process (break) break keyword interrupt a current loop. It is always used inside the loop functions or switch functions. ✞ -- i = 0; 2 -- while i10 do -- disp (i); 4 -- i = i + 1; -- if(i5) 6 -- break;// break the loop -- end 8 -- end ✌ ✆ ✞ 0. 1. 2. 3. 4. 5. ✌ ✆ 1.4.7 Case case is used to compare a select value with arbitrary chosen value. If select value is equal to case value, statement inside the case is executed. ✞ -- A = 2 2 -- select A -- case 1 then 4 -- disp (1) -- case 2 then 6 -- disp (2) -- else 8 -- disp (3) -- end ✌ ✆ ✞ 2 ✌ ✆
  • 87. 1.4. CORE KEYWORDS 53 1.4.8 Kill the Value (clear) clear kills the value of a variable. If a variable is cleared inside the loop, an error is displayed as undefined variable. ✞ 1 --i = 0; --while i5 do 3 -- disp (i); -- i = i + 1; 5 -- if(i2) -- // Clear variable i. Now , in next loop variable 7 -- // i shall not be identified inside while loop . -- clear i; 9 -- end --end ✌ ✆ ✞ 0. 1. 2. while i5 do !--error 4 Undefined variable : i ✌ ✆ 1.4.9 Remove a Function (clearfun) clearfun is used to remove a function name in the table of Scilab functions. ✞ -- // Get the func ptr associated with the abs function 2 -- absptr=funptr(abs); -- // Create an alias of the abs function 4 -- newfun(abs_bis,absptr); -- clearfun (abs) ✌ ✆ ✞ ans = T ✌ ✆ 1.4.10 Clear Global clearglobal clears the global variable defined previously. 1.4.11 Compile Scilab Function (comp) comp compiles a function in Scilab. If a function is already compiled then it gives warning. ✞ -- comp (abs ,0) ✌ ✆ ✞ Warning : Function is already compiled . ✌ ✆
  • 88. 54 Scilab Core There are three options of compilation of function. Default is ‘0’ and others are ‘1’ and ‘2’. Options Meaning 0 Default compilation value. 1 Obsolete, similar to option ‘0’. 2 Function to be compiled “for profiling”. 1.4.12 Continue continue pass the control to the next iteration of loop. To understand the working of continue keyword, we use same example in three different methods. In following example two for loops are used. ✞ 1 -- for j =1:1:3 -- for k=3: -1:1 3 -- if jk then -- disp (j*k); 5 -- end -- end 7 -- end ✌ ✆ ✞ 2. 6. 3. ✌ ✆ Now we put the continue command after disp(j*k) as ✞ 1 -- for j =1:1:3 -- for k=3: -1:1 3 -- if jk then -- disp (j*k); 5 -- continue ; -- end 7 -- end -- end ✌ ✆ ✞ 2. 6. 3. ✌ ✆ There is no change in output as disp put the result before continue encountered. Again if we put the continue command before disp(j*k) as ✞ 1 -- for j =1:1:3 -- for k=3: -1:1 3 -- if jk then -- continue ;
  • 89. 1.4. CORE KEYWORDS 55 5 -- disp (j*k); -- end 7 -- end -- end ✌ ✆ There is no output as continue pushes to the next iterator before disp put the result in output window. 1.4.13 Debug debug is used to find the errors and bad scripting in a code script. There are five levels of debugging, ranged from -1 to 4. This range defines the level of debugging. ✞ -- debug(-1) ✌ ✆ ✞ ans = 1 ✌ ✆ 1.4.14 Delete Break delbpt is used to delete a break point from the function. To set a breakpoint for function ‘foo’, we use setbpt. The setbpt sets break point one over other as stack in setbpt list. On call of delbpt the top most breakpoint is deleted from the stack. ✞ -- setbpt(’foo’ ,1); // set first break point at 1 2 -- setbpt(’foo’ ,10);// set second break point at 10 -- delbpt(’foo’ ,10);// deleted second break point at 10 4 -- dispbpt () // show first break point at 1 ✌ ✆ ✞ Breakpoints of function : foo 1 ✌ ✆ 1.4.15 Display Break Points (dispbpt) dispbpt is used to show a break point of a function from the setbpt list. ✞ -- setbpt(’foo’ ,1); // set first break point at 1 2 -- setbpt(’foo’ ,10);// set second break point at 10 -- delbpt(’foo’ ,10);// deleted second break point at 10 4 -- dispbpt () // show first break point at 1 ✌ ✆ ✞ Breakpoints of function : foo 1 ✌ ✆
  • 90. 56 Scilab Core 1.4.16 Do do keyword is used to execute a group of statements or programming script until unless a condition is being satisfied. do keyword is always used with while function. The scope of do keyword is from the next line of statement to the corresponding end keyword. ✞ -- i = 0 2 -- while i5 do -- disp (i); 4 -- i = i + 1; -- end ✌ ✆ ✞ ans = 0 1 2 3 4 ✌ ✆ 1.4.17 Edit Function edit is used to open a existing file or existing function in the Scilab editor or open editor for definition of new function. ✞ -- // open editor with text of existing function 2 -- edit (’edit ’) -- // open editor for a new function 4 -- edit (’myF’) ✌ ✆ The argument of this function is either a function name or a file name as absolute path. ✞ -- // open the file bar.sci in TMPDIR directory 2 -- edit ( fullfile (TMPDIR+’bar.sci’)) ✌ ✆ An existing file may be open in the Scilab editor with reaching to specific line of the script. The script line is specified by the second argument. Second argument is a pure integer value. ✞ -- edit (’test_run ’, 123) ✌ ✆ User defined function can also be open in default Scilab editor with the function scripts. ✞ 1 -- function a=b(c) -- c=1; 3 -- endfunction -- edit (’b’) ✌ ✆ This will open function ’b’ in Scilab editor.
  • 91. 1.4. CORE KEYWORDS 57 1.4.18 Else else is the false case of if condition. If a condition is not satisfied, statement in else section are executed. Another if-else loop can be initiated in the statement section of else as a nested loop. ✞ -- i = 5; 2 -- j = 10; -- if(i==j) 4 -- disp (T); -- else 6 -- disp (F); -- end ✌ ✆ ✞ T ✌ ✆ 1.4.19 Else-If elseif is used as false case of if with new if conditions. It is also used as chain conditional case. A nested loop can also be used within the elseif statement portion. ✞ 1 -- i = 5; -- j = 10; 3 -- if(ij) -- disp (L); 5 -- elseif(ij) -- disp (G); 7 -- elseif(i==j) -- disp (E); 9 -- end ✌ ✆ ✞ L ✌ ✆ 1.4.20 End end keyword is used to terminate a conditional statement. end is used for the following purposes 1. To finish a condition. 2. To finish a function definition by using endfunction for Scilab version 5.5 and prior or using end only since Scilab 6.0 and later. 3. To finish a statement. ✞ 1 -- i = 5; -- j = 10; 3 -- if(ij)
  • 92. 58 Scilab Core -- disp (L); 5 -- elseif(ij) -- disp (G); 7 -- elseif(i==j) -- disp (E); 9 -- end ✌ ✆ ✞ L ✌ ✆ 1.4.21 Catch Error (errcatch) errcatch is used to trap an error. This function is removed since Scilab 6. ✞ 1 -- errcatch (1,’pause’); ✌ ✆ The first variable in errcatch is number that is used to trap an error. If it is less than 0 then all errors are catch and if it is grater than 0 then errcatch traps that specific error assigned to this number. Second variable is action in string form that is to be performed if error catches. The actions are either ‘pause’, ‘continue’, ‘kill’ or ‘stop’. 1.4.22 Clear The Error (errclear) In scilab, error table contains the list of all errors being rose during the operation. errclear is used to clear a specific or all errors from the error list. It is used like ✞ 1 -- errclear (n); ✌ ✆ Where ‘n’ is the error number. If ‘n’ is positive (n 0), it is the number of the cleared error. If (n ≤ 0) then all errors are cleared (default case). 1.4.23 Error error function is standard way of printing errors during the process by Scilab. A cus- tomised error may also be constructed by using this function. It accepts two arguments, in which first argument is message and second argument is error number associated with message. It is used like ✞ 1 -- error(message ) -- error(message , n) 3 -- error(n) -- error(n, message ) 5 -- error(n, pos ) ✌ ✆ Here ‘message’ is the error message. ‘n’ is error number and ‘pos’ is a parameter of error message. By default ‘n’ is ‘10000’. ✞ 1 -- error(! This value must be an integer !, 10) ✌ ✆