Sei sulla pagina 1di 11

Solver List Numerical Methods & Optimization

Solvers for SCILAB software

Roots of Equations

1. Write a program to solve root of equation f(x)= -0.9x2+1.7x+2.5. With initial guesses x1=
2.8 and x2 =3, using three iteration of bi-section method.
Solver
In console window define function as

--> deff('y=f(x)','y=-0.9*x*x+1.7*x+2.5')
use solver as
--> fsolve(2.5,f)
Then we will get answer as

ans =

2.8601044

2. Write a program to solve root of equation f(x)=0.51x-sinx using three iterations of


newton raphson method.
Solver
In console window define function as
--> deff('y=f(x)','y=0.51*x-sin(x)')
use solver as
--> fsolve(2,f)
Then we will get answer as
ans =

1.8723224

3. Write a program to solve root of equation x3 -15x+8=0 using Successive Iteration


Method

Solver
In console window define function as
--> deff('y=f(x)','y=x*x*x-15*x+8')
use solver as
--> fsolve(0,f)
Then we will get answer as
ans =

0.5440701
Solver List Numerical Methods & Optimization
Simultaneous Equations

1. Solve following set of equation using Gauss elimination method with partial pivoting
X+3y+z=10 X+2y+5z=12 4X+y+2z=16
Solver
Define Coefficient Matrix in console window
--> a=[1 3 1;1 2 5; 4 1 2]
Define Constant Matrix in console window
(Note: while writing constant matrix consider terms to LHS ( -ve))
--> b=[-10;-12;-16]
use solver as
--> c=linsolve(a,b)

Then we will get answer as


c =
3.
2.
1.
2. Solve following set of equation using Tridigonal matrix algoritham(Thomas method)
method
X+2y=3 2x+3y+z=4 2y-z=1
Solver
Define Coefficient Matrix in console window
--> a=[1 2 0;2 3 1; 0 2 -1]
Define Constant Matrix in console window
(Note: while writing constant matrix consider terms to LHS ( -ve))
--> b=[-3;-4;-1]
use solver as
--> c=linsolve(a,b)
Then we will get answer as
c =
5.
-1.
-3.
3. Solve the following equations by Gauass Seidal Method.
x1+20x2+9x3= -23 , 2x1-7x2-20x3= -57 and 20x1+2x2+6x3=28 . Write a Computer program .
Assume Acc=0.001

Solver
Define Coefficient Matrix in console window
--> a=[1 20 9; 2 -7 -20;20 2 6]
Define Constant Matrix in console window
(Note: while writing constant matrix consider terms to LHS ( -ve))
--> b=[23;57;-28]
use solver as
--> c=linsolve(a,b)
Then we will get answer as
c =
0.5148287
-2.9452923
3.9323352
Solver List Numerical Methods & Optimization
Optimization

1. Minimize Z=25x+30y subjected to,


4x+3y>60
2x+3y>36
x, y>0
Solver
Define Objective function Matrix in console window
--> z=[25 30]
Define Coefficient Matrix in console window
--> a=[4 3;2 3]
Define Constant Matrix in console window
(Note: while writing constant matrix consider terms to LHS ( -ve))

--> b=[-60;-36]
use solver as
--> c=linsolve(a,b)
--> z=z*c
Then we will get answer as
z =
420.
Solver List Numerical Methods & Optimization
ODE

1. Solve dy/dx = x+2y for given boundary condition that x=1,y=1 find y(1.4) take h=0.1. using
Eulers Method
Solver
Note: ans=ode(y0,x0,x0:h:xn,f)

use solver as
--> deff('y=f(x,y)','y=x+2*y')
--> ans=ode(1,1,1:0.1:1.4,f)
Then we will get answer as

ans =
column 1 to 3
1 1.3374549 1.7606934
column 4 to 5
2.2887081 2.9446969
2. Solve dy/dx = x+y for given boundary condition that x=0,y=1 find y(0.2) take h=0.1. using
RK2 method.

Solver
Note: ans=ode(y0,x0,x0:h:xn,f)

use solver as
--> deff('y=f(x,y)','y=x+y')
--> ans=ode(1,0,0:0.1:0.2,f)
Then we will get answer as

ans =
1. 1.1103418 1.2428055
Solver List Numerical Methods & Optimization
PDE

1. Solve Elliptic Laplace equation w.r.t. grid


shown in fig. with specified BCs.
Find Temp.,T1, T2, T3, T4
H=K=250.Write a Computer program

Solver
use solver as

--> a=[4 -1 0 -1;-1 4 -1 0;0 -1 4 -1; -1 0 -1 4]

--> b=[(-(100+0));(-(0+0));(-(0+100));(-(100+100))]

--> T=linsolve(a,b)

Then we will get answer as

T =

50.
25.
50.
75.
Solver List Numerical Methods & Optimization
Curve Fitting

1. Fit a straight line using following data. Find values of a and b.

X 1 2 3 4 5 6 7
Y 0.5 2.5 2 4 3.5 6 5.5

Solver
use solver as
--> x=[1 2 3 4 5 6 7]'

--> y=[0.5 2.5 2 4 3.5 6 5.5]'

--> X=[x ones(x)]

--> c=X\y
Then we will get answer as

c =

0.8392857
0.0714286

2. For given data fit a Power equation y=axb . find value of a and b.

X 1 2 3 4 5
Y 0.5 2 4.5 8 12.5
Solver
use solver as
--> x=[1 2 3 4 5]'

--> y=[0.5 2 4.5 8 12.5]'

--> X=log10(x)

--> Y=log10(y)

--> X=[ X ones(X)]

--> c=X\Y
Then we will get answer as

c =
2.
-0.30103
To calculate a & b Values use
--> a=10^c(2)
--> b=c(1)

a =
0.5
Solver List Numerical Methods & Optimization
b =

2.

3. Fit a exponential equation y=aebx . find value of a and b.


X 0.1 0.2 0.3 0.4
Y 1.8 2.238 2.733 3.338

Solver
use solver as
--> x=[0.1 0.2 0.3 0.4]'

--> y=[1.8 2.238 2.733 3.338]'

--> Y=log(y)

--> X=[x ones(x)]

--> c=X\Y

Then we will get answer as

c =
2.0525728
0.3878921

To calculate a & b Values use


--> a=exp(c(2))
--> b=c(1)

a =

1.4738707

b =

2.0525728
Solver List Numerical Methods & Optimization
Interpolation

1. Using Langranges interpolation formula for given set of values find y(1.5)

X 0 1 2 5
Y=f(x) 2 3 12 147
Solver
use solver as
--> x=[0 1 2 5]
--> y=[2 3 12 147]
--> d=splin(x,y)
--> interp(1.5,x,y,d)
Then we will get answer as

ans =

6.125

2. Using newtons forward interpolation formula for given set of values find y (3.5)

x 2 3 4 5 6 7 8 9
Y=F(x) 19 48 99 178 291 444 643 894

Solver
use solver as
--> x=[2 3 4 5 6 7 8 9]
--> y=[19 48 99 178 291 444 643 894]
--> d=splin(x,y)
--> interp(3.5,x,y,d)
Then we will get answer as

ans =

70.375

3. for following data using backward difference formula, Interpolate at x=0.25

X 0.1 0.2 0.3 0.4 0.5


F(x) 1.4 1.56 1.76 2.00 2.28
Solver
use solver as
--> x=[0.1 0.2 0.3 0.4 0.5]
--> y=[1.4 1.56 1.76 2.00 2.28]
--> d=splin(x,y)
--> interp(0.25,x,y,d)
Then we will get answer as

ans =

1.655
Solver List Numerical Methods & Optimization
Integration

1. Find the integration of 1/(1+x2) in the limits 0 to 1 by Trapezoidal rule using four
strips.

Solver
use solver as
--> deff('y=f(x,y)','y=1/(1+x*x)')
--> intg(0,1,f)
Then we will get answer as

ans =
0.7853982
OR
use solver as
--> integrate('1/(1+x*x)','x',0,1)
Then we will get answer as

ans =
0.7853982

2. Find the integration of (4x-1).dx in the limits 1 to 4 by Simpsons 3/8 Rule using six
strips.

Solver
use solver as
--> integrate('4*x-1','x',1,4)
Then we will get answer as

ans =

27.
3. Find the integration of ex in the limits 0 to 4 by Simpsons 1/3 Rule using four
strips.

Solver
use solver as
--> integrate('(exp(x))','x',0,4)
Then we will get answer as

ans =
53.59815
4. Find the integration of x3 + x -1 with limits 1 to 4 using Gauss-Legender two
point formula

Solver
use solver as
--> integrate('x*x*x+x-1','x',1,4)
Then we will get answer as

ans =

68.25
Solver List Numerical Methods & Optimization

5. Find the integration of x2 - 5x +2 with limits 3 to 5 using Gauss-Legender three


point formula

Solver
use solver as
--> integrate('x*x-5*x+2','x',3,5)
Then we will get answer as

ans =

-3.3333333

6. Find the double integration of x3 +y3+6 for x=0to 2 and y=0 to 2 taking increment
in both x and y as 0.5 by Simpsons 1/3 Rule.
(0,2) (2,2)
Solver

(0,0) (2,0)

while writing x matrix firstly consider x coordinates for upper triangle in I column
& x coordinates for Lower triangle in II column

--> x=[0 0 2;0 2 2]'

while writing y matrix firstly consider y coordinates for upper triangle in I column
& y coordinates for Lower triangle in II column
--> y=[0 2 2; 0 2 0]'

Define Given function

--> deff('y=f(x,y)','y=x*x*x+y*y*y+6')
Then use solver
--> [I, error] = int2d(x,y,f)
Then we will get answer as

error =

1.155D-14

I =

40.
Solver List Numerical Methods & Optimization

7. Find the double integration of (x+y) for x=0to 2and y=1 to 3 taking increment in
both x and y as 1 by Trapezoidal rule.

(0,3) (2,3)
Solver

(0,1) (2,1)

while writing x matrix firstly consider x coordinates for upper triangle in I column
& x coordinates for Lower triangle in II column

--> x=[0 0 2;0 2 2]'


while writing y matrix firstly consider y coordinates for upper triangle in I column
& y coordinates for Lower triangle in II column
--> y=[1 3 3;1 3 1]'
Define Given function

--> deff('y=f(x,y)','y=(x+y)')
Then use solver
--> [I, error] = int2d(x,y,f)
Then we will get answer as

error =

3.553D-15

I =

12.

Potrebbero piacerti anche