Scilab Bag Of Tricks

The Scilab-2.5 IAQ (Infrequently Asked Questions)

Lydia E. van Dijk

Hammersmith Consulting

Christoph L. Spiel

Hammersmith Consulting

sci-BOT – the Scilab Bag Of Tricks – is a collection of Scilab experience that come from every day use. We warn of common pitfalls, discuss stylistic issues, shed light on unknown spots, and show many different ways of increasing the performance of Scilab functions.

The document is not meant to be comprehensive or even suitable to a particular level of knowledge. Some sections are at the beginners level, some even surprise long-time users.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no invariant sections, with the Front-Cover Texts being "Scilab Bag Of Tricks", and with no Back-Cover Texts. A copy of the license is included in the appendix "GNU Free Documentation License".

Trademarks: Matlab™is a trademark of The Mathworks, Inc.; DIGITAL™is a trademark of Digital Equipment Corp.; Intel™ IBM™ SUN™ is a trademark of Sun Microsystems, Inc.; SGI™ PostScript™ is a trademark of Adobe, Inc.; TeX™ is a trademark of the American Mathematical Society;

Copyrights: Linux© by Linus Torvalds; MuPAD© by Benno Fuchsensteiner; Pari© by C. Batut, K. Belabas, D. Bernardi, H. Cohen, and M. Olivier; Scilab© by INRIA, France. Octave© by John W. Eaton; Tela© be Pekka Janhunnen; GNUPlot© by Thomas Williams, Colin Kelley and many others; PlotMTV© by Kenny Toh;


Table of Contents
Preface
1. Outline
2. Other Formats of sci-BOT
3. Typographic Conventions Used In This Book
4. Acknowledgments
1. Introduction
2. Common Pitfalls
2.1. The Infamous Dot
2.2. Vector Construction
2.3. Last Newline
2.4. Variable Lifetime And Scoping
2.4.1. Local Variable Scoping
2.4.2. Global Variables
2.4.3. Clearing Variables
3. Programming Style
3.1. Spacing and Formatting
3.1.1. Intra-Expression Spacing
3.1.2. Line Breaking
3.1.3. Setting Brackets Apart
3.2. Indentation
3.3. Choice Of Control Structures
3.3.1. while/for
3.3.2. if/select
3.3.3. Strict Block Structure/Early Return
3.4. Size of a Function
4. Unknown Spots
4.1. Operator Precedence And Associativity
4.1.1. Numeric Operators
4.1.2. Relational Operators
4.1.3. Logical Operators
4.2. Implicit Cast To Boolean
4.3. Functions
4.3.1. Functions Without Parameters or Return Value
4.3.2. Named Parameters
4.3.3. Bulletproof Functions
4.3.4. Function Variables
4.3.5. Nested Function Definitions
4.3.6. Functions as Parameters in Function Calls
4.3.7. Functions in tlists
4.3.8. macrovar
4.4. Miscellaneous Unknown Spots
4.4.1. Starting scilex
4.4.2. Tuple Assignment
4.4.3. Omitting Parentheses on Function Call
5. Performance
5.1. High-Level Operations
5.1.1. Vectorized Operations
5.1.2. Avoiding Indexing
5.1.3. Built-In Vector-/Matrix-Functions
5.1.4. Evaluation Of Polynomials
5.2. Extending Scilab
5.2.1. Comparison Of The Link Overhead
5.2.2. Preparing And Compiling External Subroutines
5.2.3. Pushing It Further
5.3. Building an Optimized Scilab
6. Scilab Core
6.1. Introduction To Pseudo-Ada
6.2. Internal Data Structure
6.2.1. Parameter Stack And Data Stack
6.2.2. Storage of Complex Matrices
6.3. Writing Native Scilab Functions
6.3.1. Simple Functions
6.3.2. Functionals
6.3.3. Dispatch Tables
6.4. Error Handling
6.4.1. Fatal Errors
6.4.2. Warnings
6.4.3. Messages
6.5. Interface to Scilab's Core
6.5.1. Query
6.5.2. Access Object
6.5.3. Create Object
7. Further Information
7.1. Coping With Scilab
7.1.1. Distribution Size
7.1.2. Bug Hunting
7.2. Local Documents
7.3. Hyperlinks
8. Complete Examples
8.1. benchmark.sci
8.2. listdiff.sci
8.3. whatis.sci
8.4. Auto-Determination of Precedence and Associativity
8.4.1. assoc.sci
8.4.2. prec.sci
8.4.3. parser.sci
8.5. cat.sci
8.6. quadpack.sci
A. GNU Free Documentation License
0. PREAMBLE
1. APPLICABILITY AND DEFINITIONS
2. VERBATIM COPYING
3. COPYING IN QUANTITY
4. MODIFICATIONS
5. COMBINING DOCUMENTS
6. COLLECTIONS OF DOCUMENTS
7. AGGREGATION WITH INDEPENDENT WORKS
8. TRANSLATION
9. TERMINATION
10. FUTURE REVISIONS OF THIS LICENSE
B. GNU General Public License
0. APPLICABILITY[1]
1. VERBATIM COPYING
2. MODIFICATIONS
3. DISTRIBUTION
4. TERMINATION
5. ACCEPTANCE
6. REDISTRIBUTION
7. CONSEQUENCES
8. LIMITATIONS
9. FUTURE REVISIONS OF THIS LICENSE
10. AGGREGATION WITH INDEPENDENT WORKS
11. NO WARRANTY
12. LIABILITY
Bibliography
Index
List of Tables
4-1. Arithmetic Operators
4-2. Boolean Operators
5-1. Comparison of various vectorization levels
5-2. Mode Specifiers for gsort
5-3. Direction Specifiers for gsort
5-4. Performance comparison of different polynomial evaluation routines
6-1. pAda to Fortran-77 type mappings
List of Figures
5-1. Benchmark results for the mirror functions
List of Examples
2-1. Building a matrix column-by-column and row-by-row
2-2. Canonicalization of Scilab files
2-3. Shadowing of local variables
2-4. Accessing variables from the enclosing scope
2-5. Dynamic Scoping
3-1. Function whocat
3-2. Function mysign
4-1. Function cat
4-2. Function tauc
4-3. Manually launching scilex
5-1. Variants of a matrix mirror function
5-2. Naive functions to evaluate a polynomial
5-3. Less naive functions to evaluate a polynomial
5-4. Sample interface description (".desc")
5-5. Makefile for static Scilab interfaces via intersci
6-1. Simple native Scilab function
6-2. Scilab functional
6-3. Handling of warnings in Scilab