5th National Conference on Role of Engineers in Nation Building, 3rd and 4th March, 2017
APPLICATION OF SCILAB ON NUMERICAL COMPUTATIONS Jayesh Jain
Ajazul Haque
Bhagyashri Netke
Ramashankar Prajapati
Assistant Professor Viva Institute Of Technology Virar (E),Mumbai(India)
Assistant Professor Viva Institute Of Technology Virar (E),Mumbai(India)
Assistant Professor Viva Institute Of Technology Virar (E),Mumbai(India)
Assistant Professor Viva Institute Of Technology Virar (E),Mumbai(India)
[email protected]
[email protected]
ramashankar.p28@gmail.
[email protected]
com.
ABSTRACT Numerical methods are very important to solve mathematical expressions of engineering and scientific problems. Its provide a way for the engineer to translate the language of mathematics and physics into information that may be used to make engineering decisions. Often, this translation is implemented so that calculations may be done by machines (computers). This paper represent application of Scilab, which is used to carter the problems related to mathematical modeling such as Matrices, some numerical methods like Euler,s method, Rungekutta method, Trapezoidal method, Gauss saideal method, statestics problem, operation with differential equation and evaluation of double integration etc.
Keywords
in engineering problem solving has increased dramatically in recent years. Today, scilab is a free software on a computer which provide an alternative of numerical methods for such complicated calculations.
1.2 Introduction Of Scilab Open source software is a Free software that is available without any cost ,anyone can modify it and distribute. Scilab is free and open source software for numerical compytation providing a powerful computing environment for engineering and scientific applications. Gathering both industrial needs and scientific advances, scilab covers a wide sprectum of areas: Such as Space, Aeronautics, Automotive, Energy, Defense, Finance, Chemistry, Biology, Medicine etc.
Mathematics, Numerical Methods, Scilab programming.
1. INTRODUCTION 1.1 Introduction Of Numerical Methods Numerical methods have been used to solve mathematical expressions of engineering and scientific problems for at least 4000 years. Such methods apply numerical approximation in order to convert continuous mathematical problems into systems of discrete equations that can be solved with sufficient accuracy by machine. Numerical methods provide a way for the engineer to translate the language of mathematics and physics into information that may be used to make engineering decisions. Often, this translation is implemented so that calculations may be done by machines (computers). The types of problems that encounter as an engineer may involve a wide variety of mathematical phenomena and hence it will benefit us to have an equally wide range of numerical methods with which to approach some of the engineering problems. 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
Scilab provides about 2000 methematical functions for usual engineering and science applications including mathematical operations and data analysis. It has a high level programming language allowing access to advanced data structures,2-D,3-D Visuaalization,Optimisation, Statics,Control System Design &Analysis, Signal Processing, Application Development. 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 . Scilab also interface with LabVIEW, a platform and development environment for visual programming languages from National Instruments. 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. Commands for Scilab a)Plot y = f(x) plot(x,y) b) Plot x = f(t), y = f(t) plot(t,x,t,y) c) Polar plot r = f(theta) polarplot (r,theta) d) Single integral intergrate(expr,v,x0,x1,[ra]) e) Double integral int2d(X,Y,f) f)Triple integral int3d(X,Y,Z,”int3dex”) g) Ordinary differential equation (ode) y = ode(y0,x0,x,f)
5th National Conference on Role of Engineers in Nation Building, 3rd and 4th March, 2017
Symbols for scilab SR NO 1
Operation
Symbol
Example
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.
Addition
+
2+3
2 3
Subtraction Multiplication
*
4-1 2*5
4 5
Division Power
/ ^
5/7 2^5
6
Exponential i.e power of Comments
exp( )
exp(5)
This paper discussed the some topics that involved in engineering solving and basic conceptual using Scilab programming.
//
//ELLIPSE
4. CASE STUDIES
Sin(x),cos(x)
10
Trigonometric Function Hyperbolic Function Square root
Sqrt
Sqrt(3)
Case Study 1 : Matrices 𝟏 𝟏 𝟑 Verify the matrix A=[𝟏 𝟓 𝟏] is diagonalizable.Find the 𝟑 𝟏 𝟏 transforming matrix and diagonal matrix.
11
Array
:
Y=-1:0.2:2
7 8 9
Sinh(x),cosh(x)
2. 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 . In recent times, it has gained more attention and awareness in other fields such as bioengineering, economics, biology, epidemiology and the medical sciences. 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.
3. BENEFIT OF NUMERICAL METHODS Numerical methods are extremely powerful problemsolving 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 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-
clear clc A=[1 1 3;1 5 1;3 1 1] disp("let R represents the matrix of transformation and P represents a diagonal matrix whose values are the eigen values of A.then ") [R P]=spec(A) disp("R is normalised. let U represents unnormalised version of r ") U(:,1)=R(:,1)*sqrt(2); U(:,2)=R(:,2)*sqrt(3); U(:,3)=R(:,3)*sqrt(6) disp("three eigen vectors are the three columns of U") OUTPUT:A = 1. 1. 3. 1. 5. 1. 3. 1. 1. Since the eigen values -2,3,6 are distinct, thus the matrix A is digonalisable. let M represents the matrix of transformation and D represents a diagonal matrix whose values are the eigen values of A.Then D = - 2. 0. 0. 0. 3. 0. 0. 0. 6. M = - 0.7071068 0.5773503 0.4082483 - 9.000D-17 - 0.5773503 0.8164966 0.7071068 0.5773503 0.4082483
5th National Conference on Role of Engineers in Nation Building, 3rd and 4th March, 2017
Case Study 2 : Differential Equations
CaseStudy 3 Double Integrals
Solve dy/dx=(y-x)/(y+x) given y(0)=1 and find y(0.5). Evaluate the integral f(x,y)=(x^2+y^2) over the region bounded by the lines x=0 , x=1 ; y=0 , y=2.
function ydot=f(x,y), ydot=(y-x)/(y+x), endfunction
x=[0,0;1,1;1,0]; //form 3X2 matrix with abscissae of the vertices of the triangles in //the defined region
//define the function dy/dx=(y-x)/(y+x), y0=1;x0=0; y=[0,0;2,2;0,2];
//form 3X2 matrix with ordinates of the vertices of the triangles in //the defined region
deff('z=f(x,y)','z=(x^2+y^2)') function f(x,y)
//define the integrand as a
[I,e]=int2d(x,y,f) and the estimated error
//evaluate the definite integral
//specify the initial conditions x=0.5; //assign value of x at which y is to be evaluated y=ode(y0,x0,x,f) //function to solve the differential equation ydot //with given initial conditions at x=0.5 x=0:.01:.5;
OUTPUT: e = 7.401D-16 ;
I = 3.3333333
//populate x vector with values from 0 to 0.5 with an interval
Case Study 4 Numerical Methods
of 0.01 (i)Using Euler’s method find the approximate value of y at x =0.1 in 5 steps, given that
y=ode(y0,x0,x,f);
𝒅𝒚
//Find y for all x ranging from 0 to 0.5
=
(𝒚−𝒙) (𝒚+𝒙)
and y(0) = 1
Sol:
plot(x,y)
-->deff('[df]=g(x,y)','df=(y-x)/(y+x)');
//plot y against x title('dy / dx = (y-x) / (y+x)','fontsize',5) //Give the title to the plot with a font size of 5 OUTPUT:
𝒅𝒙
y =1.339209
-->x0=0;y0=1;dx=0.02;xn=0.1; -->x=[x0:dx:xn];y=zeros(x);n=length(y); -->n n = 6. -->y(1)=1 y = 1. 0. 0. 0. 0. 0. -->for j=1:n-1 -->y(j+1)=y(j)+dx*g(x(j),y(j)); -->end; -->y(6) ans =
5th National Conference on Role of Engineers in Nation Building, 3rd and 4th March, 2017
ans =
1.0928319
1.13727 (ii) Apply Runge- Kutta method of fourth order to find an 𝒅𝒚 approximate value of y when x=0.2, given that = x+y 𝒅𝒙 when y = 1 at x = 0.
-->x=(0:0.2:1) x = 0. 0.2
Sol:
1.
-->y=((sin(x)+cos(x))^1/2) !
-->deff('[df]=f(x,y)','df=x+y') -->x0=0;y0=1;dx=0.2;xn=1;
Warning: Syntax "vector ^ scalar" is obsolete. It will be removed in Scilab 6.0. Use "vector .^ scalar" instead.
-->x=[x0:dx:xn]; -->y=zeros(x);
y =
-->x(1)=x0 x = 0. 0.2
0.4 0.6 0.8
0.5 0.5893680 0.6552397 0.6908866 0.4 0.6 0.8
1.
0.6949890 0.7070314
-->inttrap(x,y) ans =
-->y(1)=y0 y =
0.6484143
1. 0. 0. 0. 0. 0.
-->y=((sin(x)+cos(x))^(1/2)) !
-->n=2 n =
Warning: Syntax "vector ^ scalar" is obsolete. It will be removed in Scilab 6.0. Use "vector .^ scalar" instead.
2. -->for i=1:n -->k1=dx*f(x(i),y(i)); -->k2=dx*f(x(i)+dx/2,y(i)+k1/2); -->k3=dx*f(x(i)+dx/2,y(i)+k2/2); -->k4=dx*f(x(i)+dx,y(i)+k3); -->k=(k1+2*k2+2*k3+k4)/6; -->y(i+1)=y(i)+k; -->x(i+1)=x(i)+dx; -->end;
y = 1. 1.085696 1.1447617 1.1754885
1.1789733 1.1891437
-->inttrap(x,y) ans = 1.1372638
-->disp(y(i)) 1.2428 𝟏 (iii) Evaluate ∫𝟎 √𝒔𝒊𝒏𝒙 + 𝒄𝒐𝒔𝒙 dx by trapezoidal rule using the following data x :0
0.2
0.4
0.6
0.8
1
Case Study 5: Intersection of Surfaces
Plot the surfaces defined by the cylinder z 2 + x2=8 and the paraboloid z=0.2(x2 +y2 ) and show their intersection. //program for plotting cylinder
y : 1 1.0857
1.1448 1.1790 1.1891 1.1755 deff('[z]=f1(x,y)','z=sqrt(8-x^2)')
Sol:
x= [-2.9:0.05:2.9]; y = x; -->x=(0:0.2:1) x = 0. 0.2
0.4 0.6 0.8
z=feval(x,y,f1); 1.
-->y=[1,1.0857,1.1448,1.1790,1.1891,1.1755] y = 1. 1.0857 1.1448 1.179 1.1891 -->inttrap(x,y)
surf(x,y,z','edgecolor',[1 1 1],'facecolor',[0 0 1] surf(x,y,-z','edgecolor',[0 0 1],'facecolor',[0 0 1]);
1.1755 //program for plotting paraboloid
5th National Conference on Role of Engineers in Nation Building, 3rd and 4th March, 2017
deff('[z]=f2(x,y)','z=(x^2+y^2)/5') x= [-4:0.05:4]; y = [-4:0.05:4]; z=feval(x,y,f2); surf(x,y,z','edgecolor',[1 0 1],'facecolor',[1 0 1]);
u2=(1/n)*(integrate ('(x^2)*(x^3)','x',0,1)+integrate('(x^2)*((2-x)^3)','x',1,2)) disp('standard deviation=(u2-u1^2)^0.5=') (u2-u1^2)^0.5 disp('mean deviation about the mean=(1/n)*(integrate (|x1|*(x^3),x,0,1)+integrate(|x-1|*((2-x)^3),x,1,2`)') (1/n)*(integrate ('(1-x)*(x^3)','x',0,1)+integrate('(x-1)*((2x)^3)','x',1,2))
Output OUTPUT:total frequency= integrate (f,x,0,2 ) n = 0.5 u1 about origin= u1 = 1. u2 about origin= u2 = 1.0666667 standard deviation=(u2-u1^2)^0.5= ans = 0.2581989 mean deviation about the mean=(1/n)*(integrate (|x1|*(x^3),x,0,1)+integrate(|x-1|*((2-x)^3),x,1,2`) ans = 0.2 (iii)Correlation And Regression Lines Find the coefficient of regression and hence the equations of the lines of regression for the following data x= 60, 62, 64, 65, 66, 67, 68, 70, 72, 74 y= 63.6, 65.2, 66 ,65.5, 66.9, 67.1, 67.4, 68.3, 70.1, 70 Draw the lines of regression from your equations on the graph. What is the significance of the point of intersection of the two lines.
Case Study 6: Statistics (i) Find the expectation of the number of points on the dice. p1=1/6; p2=1/6; p3=1/6; p4=1/6; p5=1/6; p6=1/6; expec= p1 + (2*p2)+(3*p3)+(4*p4)+(5*p5)+ (6*p6); disp(expec) OUTPUT:3.5 (ii) A random variable X has the probability density function 𝒙𝟑 𝟎