Sci Lab Introduction
Sci Lab Introduction
Satish Annigeri
Ph.D.
Professor of Civil Engineering
B.V. Bhoomaraddi College of Engineering & Technology, Hubli
[email protected]
December 2009
Table of Contents
Preface........................................................................................................................................ ii
Introduction.............................................................................................................................. 1
Tutorial 1 Scilab Environment....................................................................................... 3
Exercise 1 Scilab Environment...................................................................................... 5
Tutorial 2 The Workspace and Working Directory................................................6
Exercise 2 The Workspace and Working Directory...............................................8
Tutorial 3 Creating Matrices and Some Simple Matrix Operations.................9
Exercise 3 Creating Matrices and Some Simple Matrix Operations..............12
Tutorial 4 Sub-matrices................................................................................................. 13
Exercise 4 Sub-matrices................................................................................................. 15
Tutorial 5 Statistics.......................................................................................................... 16
Tutorial 6 Working with Polynomials...................................................................... 17
Exercise 6 Working with Polynomials...................................................................... 20
Tutorial 7 Plotting Graphs............................................................................................ 21
Tutorial 8 Plotting 3D Graphs...................................................................................... 24
Tutorial 9 Scilab Programming Language.............................................................. 26
Tutorial 10 Script Files and Function Files............................................................. 30
Tutorial 11 Functions in Scilab................................................................................... 32
Tutorial 12 File Operations.......................................................................................... 35
Tutorial 13 Polynomial Curve Fitting....................................................................... 37
Tutorial 14 Reading Microsoft Excel Files.............................................................. 40
Tutorial 15 Some Miscellaneous Commands......................................................... 42
Tutorial 16 Data Structures.......................................................................................... 43
Tutorial 17 Directed Graphs........................................................................................ 47
Tutorial 18 Principal Stresses..................................................................................... 51
An Introduction to Scilab | i
Preface
Scilab is an open source software for numerical mathematics and
scientific visualization. It is capable of interactive calculations as well as
automation of computations through programming. It provides all basic
operations on matrices through built-in functions so that the trouble of
developing and testing code for basic operations are completely avoided. Its
ability to plot 2D and 3D graphs helps in visualizing the data we work with.
All these make Scilab an excellent tool for teaching, especially those subjects
that involve matrix operations. Further, the numerous toolboxes that are
available for various specialized applications make it an important tool for
research. Being compatible with Matlab
i=1
n+1
a
i
x
i1
where
a
i
, i=1to n+1
are unknown coefficients which can be computed by
solving the following set of linear simultaneous equations:
|
x
0
x
x
2
x
n
x
x
2
x
3
x
n+1
x
2
x
3
x
4
x
n+2
x
n
x
n+1
x
n+2
x
2n
a
1
a
2
a
3
a
n+1
xy
x
2
y
x
n
y
or
| X a=b
We can solve for the unknown coefficients as follows:
a=| X
1
b
Once the coefficients are determined, the predicted values of y for the
observed values of x as follows:
y (x)=
i=1
n+1
a
i
x
i1
Let us consider the sample data given below:
x -1 0 1 2 3 5 7 9
y -1 3 2.5 5 4 2 5 4
Let us fit a fourth order polynomial equation to the above data, of the form
y=a
1
+a
2
x+a
3
x
2
+a
4
x
3
+a
5
x
4
The required simultaneous equations that must be solved are as follows:
|
8
x
x
2
x
3
x
4
x
x
2
x
3
x
4
x
5
x
2
x
3
x
4
x
5
x
6
x
3
x
4
x
5
x
6
x
7
x
4
x
5
x
6
x
7
x
8
a
1
a
2
a
3
a
4
a
5
xy
x
2
y
x
3
y
x
4
y
The elements of the above matrix equation are listed in the table on the
next page.
Tutorial 13 Polynomial Curve Fitting | 38
x
0
x
1
x
2
x
3
x
4
x
5
x
6
x
7
x
8
8 26 170 1232 9686 79256 665510 5686952 49208966
Similarly, the right hand vector is
y
xy
x
2
y
x
3
y
x
4
y
24.5 106.5 676.5 5032.5 39904.5
The simultaneous equations are therefore as follows:
|
8 26 170 1232 9686
26 170 1232 9686 79256
170 1232 9686 79256 665510
1232 9686 79256 665510 5686952
9686 79256 665510 5686952 49208966
a
1
a
2
a
3
a
4
a
5
24.5
106.5
676.5
5032.5
39902.5
The principal planes are defined as those planes on which only normal
stresses act and are free of shear stresses. They also represent the maximum
values of the normal stress at that point. The condition for a plane to be a
principal plane and the stresses on it to be the principal stress is expressed in
the form of a homogeneous equation:
|
(c
x
c) t
xy
t
xz
t
xy
(c
y
c) t
yz
t
xz
t
yz
(c
z
c)
l
x
l
y
l
z
0
0
0
=l
x
t
xy
t
xz
x(t ) is
the vector of accelerations at instant of time t . Assuming
x(t )=X cos ot to be harmonic, the above equation can be reduced to
the following standard eigenvalue form:
(| ko
2
| m) X =0
or alternately as
(\| I | D) X =0 where
\=
1
o
2
and
| D=|k
1
| m
is called
the dynamic matrix of the system. Solution to the above eigenvalue problem
consists of finding the eigenvalues
\
i
, i=1, 2,... , n and the eigenvectors
X
i
( j )
corresponding to the eigenvalue
\
i
. The eigenvalues are related to the
natural frequencies
o
i
=
1
.
\
i
and the eigenvectors are related to the mode
shape vectors of the system.
The eigenvalues and eigenvectors can be determined using Scilab in a
number of ways. One way is to find the dynamic matrix | D and find its
eigenvalues and eigenvectors using the Scilab function spec().
An alternative way is to formulate the eigenvalue problem using
polynomials and obtain the characteristic equation and eigenvalues. Although it
is possible to find the eigenvectors, it is rather tedious when the number of
degrees of freedom is large.
Let us consider a 3 degree of freedom system shown in the figure above
and compute its system properties.
| m=m
|
1.5 0 0
0 1.5 0
0 0 1
and | a=
1
k
|
0.5 0.5 0.5
0.5 1.5 1.5
0.5 1.5 2.5