Scilab Bag Of Tricks

The Scilab-2.5 IAQ (Infrequently Asked Questions)

Lydia E. van Dijk

Christoph L. Spiel

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".


Table of Contents
Preface
Outline
Other Formats of sci-BOT
Typographic Conventions Used in This Book
Acknowledgments
1. Introduction
2. Common Pitfalls
The Infamous Dot
Vector Construction
Last Newline
Variable Lifetime And Scoping
Local Variable Scoping
Global Variables
Clearing Variables
3. Programming Style
Spacing and Formatting
Intra-Expression Spacing
Line Breaking
Setting Brackets Apart
Indentation
Choice Of Control Structures
while/for
if/select
Strict Block Structure/Premature Return
Size of a Function
4. Unknown Spots
Operator Precedence And Associativity
Numeric Operators
Relational Operators
Logical Operators
Functions
Functions Without Arguments or Return Value
Bulletproof Functions
Function Variables
Nested Function Definitions
Functions as Parameters in Function Calls
Functions in tlists
macrovar
Miscellaneous Unknown Spots
Starting scilex
Tuple Assignment
Omitting Parentheses on Function Call
5. Graphics
Function- And Data-Plotting
Graphics Primitives
User Interfaces
6. Performance
High-Level Operations
Vectorized Operations
Avoiding Indexing
Built-In Vector-/Matrix-Functions
Evaluation Of Polynomials
Extending Scilab
Comparison of the Link Overhead
Preparing And Compiling External Subroutines
Pushing It Further
Building an Optimized Scilab
7. Scilab Core
Introduction To pAda
Internal Data Structure
Parameter Stack And Data Stack
Storage of Complex Variables
Writing Native Scilab Functions
Simple Functions
Functionals
Error Handling
Fatal Errors
Warnings
Messages
Interface to Scilab's Core
Query
Access Object
Create Object
8. Further Information
Coping With Scilab
Distribution Size
Bug Hunting
Local Documents
Hyperlinks
9. Longer Examples
benchmark.sci
listdiff.sci
whatis.sci
Auto-Determination of Precedence and Associativity
assoc.sci
prec.sci
parser.sci
cat.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.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Bibliography
List of Tables
4-1. Arithmetic Operators
4-2. Boolean Operators
6-1. Comparison of various vectorization levels
6-2. Performance comparison of different polynomial evaluation routines
7-1. pAda to Fortran-77 type mappings
List of Figures
6-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 fibonacci
3-3. Function shape4
3-4. Function mysign
4-1. Function cat
4-2. Function tauc
4-3. Function minimize
4-4. Manually launching scilex
6-1. Variants of a matrix mirror function
6-2. Naive functions to evaluate a polynomial
6-3. Less naive functions to evaluate a polynomial
6-4. Makefile for static Scilab interfaces via intersci
6-5. Linking (GNAT) Ada-code
7-1. Simple native Scilab function
7-2. Handling of warnings in Scilab