Вы находитесь на странице: 1из 7

D&S Lab Report

Objective: To solve a non-linear algebraic equation using Newton-Rapshon's method on scilab.

Theory: The Newton-Raphson method is one of the most widely used methods for root finding.
It can be easily generalized to the problem of finding solutions of a system of non-linear
equations, which is referred to as Newton's technique. Moreover, it can be shown that the
technique is quadratically convergent as we approach the root.

Unlike the bisection and false position methods, the Newton-Raphson (N-R) technique requires
only one initial value x0, which we will refer to as the initial guess for the root. To see how the
N-R method works, we can rewrite the function f(x) using a Taylor series expansion in (x-x0):

f(x) = f(x0) + f'(x0)(x-x0) + 1/2 f''(x0)(x-x0)2 + ... = 0  (1)

where f'(x) denotes the first derivative of f(x) with respect to x, f''(x) is the second derivative, and
so forth. Now, suppose the initial guess is pretty close to the real root. Then (x-x0) is small, and
only the first few terms in the series are important to get an accurate estimate of the true root,
given x0. By truncating the series at the second term (linear in x), we obtain the N-R iteration
formula for getting a better estimate of the true root:

(2)

Thus the N-R method finds the tangent to the function f(x) at x=x0 and extrapolates it to intersect
the x axis to get x1. This point of intersection is taken as the new approximation to the root and
the procedure is repeated until convergence is obtained whenever possible. Mathematically,
given the value of x = xi at the end of the ith iteration, we obtain xi+1 as
(3)
 

 The algorithm for Newton-Raphson's method is:

(1) Take an initial value xi

(2) Calculate  f and  f'=d f/dx at the value of xi

(3) Calculate the new value of x, using equation(3)

(4) Check if | xi+1- xi | < e if yes; stop, else

(5) Make xi+1= xi and go to step(2) and repeat the procedure till the condition stated in (4) is
satisfied. e is the convergence criterion and may be of the order 10-6.

Newton-Raphson method concept


*Program Code

Prog.(1) Determine the positive root of  f(x) = x10 - 1 using Newton-Raphson method and an
initial guess of x0 = 0.5

//Solving a non-linear equation using Newton-Raphson method


clc;
clear;
close;
x0=input('Enter the Initial Guess');
e=input('Enter the value of Accuracy');
i=0; //Initializing no of Iterations
deff('y=f(x)','y=x^10-1') //Defining the function f(x)=0
deff('y=fd(x)','y=10*x^9') //Defining the function f'(x)=0
printf('\n Iteration no\t\t x0\t\t x1');
x1=x0-(f(x0)/fd(x0)); //The Newton-Raphson formula
printf('\n %f\t\t %f\t\t %f',i,x0,x1);
while(abs(x1-x0)>e)
x0=x1;
x1=x0-(f(x0)/fd(x0));
i=i+1;
printf('\n %f\t\t %f\t\t %f',i,x0,x1);
end
printf('The value of root x after %f Iteration = %f',i,x1);

*Console Window Execution

Enter the Initial Guess


0.5

Enter the value of Accuracy


0.001

x1
0.000000 0.500000 51.650000
1.000000 51.650000 46.485000
2.000000 46.485000 41.836500
3.000000 41.836500 37.652850
4.000000 37.652850 33.887565
5.000000 33.887565 30.498809
6.000000 30.498809 27.448928
7.000000 27.448928 24.704035
8.000000 24.704035 22.233631
9.000000 22.233631 20.010268
10.000000 20.010268 18.009241
11.000000 18.009241 16.208317
12.000000 16.208317 14.587486
13.000000 14.587486 13.128737
14.000000 13.128737 11.815863
15.000000 11.815863 10.634277
16.000000 10.634277 9.570849
17.000000 9.570849 8.613764
18.000000 8.613764 7.752388
19.000000 7.752388 6.977149
20.000000 6.977149 6.279434
21.000000 6.279434 5.651491
22.000000 5.651491 5.086342
23.000000 5.086342 4.577708
24.000000 4.577708 4.119937
25.000000 4.119937 3.707944
26.000000 3.707944 3.337150
27.000000 3.337150 3.003437
28.000000 3.003437 2.703098
29.000000 2.703098 2.432801
30.000000 2.432801 2.189555
31.000000 2.189555 1.970686
32.000000 1.970686 1.773840
33.000000 1.773840 1.597031
34.000000 1.597031 1.438808
35.000000 1.438808 1.298711
36.000000 1.298711 1.178355
37.000000 1.178355 1.083350
38.000000 1.083350 1.023665
39.000000 1.023665 1.002316
40.000000 1.002316 1.000024
41.000000 1.000024 1.000000 The value of root x after 41.000000
Iteration = 1.000000

Prog.(2) Determine the positive root of  f(x) = x3-5x+1=0 using Newton-Raphson method and an
initial guess of x0 = 0.5

//Solving a non-linear equation using Newton-Raphson method


clc;
clear;
close;
x0=input('Enter the Initial Guess');
e=input('Enter the value of Accuracy');
i=0; //Initializing no of Iterations
deff('y=f(x)','y=x^3-5*x+1') //Defining the function f(x)=0
deff('y=fd(x)','y=3*x^2-5') //Defining the function f'(x)=0
printf('\n Iteration no\t\t x0\t\t x1');
x1=x0-(f(x0)/fd(x0)); //The Newton-Rapshon formula
printf('\n %f\t\t %f\t\t %f',i,x0,x1);
while(abs(x1-x0)>e)
x0=x1;
x1=x0-(f(x0)/fd(x0));
i=i+1;
printf('\n %f\t\t %f\t\t %f',i,x0,x1);
end
printf('The value of root x after %f Iteration = %f',i,x1);

*Console Window Execution

Enter the Initial Guess


0.5

Enter the value of Accuracy


0.001

Iteration no x0 x1
0.000000 0.500000 0.176471
1.000000 0.176471 0.201568
2.000000 0.201568 0.201640 The value of root x after 2.000000
Iteration = 0.201640

Pressure drop & friction factor in a Pipe

Objective: To calculate friction factor & pressure drop in a Pipe through Colebrook Equation
on scilab.

Theory: The Colebrook–White equation, sometimes referred to simply as


the Colebrook equation is a relationship between the friction factor and the Reynolds number,
pipe roughness, and inside diameter of pipe. The following form of the Colebrook equation is
used to calculate the friction factor in gas pipelines in turbulent flow.
*Program Code

function value=fn(f, a, b);


value=1/sqrt(f)+2.0*log10(a+b*f^(-0.5));
endfunction
function value=fnDash(f, a, b);
value=-0.5*f^(-1.5)+(b*(-0.5)*f^(-1.5))*log(10)/(a+b*f^(-0.5));
endfunction
function delta_p=get_pressure_drop(fricFact, l, v, rho, d);
delta_p=fricFact*l*v*v*rho/(2*d);
endfunction
function value=getFricFact(nRe, k);
a=k/3.7;
b=2.51/nRe;
fNew=0.01;
f=fNew;
while (1)
f=fNew;
fNew=f-fn(f,a,b)/fnDash(f,a,b);
if(abs(fNew-f)<1.0e-6) then
break;
end
end // while loop
value=fNew;
endfunction

rho =1.23; //kg/cubm


mu =1.79e-5 //kg/m-s
d =0.004; //m (4 mm dia pipe)
l =1; //1 m length
v =50; //m/sec
e =0.0015e-3; //m
// // relative roughness
k =e/d; // Raynolds num
nRe =rho*v*d/mu;
fricFact =getFricFact(nRe,k) get_pressure_drop (fricFact, l, v, rho, d)

*Console Window Execution

friction factor = 0.029099


pressure drop = 11185.097 N/m 2

f fNew
0.010000 0.017503
0.017503 0.024358
0.024358 0.027878
0.027878 0.028870
0.028870 0.029061
0.029061 0.029093
0.029093 0.029099
0.029099 0.029099
Varun Kumar Azad
Final Year Chemical Engineering
Roll No:170103050

Вам также может понравиться