Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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
1.8723224
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)
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
--> 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
Solver
use solver as
--> b=[(-(100+0));(-(0+0));(-(0+100));(-(100+100))]
--> T=linsolve(a,b)
T =
50.
25.
50.
75.
Solver List Numerical Methods & Optimization
Curve Fitting
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]'
--> 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]'
--> X=log10(x)
--> Y=log10(y)
--> 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.
Solver
use solver as
--> x=[0.1 0.2 0.3 0.4]'
--> Y=log(y)
--> c=X\Y
c =
2.0525728
0.3878921
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
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
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
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]'
--> 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
--> 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.