Wednesday, September 1, 2010

Solution of Non-linear Equations

Solution of Non-linear Equations:--

Algebraic equation
5x+3=0 => linear equation
x2 – 4x + 3 =0 => transcendental equation.
non linear equation
ex – x = 0
sinx + cosx = 0

eg: f(x) = x2 + 4x – 3 = 0

x1 = ? root of equation.
x2 = ? or solution.

Root is the point where function cuts x- axis.
Root is the point where function value is zero.

Graphical Method:
 Function f(x) is provided.
 Plot graph & get the roots.


Bisection Method (Half interval method):
This method is known as bolzano method, Bracketting method, binary chopping or half-interval method.
Suppose we are given the continuous function f(x) in the interval [p, q] and we want to find the root of the equation f(x)=0 by bisection method. The process is described as follows:

1) Find two points a and b such that f(a) x f(b) < 0. That is find a and b so that f(a) and f(b) are of opposite sign. This process is called finding the initial root. 2) Compute the middle point c using relation c = a+b/2. If f(c) = 0 then c is the required root & stop the process. If f(c) ≠ 0 then go to next step. 3) If f(a) x f(c) <0 then root lies between a & c otherwise the root lies between c & b. 4) Repeat the steps 2 & 3 until the root is found to be desired degree of accuracy. Advantages: • Calculation is easy. • If guesses are correct, it always give the root.(Always convergent) Disadvantages: • Process is very slow, tedious. • Guess selection is slightly calculative. Q. Finds the root of the equation x3 – 4x – 9 = 0 using bisection method of four stages. It is given that the root lies between 2 & 3. n a f(a) b f(b) c= a+b/2 f(c) 1 2 -2 3 6 2.5 -3.375 2 2.5 -3.375 3 6 2.75 0.797 3 2.5 -3.375 2.75 0.797 2.625 -1.412 4 2.625 1.412 2.75 0.797 2.6875 -0.339 The required root up to 4th stage is 2.6875. Q. Find the root of the equation x2-4x-10=0 using bisection method correct upto 3 decimal places. (Ans=>5.741)
Q. Find the root of the equation f(x) =xsinx+cosx=0 using bisection method upto 3 decimal places.
(Ans=>2.798)
Q. Find the root of the equation f(x) =ex-x=0 using bisection method correct upto 3 decimal places.
(Ans=>0.567)


Regula – Falsi method:
[Method of False – Position]
Suppose we are given continuous functions f(x) is the interval [p, q] & we want to find the root of the equation f(x) = 0 by the method of false – position. The process is described as follows:
i. Find two numbers a & b so that f(a) x f(b) <0 ii. Compute c = a f(b)-bf(a) f(b)-f(a). iii. If f(c)=0 then c is the required root & stop the process. If f(c) ≠ 0 then go to next step. iv. If f(a) x f(c) <0 then the root lies between a & c otherwise the root lies between c & b. v. Repeat the steps (ii), (iii) & (iv) until the root is found to the desired degree of accuracy. Geometrical Interpretation y-f(a)= f(b)-f(a) (x-a) b-a or, 0-f(a)= f(b)-f(a) (c-a) b-a or, c-a = - f(a) (b-a) f(b)-f(a) or, c = a - f(a) (b-a) f(b)-f(a) or, c = af(b)-af(a)-bf(a)+af(a) f(b)-f(a) Therefore, c = af(b) - bf(a) f(b)-f(a) Q. Find the root of the equation of the xlog10x-1.2=0 which lies between 2 and 3 correct to 3 places of decimal using the method of False-Position. n a f(a) b f(b) c f (c) 1 2 -0.59794 3 0.23136 2.72102 -0.01709 2 2.72102 -0.01709 3 0.23136 2.74021 -0.00038 3 2.74021 -0.00038 3 0.23136 2.74064 -5.32x106 The required root correct to 3 decimal place is 2.741 Newton-Raphson Method [Successive Substitution Method] Algorithm i. Assign an initial value to x say x0 ii. Evaluate f(x0) and f’(x0) iii. Compute x1 =x0-f(x0)/f’(x0) iv. If f(x1) =0 then x1 is the required root and stop the process. v. If(x1) ≠0 then replace x0 by x1 and repeat the process till the root is found to the desired degree of accuracy. Let x0 be the first approximation to the root of the equation f(x) =0. Let x1=x0+h be the better approximation which approximately satisfy the equation f(x) =0. Therefore, f(x0+h) = 0 approximately f(x0)+hf’(x0) + h2/2!f”( x0) + h3/ 3!f’’’+…=0 Assumption Since h is very small, neglecting its square and higher power, we get, f(x0)+hf’(x0)=0 or, h=-f(x0)/f’(x0) Therefore, x1=x0-f(x0)/f’(x0) Geometric Interpretation TanƟ = AB/AC = f(x0)/(x0-x1) or, f’(x0) = f(x0)/(x0-x1) => x0-x1= f(x0)/f’(x0)
Therefore, x1=x0- f(x0)/f’(x0)

Advantage:
• Guess selection is easy.
• Convergence is faster than bisection method.
Limitation:
• Division by zero may occur if f’(x) is zero.
• If the initial guess is too far away from the required root, the process may converge to some other root. Hence the proper choice of the initial guess is very important.

Q. Find the root of the equation 2x-tanx=0 using Newton-Raphson method. Take x0=1. Calculate the
root correct upto 5 decimal.

Let f(x) =2x-tanx
xn+1= xn-f(xn)/f’(xn)

i. x1= x0 – f(x0)/f(x1)
f(1)=2x1-tan1=0.4425923
f’(x)=2-sec2x
f’(1)=2-sec2x=-1.4255188

x1=1+0.4425923/1.4255188
=1.3104781

ii. x2=x1-f(x1)/f’(x1)
=1.3104781 – (-1.333366)
-13.0946546
=


Ans=>1.16556

Some special cases
Case I: To find the solution to compute the square root of the positive no. N

Let x= N

x2=N
or, x2-N=0
let f(x)= x2=N
f’(x)=2x
Let x0 be the initial root.
x1=x0 – f(x0)/f’(x0)
=x0- (x02-N)/2x0
= 2x02 –(x02-N)
2x0
= ½( x0+N/x0)
In general,
xn+1=½( xn+N/xn)

Case II: Show that the pth root of any given positive number N is given by
xn+1=1/p[(p-1)xn+N/xnp-1]
Let x=N1/p
or, xp-N=0
Let f(x) = xp-N
f’(x)=pxp-1
Let x0 be the initial value.
x1 = x0-f(x0)/f’(x0)
or, x1 = x0- (x0p-N)/( px0p-1)
= (px0p-x0p+N) /( px0p-1)
= (x0p(p-1)+N) /( px0p-1)
= 1/p[(x0p(p-1)+N) /( x0p-1)]
= 1/p[(p-1) x0+N/ x0p-1]
In general,
xn+1=1/p[(p-1) xn+N/ xnp-1]

Case III: Show that reciprocal of the pth root of any positive number is given by
xn+1=1/p[(p+1) xn+N xnp+1]

Let x=1/N1/p
or, x-p-N=0
Let, f(x)= x-p-N
f’(x)= -p x-p-1
Let x0 be the initial root
x1 = x0-f(x0)/f’(x0)
= x0- (x0-p – N)/px0-p-1
= (px0-p + x0-p –N)/ px0-p-1
= [x0-p(p+1)-N]/ px0-p-1
= 1/p[x0(p+1)-Nx0p+1]
In general,
xn+1=1/p[xn(p+1)-Nxnp+1]

Case IV: Derive the relation to find the value of the reciprocal of N.
Let x=1/N
or, x=N-1
x-1-N=0
Let f(x) = 1/x – N
f’(x)=-1/x2
Let x0 be the initial root
x1 = x0-f(x0)/f’(x0)
= x0- (1/x0 – N)/ (-1/x02)
= x0+ x0-N x02
= 2x0-Nx02
In general,
xn+1=2xn-Nxn2


Q. Evaluate 12 using N-R method correct upto 7 decimal places.

We have,
xn+1=½( xn+N/xn) , N=12
For n=0,
x1=½( x0+N/x0)
Let x1=3.5
x1=1/2[3.5+12/3.5]
= 3.464285714
Again,
x2=1/2[3.464285714 + 12/3.464285714]
=3.46410162
Again,
x3=1/2[3.46410162+12/3.46410162]
=3.46410162
Therefore, The required root correct to 7 decimal places is 3.4641016

Secant Method
Suppose we are given the continuous function f(x) in the interval [p, q] and we want to find the root of the equation f(x) = 0 by secant method. The process is described as follows:
i. Find two members a and b.
ii. Compute c=[af(b)-bf(a)]/[f(b)-f(a)]
iii. If f(c)=0 then c is the required root and stop the process.
iv. If (c)≠0 then set a=b, f(a)=f(b) and b=c, f(b)=f(c).
v. Repeat the step (ii), (iii) and (iv) until the required root id found to the desired degree of accuracy.

Q. Find the root correct to 3 decimal places of the equation cosx–x ex=0. It the given that the root lies
between 0.5 and 1.


n a f(a) b f(b) c f(c)
1 0.5 0.053221 1 -2.1779 0.51193 0.01764
2 1 -2.1779 0.51193 0.01764 0.51585 0.005789
3 0.51193 0.01764 0.51585 .005789 0.51776 -0.00802x10-3
4 0.51585 0.005789 0.51776 -0.00802x10-3 0.51779

Therefore the required root upto 3 decimal places is 0.518

Q. Use the secant method to find an appropriate root the equation f(x) =3x+sinx-ex correct upto 3 decimal
places with a=1 and b=0.

n a f(a) b f(b) c f(c)
1 1 1.12319 0 -1 0.47009 0.26516
2 0 -1 0.47099 0.26516 0.209591 -0.39634
3 0.47099 0.26516 0.20959 -0.39634 0.36621 0.01445
4 0.20959 -0.39634 0.36621 0.01445 0.36070 0.696x10-3
5 0. 36621 0.01445 0.36070 0.696x10-3 0.36076

Therefore, the required root upto 3 decimal places is 0.360

Iteration Method
This method is also known as direct substitution method or method of iteration or method of fixed iteration or method of successive approximation.
It is applicable if the equation f(x)=0 can be expressed as x=g(x).
If x0 is the initial approximation to the root, then the next approximation to the root is given by,
x1=g(x0)
And the next approximation will be x2=g(x1).
In general,
xn+1=g(xn)
Note: This method converges if |g’(x0)|<1 Q. Find an approximate root of the equation x2-2x-8=0 using fixed point iteration method starting with x0=5. Stop the iteration whenever |xi+1-xi|<=0.001. Solution, x2-2x-8=0 or, x2=2x+8 or, x= 2x+8 g(x)= 2x+8 g’(x)= 1 , g’(5)=0.24<1 2x+8 xi g(xi) |xi+1-xi| 5 4.24264 0.75736 4.24264 4.06021 0.18243 4.06021 4.01502 0.04519 4.01502 4.00375 0.01127 4.00375 4.00094 0.00281 4.00094 4.00023 0.00071 The required root correct to 3 decimal places is 4.000 Q. Find the root correct upto 3 decimal places to the equation 2x-x-3=0, Take x0=5. Solution, 2x-x-3=0 or, x=2x-3 g(x)= 2x-3 g’(x)= 2xloge2 g’(x)=0.037<1 xi g(xi) -3 -2.8750 -2.8750 -2.86369 -2.86369 -2.86261 -2.86369 -2.86251 The required root correct to 3 decimal places is -2.862. Horner’s Method By this method, every real root of the polynomial is found figure by figure, first by finding the integral part then by finding the decimal part and then by finding the decimal part upto the required degree of accuracy. Suppose it is required top find the root of the polynomial eg: f(x)=0. 1) Let a and a+1 be two consecutive integers such that f(a) and f(a+1) have opposite signs. Then the root lies between a and a+1 so that the integral part of the root id a. Let the root be a.a1a2a3……. 2) Diminish the roots by a. Then the root of the new equation corresponding to a is 0.a1a2a3……. 3) Multiply the root of the equation in 2) by 10. Then the transformed equation will have the root (correspondent to a) a1.a2a3…….By trail, find two consecutive integers a1 and a1+1 between which the root of the equation lies. Thus a1 is found. 4) Diminish the roots of the equation in 3) by a1 and again multiply the roots by 10. The process is repeated and we get the 2nd, 3rd etc decimal figures of the root. Q. Show that the equation x3-3x+1=0 has the root between 1 and 2. Calculate the root correct upto 2 decimal places. Let f(x) = x3-3x+1=0 f(1) =1-3+1= -1 (-ve) f(2)= 8-6+1 =3 (+ve) Let the root be 1.a1a2 Using synthetic division, 1 1 0 -3 1 1 1 -2 1 1 1 -2 -1 1 2 1 1 2 0 1 1 3 x3+3x2-1=0 0.a1a2 f(x)=x3+30x2-1000=0 Now taking x=5, f(5)= -125 (-ve) f(6) = 296 (+ve) Therefore, a1=5 5 1 30 0 -1000 5 175 875 5 1 35 175 -125 5 200 5 1 40 375 5 1 45 x3+45x2+375x-125=0 f(x)= x3+450x2+37500x-125000=0 It has root a2.a3… f(3)= (-ve) f(4)= (+ve) a2=3 So, the correct root upto 2 decimal place is 1.53 Q. Find the root of the equation f(x)=x3+9x2-18=0 correct upto 2 decimal places. (Ans=>1.32)
Q. Find the root of the equation f(x)=x3+x2-3x-3=0 correct upto 2 decimal places.(Ans=>1.73)



Programs

Bisection Method

#include
#include
float f(float x)
{
return (x*x*x-4*x-9);
}
void main()
{
int n,i;
float a,b,c;
clrscr();
printf("Enter the iteration:");
scanf("%d",&n);
printf("Enter the initial guess a and b:");
scanf("%f %f",&a,&b);
if(f(a)*f(b)>0)
{
printf("Doesnot bound the root of the equation");
}
else
{
for(i=0;i<=n;i++) { c=(a+b)/2; if(f(c)==0) break; if(f(a)*f(c)<0) { b=c; } else a=c; } printf("The required root after n iteration is %f",c); } getch(); } Secant Method #include
#include
#include
#define error .0001

float f(float x)
{
return (cos(x)-x*exp(x));

}

void main()
{
float a,b,c;
clrscr();
printf("Enter the value of a & b:");
scanf("%f %f",&a,&b);
do
{
c=(a*f(b)-b*f(a))/(f(b)-f(a));
if(f(c)==0)
break;
else
{
a=b;
b=c;
}
}while(fabs((b-a)/b)>error);
printf("the required root is %f",c);
getch();
}



Newton-Raphson Method

#include
#include
#include
#define error .0001

float f(float x)
{
return (2*x-tan(x));
}
float df(float x)
{
return(2-1/(cos(x)*cos(x)));
}
void main()
{
float initial,newvalue;
clrscr();
printf("Enter the initial value of x:");
scanf("%f",&initial);
if(df(initial)!=0)
{
do
{
newvalue=initial-f(initial)/df(initial);
if(f(newvalue)==0)
break;
else
initial=newvalue;
}while(fabs((newvalue-initial)/newvalue)>error);
}
else
{
printf("the calculation cannot be proceed due derivative zero");
getch();
exit();
}
printf("the required root is %f",newvalue);
getch();
}

No comments:

Post a Comment