You are on page 1of 8

# Proceedings of the 2

nd
International Conference on Mathematical Applications in Engineering (ICMAE2012)

BASIC OF NUMERICAL COMPUTATIONAL USING SCILAB
PROGRAMMING

Z.Salleh
1
, M.Y.M Yusop
2
and S.B. Ismail
3

1,2,3
Malaysian Institute of Marine Engineering Technology
Universiti Kuala-Lumpur 32200 Lumut, Perak, Malaysia

ABSTRACT

Mathematics is very important for the engineering and scientist but to make understand the mathematics is very difficult if without proper
tools and suitable measurement. A numerical method is one of the algorithms which involved with computer programming. In this paper,
Scilab is used to carter the problems related the mathematical models such as Matrices, operation with ODE’s and solving the Integration.

Keywords: Mathematics; Numerical Methods; Scilab programming

1 Introduction

Numerical methods are techniques by which mathematical problems are formulated so that they can be solved
with arithmetic operations. Although there are many kinds of numerical methods, they have one common
characteristic: they invariably involve large numbers of tedious arithmetic calculations. It is little wonder that
with the development of fast, efficient digital computers, the role of numerical methods in engineering problem
solving has increased dramatically in recent years. Today, computers and numerical methods provide an
alternative for such complicated calculations. Using computer power to obtain solutions directly, it can
approach these calculations without recourse to simplifying assumptions or time-intensive techniques. Although
analytical solutions are still extremely valuable both for problem solving and for providing insight, numerical
methods represent alternatives that greatly enlarge your capabilities to confront and solve problems. As a result,
more time is available for the use of your creative skills. Thus, more emphasis can be placed on problem
formulation and solution interpretation and the incorporation of total system, or “holistic” awareness. Since the
late 1940s the widespread availability of digital computers has led to a veritable explosion in the use and
development of numerical methods [1]. At first, this growth was somewhat limited by the cost of access to large
mainframe computers, and, consequently, many engineers continued to use simple analytical approaches in a
significant portion of their work.

2 Background

2.1 Benefit of Numerical methods

Numerical methods are extremely powerful problem-solving tools. They are capable of handling large systems
of equations, nonlinearities, and complicated geometries that are not uncommon in engineering practice and that
are often impossible to solve analytically. As such, they greatly enhance your problem-solving skills. During
engineer careers, it might be often have occasion to use commercially available prepackaged, or “canned,”
computer programs that involve numerical methods. The intelligent use of these programs is often predicated on
knowledge of the basic theory underlying the methods. Many problems cannot be approached using canned
programs. It is well known that an effective way to learn programming is to actually write computer programs.
Because numerical methods are for the most part designed for implementation on computers, they are ideal for
this purpose. Further, they are especially well-suited to illustrate the power and the limitations of computers.
Numerical methods provide a vehicle for you to reinforce your understanding of mathematics. Because one
function of numerical methods is to reduce higher mathematics to basic arithmetic operations, they get at the
“nuts and bolts” of some otherwise obscure topics. Enhanced understanding and insight can result from this
alternative perspective.

2.2 Introduction to Scilab programming

Scilab is a programming language associated with a rich collection of numerical algorithms covering many
aspects of scientific computing problems. From the software point of view Scilab is an interpreted language.
Scilab language allows to dynamically compile and link other languages such as FOTRAN, MATLAB, C++ if
they were a part of built-in features [2]. Scilab also interface with LabVIEW, a platform and development
environment for visual programming languages from National Instruments. Cost for Scilab is free source
software and no need to pay for license because it is provided under the Cecill license. Scilab comes with many
features and rapidly the number of features extended to cover many areas of scientific computing. The
following is a short list of its capabilities for Scilab such as Matrices, Polynomials, Linear equation, Signal
processing, Ordinary differential equation and statistic. The Scilab console for the windows mode shows at
Figure 1.

Figure 1. Scilab console

Figure 2. Scilab Text Editor (Scinotes)
The Scilab also provided an editor to edit script easily. The editor can be accessed from the menu of the console,
under the Application> Editor menu or from the console [3]. The Figure 2 shows the Scilab Text Editor. This
editor allows managing several files at the same time. The following example, the function display is used in
interactive mode to print the string ‘Hello World!’.

2.3 Study of Numerical Methods

Study the Numerical methods always involve with the topics related to generate the Matrices which are solving
the linear equation, ODE’s Ordinary Differential Equation and Numerical Integration. Numerical methods use
mathematical modeling forms an important part of many tertiary courses in mathematics and engineering [4]. In
recent times, it has gained more attention and awareness in other fields such as bioengineering, economics,
biology, epidemiology and the medical sciences [5]. Traditionally, the techniques used and skills involved are
confined to deterministic models based on concepts from algebra, vector calculus, regression, differential
equations and so on. In this paper, we discuss the common topics that involved in engineering solving and basic
conceptual using Scilab programming.

A) Matrices

The matrix A has m rows and n columns. Scilab has multidimensional matrices. In this paper, we will introduce
the main functions and operations of generating matrices, extracting data from arrays, using special matrices,
and applications to solve problem in linear algebra using Scilab. The Matrix A shown at below;

|
|
|
|
|
.
|

\
|
=
amn am am am
n a a a a
n a a a a
n a a a a
A
.... 3 2 1
3 .... 33 32 31
2 .... 23 22 21
1 .... 13 12 11

Where m = rows and n = columns

Case Study 1

Solve the linear system using Gauss-Jordan methods.

−2x + y +2z = 4, x −4y −2z = −6,−x +2y −2z = 2

Use the Scilab editor the solution is state as;

A=[-2 1 2 4; 1 -4 -2 -6; -1 2 -2 2], AR= rref(A)
A =
-2 1 2 4
1 -4 -2 -6
-1 2 -2 2
AR =
1.0000 0 0 -1.0000
0 1.0000 0 1.0000
0 0 1.0000 0.5000

The solution is the vector (x, y, z) = (−1,1,0.5)
Then it can be compared with Gauss-Jordan formula, the matrices can be written as;
|
|
|
|
|
.
|

\
|
÷ ÷
÷ ÷ ÷
÷
=
2 2 2 1
6 2 4 1
4 2 1 2
A

The pivot element for a
11
is -2, so all the element at E
1
need to divided with -2, to yield

|
|
|
|
|
.
|

\
|
÷ ÷
÷ ÷ ÷
÷ ÷ ÷
2 2 2 1
6 2 4 1
2 1 5 . 0 1

The x
1
term can be eliminated from the second row by subtracting 1 times the first row from the second row.
Similarly, subtracting -1 times the first row from the third row will eliminate the x
1
term from the third row.
|
|
|
|
|
.
|

\
|
÷
÷ ÷ ÷
0 3 5 . 1 0
1429 . 1 2857 . 0 1 0
2 1 5 . 0 1

Reduction of the x
2
term from the first and third equations gives
|
|
|
|
|
.
|

\
| ÷ ÷
171435 42855 . 3 0 0
1429 . 1 2857 . 0 1 0
42855 . 1 85715 . 0 0 1

Finally, the x
3
terms can be reduced from the first and the second equations to give;
|
|
|
|
|
.
|

\
| ÷
5000 . 0 1 0 0
0000 . 1 0 1 0
0000 . 1 0 0 1

Thus, Gauss-Jordan method technique can be solve either using Scilab or manually but the algorithm must be
same for both of the methods. A solution of an ordinary differential equation is a specific function of the
independent variable and parameters that satisfies the original differential equation. To illustrate this concept,

y = −0.5x
4
+ 4x
3
− 10x
2
+ 8.5x + 1, which is a fourth-order polynomial. If we differentiate equation, it obtains an
Ordinary’s Differential Equation (ODE):
5 . 8 20 12 2
2 3
+ ÷ + ÷ = x x x
dx
dy

Case Study 2
Solve the ODE function using Scilab;
) cos( ) sin(
2
t t y y
dt
dy
+ ÷ =

Solution:
// ---------- Simple one dimension ODE (Scilab function external)
// dy/dt=y^2-y sin(t)+cos(t), y(0)=0
function ydot=f(t, y),ydot=y^2-y*sin(t)+cos(t),endfunction
y0=0;t0=0;t=0:0.1:%pi;
y=ode(y0,t0,t,f)

Figure 3. Output for Case study 2(A)
B) Integration
The approximation of definite integral
}
b
a
dx x f ) (
is called quadrature and it is based on numerical methods such
as trapezoidal, Simpson formulas, and others. Scilab has a set of built-in functions to calculate the definite
integrals, such as ‘intg’, ‘integrate’, ‘int2d’, ‘int3d’.

Case Study 1
Compute the Area for Integral
( )
}
|
.
|

\
|
2
0
10 sin
x
x
using Scilab.

Figure 4. Output for Case study 1(B)
Solution:

function y=f(x),y=abs(sin(10*x)/x) ;endfunction
I=intg(0,2,f)
I = 3.0128756
x=linspace(%eps,2,200);
fplot2d(x,f)
xtitle(’|sin(10*x)./x|’)

Case Study 2
Plot the graph with grid line for the function y = 3x −x
3
on [−3,2] with step size 0.1
Solution:

clf
x = -3:0.1:2;
y = 3*x-(x).^3;
plot(x,y);
xtitle(’Cube Function’, ’X’, ’Y’, boxed =1 );
a=get("current_axes");//get the handle of the newly created axes
a.data_bounds=[-4,-4;3,5]; // left corner and upper right corner
//axis([-4 3 -4 5]) in Scilab
xgrid()

Figure 5. Output for Case study 2(B)

Case Study 3
Plot the graph and rotate namely “monkey saddle surface”
z = x
3
−3x y
2
and plot its level curves and contours over the domain [−3,3]×[−3,3].
Solution:
clf
x=-3:.1:3;
y=-3:.1:3;
function z=f(x,y),z=x^3-3*x*y^2 ;endfunction
fplot3d(x,y,f);
// Using meshgrid commands
clf
[X,Y] = meshgrid(x,y);
Z=X.^3 -3*X.*Y.^2;
mesh(X,Y,Z)

Figure 6. Output for Case study 3(B)

3 Conclusion

Numerical methods can be expressly presented by using the open source computational programming such
Scilab or any powerful programming in the market. The entire algorithm in Numeric calculation is very useful
for engineering and scientist to explore the solution which is involved with mathematical model. Instead of
display or write at whiteboard for mathematical education but it can be also project into the screen from the
beginning stage of learning process especially for Numerical methods in engineering technology educational.

4 References

[1] Steven C. Chapra, Raymond P. Canale,2010. Numerical Methods for Engineers 6
th
Edition, Mc Graw Hill,
International Edition.
[2] Salleh. Z, 2011. Fundamental of Numerical Methods for Scientists and Engineers, 1
st
Edition, Lambert