Intro to Scilab

Developed at INRIA, SCILAB has been developed for system control and signal processing applications. It is freely distributed in source code format. High level scientific computing environments such as Matlab, RLab, Octave and Scilab are an enjoyable way to solve problems numerically. It is particularly easy to generate some results, draw graphs to look at the interesting features, explore the problem further and manipulate matrices. Scilab is made of 3 distinct parts • • • An interpreter Libraries of functions Libraries of Fortran and C routines

 - scilab prompt Up arrow key – to display // - comment %pi = 3.1415 //constant pi clc = clear the screen clear = clear memory clear varname = clear specific variable xbasc() = erase the previous plot Differences between Matlab and Scilab

 (-1+2+3)*5 – 2/3 //The four arithmetic operations
= 19.33

 2^3 // Means 2 to the power 3.
=8

 %pi // The mathematical constant pi
= 3.1415

 exp(sin(%pi/2)) //The usual functions are provided log, log10, cos, tan, asin,
… = 2.7182818

exp – element-wise exponential
Calling sequence: exp(X) Parameters

Page 1 of 7

Scilab is a case-sensitive language. A variable can have almost any name.  %e //The mathematical constant e Note: Scilab does all calculations correct only to about 16 significant decimal digits.1415927  22/7 //pi is not the same as 22/7 = 3.776D-15  cos(%pi/3) //These are familiar trigo functions = 0. Description exp(X) is the (element-wise) exponential of the entries of X.echo off. suppress unwanted output.  q= 3+5. . = 1.  %pi = 3.5 Variable – Scilab also uses variables to store intermediate answers.) Ex. Usually only 5 significant digits are displayed on the screen.• X : scalar.1428571  11*(15/11)-15 //This shows there is round off error when scilab uses fractions.5  sin(%pi/6) //These are familiar trigo functions = 0. Ex. vector or matrix with real or complex entries. Ex. Use comma (. . Page 2 of 7 . but is must begin with a letter. Ex.  ratio = p/q = 0. This is enough accuracy for most purposes. X = 2+3 Y = 4+5 result = X/Y .) or a semicolon (.  p = 2+3.5555556 >> A number of commands can be placed on the one line.

y=1-1*%i x = 2 + 3i y=1–i  z1= x-y.225D-16i PLOTTING LINES AND DATA Page 3 of 7 .  x=2+3*%i. ratio1 = p1/q1 q1 = 9 ratio1 = 0.5555556 >>Parentheses can be used to make expressions clearer. q1 = x+4.the variable %i stands for −1 Ex. z3 = x/y z1 = 1 + 4 i z2 = 5 + i z3 = -0.5i  abs(x) = 3.Scilab handles complex numbers as easily as real numbers .168907i  exp(%pi * %i ) + 1 = 1.6055513  real(x) =2  imag(x) =3  sin(x) = 9. Ex.  ratio = (2+3)/(x+4) Complex Numbers .5 + 2.1544991 – 4. p1 = 2+3 . z2 = x*y.

7 .3 1.1 1. its main power is that it gives a simple way of working with matrices and vectors. y2) 0 <= x1 <=2 3 <= x2 <=5 MATRICES AND VECTORS Although SciLab is a useful calculator.8 2.3 1.7 1. x2.5 .Ex. . 7:9] g = [1:0.5: 5]. y1) plot (x2.8]  y=[.n] where: x1.9 1.5 . y2 = (x2 – 2).4  x=[. plot (x1. Xk Yk This section shows how to produce simple plots of lines and data.3) b = ones(4.4]  plot2d(x.2 .1:5] h = linspace(-10. 4:6. Y1 = 2X + 4 Y2 = x-2        x1 = [0: 0.4) c = diag([ 1 2 3 4]) d = rand(3. y1.75 1. style=-1) Ex.5: 2].1 . x2.5 1. x2 = [3: 0.5 2.9 .7 . y1 = (2*x1+4). x2 : real or complex scalars n : integer (no of values) default = 100 Page 4 of 7 .1 . Matrix Shortcuts         a = eye(3.y.75 1.3) e = [1:5] f = [1:3.7 2.1 2. 10. y2) plot (x1. 20) linspace syntax: linspace(x1.2 .

Displaying matrix data  a = [1. :) = 4 5 6  a([1 2].8.1) =1  a(:./ . r2].5. 7.* . [1 2]) = 1 2 4 5  a([2 3].6.3. // given data  a(1. 4.[2 3]) = 2 3 5 6 MATRIX MANIPULATION + * / \ ^ ‘ .2. [c1. 1) // : is used to denote all entries = 1 4 7  a(2.^ addition subtraction multiplication division left division power transpose array multiply array division array power Subtraction of Matrices D=A D= 0 3 4 –B -1 -2 3 2 2 2 6 9 //a([r1. c2]) Addition of Matrices A= 1 4 7 2 5 8 3 6 9 B= 1 3 1 E = B-A Page 5 of 7 . : ) = 4 5 7 8  a([1 2].9].

B = [2 4 6 8.1 3 7 5 4 7 C=A+B C= 2 5 5 12 10 13 F = 3*A F = 3 6 12 15 21 24 H = A’ H = 1 2 3 E= 0 -3 -4 1 2 -3 -2 -2 -2 4 10 16 G = 2*B G = 2 6 2 14 6 10 I = B’ I= 1 3 1 9 18 27 2 8 14 4 5 6 7 8 9 1 7 4 3 5 7 Matrix Multiplication A= [1 2 3.*B ERROR! Inconsistent multiplication  C = A*B ERROR! Inconsistent multiplication Matrix Division I Page 6 of 7 . 2 3 1 4] B = [1 2 3 4. 1 2 3 4.*B C= 2 8 4 9 17 44 27 69 37 94 18 1 32 16  C = B*A ERROR! Inconsistent multiplication  C = A. 2 3 1 4]  C = A. 4 5 6]. 1 3 5 7]  C = A*B C= 7 19 Array Multiplication A = [2 4 6 8.

4010 0. 1 0 5 9] C = A/B C= 1.2604 0.8542 0.1302 0.8542 0.8542 0.x2+ x3 = 6 -x1 + 3x2 + 4x3 = 4  A = [-1 1 2.6354 -0.2604 0.6354 Page 7 of 7 . 5:8] B = [1 5 1 4. -1 3 4]  B = [2. 3 -1 1.4271 1. 2 4 6 8.A = [2 4 6 8.4010 0. 1 8 3 9. 6.8177 -0.8385 -3.6354 0.2604 0.7500 0.8750 0.3750 -3.1302 0.7500 -0. 1:4.6354 0.3750 6.2604 0.6354 1. 1 7 9 2.4]’  X = inv(A)*B X= 1 -1 2  A\B X= 1 -1 2 -0.4271 1.8750 Left Division Given: -x1+ x2 + 2x3 = 2 3x1.6354 -0.7500 -0.7500 1.8542 0.8385 Inverse of Matrix C = A*inv(B) C= 1.8177 6.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.