You are on page 1of 33

Chapter I

Introduction Background In the field of engineering electricity it is necessary to know the properties of the materials to be used for a certain project of development or for a study to be conducted. Failure to know the properties of the material to be made of, may lead to the disappointment of the project. Thus, resistivity is one of the physical properties of a material as of density, specific heat and many others. Resistivity is primarily defined as the strength or capacity of the material to oppose the flow of an electric current. Any object made of the same material has the common resistivity. When talking about resistivity it doesn't matter how big or what shape the sample is, it is the objects resistance which depends on its length, cross sectional area, etc. The relationship between the resistivity and resistance is shown by a formula,

(1)

where R is the resistance , r is the resistivity , L is the length of the material, and A is Module 3: Linear Algebraic Equations the cross sectional area. Thus, resistivity related to resistance may be obtained through mathematical process. Hence the SI unit for resistivity is ohm meter (.m). Another way of obtaining the resistivity ( ) of an object is based on its electron content. It is defined that the resistivity ( ) of a certain material is inversely

proportional to the electron charge (q), the electron density (n), and the electron mobility () measured in cm2.

(2)

Electron density is the measure of the probability of an electron being present at a specific location and the electron mobility is a quantity relating the drift velocity of electrons to the applied electric field across a material. Electron density (n) is given by the formula,
1 2

( +

2 + 4 2 )

(2)

where N is determined as the doping density and ni as the intrinsic carrier density measured in cm-3. And also the electron mobility ( temperature and reference temperature T and mobility ( ). And it is given by a formula,

) is described by the final

respectively, and a reference electron

= ( )2.42

(3)

Engineering Problem Posed Leavening is an important process in the preparation of baked products. One way of achieving this is through a chemical reaction between an acidic and an alkaline ingredient to produce carbon dioxide. This is often achieved through the use of a baking powder which is a complete mixture of at least one acid salt and an alkalilne. One such baking powder consists of monocalcium phosphate (CaH4(PO4)2) and bicarbornate of soda (NaHCO3). These react to produce tricalcium phosphate

Module 3: Linear Algebraic Equations

(Ca3(PO4)2), disodium phosphate (Na2HPO4), carbon dioxide (CO2) and water (H2O). This is represented by the chemical equation:
4( 4 )2

3(

4 )2

Find the smallest positive integer to balance the equation. Mathematical Analysis

Engineering Problem Expressed Mathematically


Determine the smallest positive integer to balance by equation 1.

Different mathematical methods should be used to obtain the value in the given problem. Thus, it needs to transform and express functions or working equations to the form the problem requires. The given qualitative equation above does not tell us how much of each reactant is needed and the relative amounts of the product are realized . Thus, in this problem, it is assumed that mixing x1 moles of monocalcium phosphate and x2 moles of bicarbonate of soda produce x3 moles tricalcium phosphate, x4 moles of disodium

phosphate, x5 moles of carbon dioxide and x6 moles of water. This is represented by the equation:
1 4( 4 )2

3(

4 )2

6 2

Balancing this chemical reaction means finding values of x1, x2, x3, x4, x5 and x6 so that the number of atoms of each element is the same on both sides of the equation. For balancing the number of Ca (calcium) atoms: =

Module 3: Linear Algebraic Equations

For balancing the number of H (hydrogen) atoms: 4 + = +

For balancing the number of P (phosphate) atoms: = +

For balancing the number of O (oxygen) atoms: + = +4 + +

For balancing the Na (sodium) atoms: + = +4 + +

For balancing the number of C (carbon) atoms: =

This is a homogenous system and has the following matrix:


1

4 4 [

2 3 4

= [ ]

] [ 6]

Module 3: Linear Algebraic Equations

Chapter II
Methods in Obtaining Roots of the Equation Referring to Appendix A are the figures of the flowchart of the programs being constructed for each methods of obtaining root of an equation, it follows a subroutine procedure. The program contains a main class obtaining the necessary methods calling for inputs, and subclasses (Bisection, FalsePosition, FixedPoint Iteration, NewtonRaphson, Secant, Brent) which leads to the computation of the root using any method. Bracketing Method It comprises different methods which the roots may be found within the two initial guesses which are typically changes the signs. The methods present here give strategies which reduces the width of the bracket until the root will be found. Bisection Method It is called the binary chopping or the Bolzanos method. A Bracketing method which finds root of a given continuous function over an interval f( ) and f( ) will have an opposite signs that gives f( ) f( =( + and such that Module 3: Linear Algebraic Equations

) < 0. The method divides

the interval in two by computing the midpoint and f( ) or f( ) and f(

)/2 of the interval. Either f( )

) will have opposite signs and it brackets a root, we must

select a subinterval within the interval and apply the same bisection step. There will be a 50% of chance of getting a function equals to zero. If f( ) f( method sets equal to , and if f( ) < 0, then the equal to .

) f( ) < 0, then the method sets

For both cases, the new f( ) and f( applicable to this smaller interval.

) will have opposite signs, so that the method is

The continuous function on the given interval [ ,

] and f( ) f(

) < 0 states

that the bisection converges to a root of the function and the true error is halved in each step and the method converges linearly if f( ) and f( ) will have different signs.

This method gives only a range where the root exists and not the estimation where is the roots location. The smallest bracket is where the root can be found. Its true error of n steps can be solved by the equation;

+ 2

(2.1)

False Position Method/Regula Falsi Method It is also called the linear interpolation method. An alternative method based on the graphical method. The false position method starts with a two points such that the functions f( ) and f(( and

) will have an opposite signs then one of the end-

points will converges and the other will remain fixed for all the iterations function f a root. It is given by the formula, Module 3: Linear Algebraic Equations

( )( ) ( )( )

(2.2)

The root f((

is from the graphical representation of joining the function f( ) and

) by a straight line and which the point that intersects the line and the axis is the

improve root. The value of the root replaces f( ) and f(( so that the root is always at the interval of the two point

) with the same sign as f( and .

The termination of the computation will be the same as the bisection method and same as the algorithm, but the equation for finding is used. The error of the

regula falsi is more efficient for root finding than the bisection since one of the points will stay throughout the computation and the others converges quickly and makes the approximate error conservative. Modified False Position Method It is the remedy of being one-sided of the false position method. It divides the function value that was stuck. The algorithm implements the strategies on how the counters are used to determine the root when the one is bound stays fixed for the two iterations and through this, the function value is bound halved. It is more than the bisection and the false position method for setting the stopping criterion as 1.01% since it gives only 12 iterations compare with the 14 and 25 of the bisection and false position method. Open Method It composed of different methods that are based on the formulas that requires only a single starting value of x or two starting values that do not necessarily bracket the root. It may diverge or converges as the computation progresses. Module 3: Linear Algebraic Equations

Simple Fixed Point Method It is also called the One-point iteration or the successive substitution method. It rearranges the function f(x)=0 to x=g(x) It can be obtained by adding both sides a x of the equation or by simply doing algebraic manipulation. The guess roots used to estimate as
+1

can be

and can be expressed as

+1 =g(x).

The convergence or the divergence of this method can be depicted graphically through its behavior and structure or it can also be predicted by separating the it into two components parts and the x values obtained by the intersections are the roots of the function f(x)=0. The two-curve method also shows the convergence and the divergence of the simple fixed-point method. To find for the approximate error of this method can be solve using this formula,

+1 +1

(2.3)

Newton Raphson Method The widely used for finding the root for approximations to the zeroes of a real valued function. It converges quickly for the iterations which are near on the desired Module 3: Linear Algebraic Equations root. It also detects and overcomes the convergences failure. This method starts with an initial guess which is close to the true root, the given function is approximated by its tangent line then computes the x-intercept of this tangent line. This x-intercept will be the approximation to the function's root than the original guess, and the method can be repeated. The formula for this method is given by

+1 = + ( )

( )

(2.4)

The termination of the Newton- Raphson method is the same as for computing the other methods. The convergence depends on the accuracy of the initial guess root and the nature of the problem. Secant Method It is an open method which assumes a function that can be approximately linear in the region of interest. The formula for the needs two initial estimates of x but the f(x) is not required to change the signs between the two estimates and is given by this equation,

+1 = 1

( )(1 ) (1 )( )

(2.5)

The two values can sometimes lie on the same root and sometimes this can cause the divergence. The convergence of this method is that the root is within the bracketing which is the reason that it was compared with the false position method. Modified Secant Position Method This method uses an alternative approach which involves the fractional perturbation of the independent variable to estimate the f(x) instead of using the two arbitrary values. The formula for the iteration is given by +1 =
( ) ( + )( )

(2.6)

Module 3: Linear Algebraic Equations

Bairstows Method It is a method that finds complex roots of a polynomial of a quadratic formula and can be used for solving the root all kinds of a polynomial. It uses the Newtons method to adjust the coefficients u and v in the quadratic x2 + ux + v until its roots are also roots of the polynomial being solved. The root can be found be found by dividing

the polynomial by the quadratic to eliminate the roots and then it can be repeated until the polynomial becomes quadratic or linear and all roots will be determined. The values of u and v can be found by picking the starting and repeating the Newtons method in two dimensions until it converges, for the quadratic equations of multiplicity higher than one it converges to that factor is a linear and quadratic factors that have a small value which has real roots will tend to diverge to infinity. To find for the zero of polynomial can be implemented with a programming language. Mller's method A root finding method that solves for the root of the form f(x) = 0 of the single variable x and a scalar function whenever theres no information about the derivatives that exists. Its the generalizes the secant method but it uses three points of quadratic interpolation noted by as xk, xk-1 and xk-2.The The parabola going through the three Module 3: Linear Algebraic Equations points (xk, f(xk)), (xk-1, f(xk-1)) and (xk-2, f(xk-2)) when

It can be written in the Newton form, where f[xk, xk-1] and f[xk, xk-1, xk-2] denote divided differences ;

10

where;

Brents Method It is a method that combines that bisection method, the secant method. The idea is to use the secant method because they converge faster, but to fall back to the more robust bisection method if necessary. Given a specific numerical tolerane , | | < | bk bk 1 |must hold and the results is used in the iteration and if previous step is perform interpolation then the inequality gives | | < | bk 1 bk 2 |. Also, if the previous step used the bisection method, the inequality must hold, otherwise the bisection

method is performed and the result used for the next iteration. If the previous step performed interpolation, then the inequality is used Module 3: Linear Algebraic Equations

instead. Most of the N2 iterations, where N denotes the number of iterations for the bisection method, if the function f is well-behaved, and this method will usually proceed by either inverse quadratic or linear interpolation, in which case it will converge linearly.

11

Chapter III
Source Code The following are the listing for the source code of the different methods of obtaining the root of the function. Listing 1. Class Main

/* Main Class - contains the main method which executes the Java application - calls the needed methods*/ //import Java extension packages import javax.swing.JOptionPane; public class Main {
//Main method begins execution of Java application public static void main(String[] args) { int j=0,B=0,I=0; MRZ a = new MRZ(); ModBisection b = new ModBisection(); ModFalsePosition c = new ModFalsePosition(); FixedPointIteration d = new FixedPointIteration(); NewtonsRaphson e = new NewtonsRaphson(); ModSecant f = new ModSecant(); Brent g = new Brent(); Object [] T = {"Repeat","End"}; Object [] J = {"Yes", "No"}; Object [] Menu={"Bisection","False Position","Fixed- Point Iteration","Newton's Raphson","Secant Method","Brent's Method"}; a.input();//obtain the values needed in the problem for (int t = 0; t>=0;t++){ j=JOptionPane.showOptionDialog(null,"Select Method",null, JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE,null ,Menu,Menu[0]); a.Mrz.setText("");//Clear Text Area a.run(j);//execute // determine the method to use based on user's choice switch(j){ case 0:{ b.Bisection(); Module 3: Linear Algebraic Equations

12

break;// done processing case } case 1:{ c.FalsePosition(); break;// done processing case } case 2:{ d.FixedPointIteration(); break;// done processing case } case 3:{ e.NewtonsRaphson(); break;// done processing case } case 4:{ f.Secant(); break;// done processing case } case 5:{ g.Brent(); break;// done processing case } }// end switch structure a.Final();//Inputs the root to the String wee a.Output();//Display the results B = JOptionPane.showOptionDialog(null,"Select",null, JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE ,null,T,T[0]);//Prompts user to repeat the application if (B==1)break ; I = JOptionPane.showOptionDialog(null,"Input new values?","Select", JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE, null,J,J[0]);//Prompts user to input new values if (I==0)a.input();

}//end for structure }//End method main }//End class Main

Listing 1 contains the source code of the Main class, the class which contains the main method, a method that executes the application.

13

Module 3: Linear Algebraic Equations

Listing 2. Class MRZ

/*MRZ class - declares method of the function - declares methods to prompt user to input values needed in the methods - declares the method in giving the output*/ //Declaring methods //import Java extension packages import javax.swing.*; //import Java core packages import java.text.DecimalFormat; public class MRZ { //Create JTextArea to display output JTextArea Mrz = new JTextArea (25,75); //Puts a scrollbar in the JTextArea JScrollPane mRz = new JScrollPane(Mrz); DecimalFormat df = new DecimalFormat("0.00000000"); public static MRZ mrz = new MRZ(); public static int imax; public static double Nl,Nu,ea,es,fl,fu,fr,Nr=0,N0,Nrold,q,uo,T, To,p,ni,u,j,sigma,eps; public static String wee; // initialize application by obtaining values public void input(){ String a,b,c,d,e,f; //Prompts user to input needed values a = JOptionPane.showInputDialog("Enter the charge q(C):"); b = JOptionPane.showInputDialog("Enter the electron" +" mobility \u00b5o(cm\u00b2(Vs)\u02c9\u00b9):"); c = JOptionPane.showInputDialog("Enter the T(K):"); d = JOptionPane.showInputDialog("Enter the temperature" +" To(K):"); e = JOptionPane.showInputDialog("Enter the " +"resistivity \u03c1 Vs(cm/C):"); f = JOptionPane.showInputDialog("Enter the carrier " +"density ni(cm\u02c9\u00b3):"); //Converting String to Double q = Double.parseDouble(a); uo = Double.parseDouble(b); T = Double.parseDouble(c); To = Double.parseDouble(d); p = Double.parseDouble(e); ni = Double.parseDouble(f); u=uo*Math.pow(T/To,-2.42);j=q*p*u; electron reference temperature reference

doped silicon
intrinsic

14

Module 3: Linear Algebraic Equations

}//end method input //Function of the given problem public double func(double N){ return ((Math.pow(j, -1)))-(N/2)(Math.sqrt(Math.pow(N,2)+ 4*Math.pow(ni,2)))/2;//returns the function } //g(x) of the function of the given problem public double gfunc(double N){ return (Math.pow(j,-1))-(N/2)(Math.sqrt(Math.pow(N,2)+4*Math.pow(ni,2)))/2+N; } //Derivative of the function of the given problem public double dfunc(double N){ return -(0.5)-((N*(1/(Math.sqrt(Math.pow(N,2)+ 4*Math.pow(ni,2)))))/2);//return the derivative of the function } //Calculates the Approximation Error public double ea(){ return Math.abs((Nr-Nrold)/Nr)*100;//returns the Approximate error } //Display the root public void Final (){ wee += "\n\n--------\n\nThe root is: "+Nr+"\nf("+Nr+") = " +mrz.func(Nr)+"\n\n--------\n"; } public void Output(){ // append String to Mrz Mrz.append(wee); //Display output JOptionPane.showMessageDialog(null,mRz); }//end method Output //Obtains the values needed by the selected method public void run(int s){ //prompts user to input the maximum number of iterations String IMAX = JOptionPane.showInputDialog(null,"Enter the maximum" +" number of iterations: "); imax=Integer.parseInt(IMAX); String NL,NU,NO,SIGMA,EPS,ES; int b=0; if (s==0||s==1||s==5) { while(b==0){ NL=JOptionPane.showInputDialog("Input lower limit:");

15

Module 3: Linear Algebraic Equations

NU=JOptionPane.showInputDialog("Input upper limit: "); Nl=Double.parseDouble(NL); Nu=Double.parseDouble(NU); //check if the given interval contains one root if (mrz.func(Nl)*mrz.func(Nu)>0) { b=0; JOptionPane.showMessageDialog(null,"The root is not " +"located in the given interval or there are more " +"than one root","Notification",JOptionPane.WARNING_MESSAGE); } else b=1; }//end while structure } // determine the method to use based on user's choice switch(s){ case 2://Fixed-Point Iteration Method { NO=JOptionPane.showInputDialog("Enter initial guess: "); N0=Double.parseDouble(NO); break;// done processing case } case 3://Newton's Raphson Method { while(b==0){ NO=JOptionPane.showInputDialog("Enter initial guess: "); N0=Double.parseDouble(NO); if (mrz.dfunc(N0)==0 || N0==0) { b=0;

JOptionPane.showMessageDialog(null,"INVALID! Enter another" +" value for x.","Notice",JOptionPane.WARNING_MESSAGE); } else b=1; }//end while structure break;// done processing case
} case 4://Secant Method { while(b==0){

16

Module 3: Linear Algebraic Equations

NO=JOptionPane.showInputDialog("Enter initial estimate of x: "); N0=Double.parseDouble(NO); if (N0==0) { b=0; JOptionPane.showMessageDialog(null,"INVALID! Enter another" +" value for x(non-zero).","Notice", JOptionPane.WARNING_MESSAGE); }else b=1; }//end while structure SIGMA=JOptionPane.showInputDialog("Input pertubation fraction: "); sigma=Double.parseDouble(SIGMA); break;// done processing case } case 5://Brent's Method { EPS=JOptionPane.showInputDialog(null,"Enter the specific " +"numerical tolerance: ");eps=Double.parseDouble(EPS); break;// done processing case } default: break;// done processing case } ES=JOptionPane.showInputDialog(null,"Enter the stopping criterion(%)?"); es=Double.parseDouble(ES); }//end method run }//end class MRZ

Listing 2 contains the source code of the MRZ class. This class is the Mother class with six subclasses ModBisection, ModFalsePosition, FixedPointIteration, NewtonRaphson, ModSecant and Brent. This class contains the conditions of obtaining correct initial inputs for each of the subclasses.

17

Module 3: Linear Algebraic Equations

Listing 3. Listing for Bisection Method

/*ModBisection Class - class containing the method of the "Modified Bisection method".*/ public class ModBisection extends MRZ{ public void Bisection(){ //initialize String wee=" Bisection\n----------\nNo of iter.\tXl\t\tXu\t\tXr\t\tEa\n"; fl = mrz.func(Nl); for(int iter = 0; iter<imax;iter++){ Nrold=Nr; Nr=(Nl+Nu)/2; fr = mrz.func(Nr); if(Nr != 0) ea = mrz.ea(); else ea=es; if (fl*fr<0){ Nu = Nr; } else { if(fl*fr > 0){ Nl=Nr; fl=fr; } else ea=0; } if(iter == 0) wee+=(iter+1)+"\t"+df.format(Nl)+"\t"+df.format(Nu)+"\t"+ df.format(Nr)+"\t-----\n"; else wee+=(iter+1)+"\t"+df.format(Nl)+"\t"+df.format(Nu)+"\t"+ df.format(Nr)+"\t"+df.format(ea)+"\n"; if (ea<es) break; }//end for structure }// end method ModBisection }// end class ModBisection

Next is Listing 3 is the source code for the class ModBisection. This class only consists of the process of the method. The inputs are located in the mother class MRZ.

18

Module 3: Linear Algebraic Equations

Listing 4. Listing for False Position package casestudy; /*ModFalsePosition Class - class containing the method of the "False Position method".*/ public class ModFalsePosition extends MRZ { public void FalsePosition(){ double il=0,iu=0; //initialize String wee="False Position\n----------\nNo of iter.\tXl\t\tXu\t\tXr\t\tEa\n"; fl = mrz.func(Nl); fu = mrz.func(Nu); for(int iter=0; iter<imax;iter++){ Nrold=Nr; Nr=Nu-fu*(Nl-Nu)/(fl-fu); fr=mrz.func(Nr); if (Nr!=0)ea=mrz.ea(); else ea=es; if ((fl*fr)<0){ Nu=Nr;fu=mrz.func(Nu); iu=0; il += 1; if(il>=2){ fl /= 2; } } else{ if(fl*fr>0){ Nl=Nr; fl = mrz.func(Nl); il=0;iu+=1; if(iu>=2){ fu/=2; } } else ea=0; } if(iter == 0) wee+=(iter+1)+"\t"+df.format(Nl)+"\t"+df.format(Nu)+ "\t"+ df.format(Nr)+"\t-----\n"; else wee+=(iter+1)+"\t"+df.format(Nl)+"\t"+df.format(Nu)+ "\t"+ df.format(Nr)+"\t"+df.format(ea)+"\n"; if (ea<es)break;//ends for structure for ea<es

19

Module 3: Linear Algebraic Equations

Listing 4 contains the source code of the class ModFalsePosition. This class contains only the methods process, input proper appears in the Mother class MRZ Listing 5. Listing for Fixed Point Iteration

/*FixedPointIteration Class - class containing the method of the "Fixed-Point Iteration method".*/ public class FixedPointIteration extends MRZ { public void FixedPointIteration(){ //initialize string wee = "Fixed-Point Iteration\n----------\nNo of iter.\tXo\t\tXr\t\tEa\n"; Nr=N0; for( int iter = 0; iter<imax;iter++){ Nrold=Nr; Nr = mrz.gfunc(Nrold); if(Nr!=0) ea=mrz.ea(); else ea=es; if(iter==0) wee+=(iter+1)+"\t"+df.format(N0)+"\t"+df.format(Nr)+ "\t-----\n"; else wee += (iter+1)+"\t"+df.format(N0)+"\t"+df.format(Nr)+ "\t"+df.format(ea)+"\n"; if(ea<es) break; }//end for structure }//end method FixedPointIteration }//end class FixedPointIteration Module 3: Linear Algebraic Equations

Listing 5 shows the source code of the class FixedPointIteration. Just like the previous listings, this class contains only the process of the method, the inputs are located in the Mother class MRZ.

20

Listing 6. Listing for Newton-Raphson

/*NewtonsRaphson Class - class containing the method of the "Newton's Raphson method".*/ public class NewtonsRaphson extends MRZ{ public void NewtonsRaphson(){ //initialize String wee = "Newton's Raphson Method\n----------\nNo of iter.\tXo\t\tXr\t\tEa\n"; Nr=N0; for( int iter = 0; iter<imax;iter++){ Nrold=Nr; Nr = Nrold-(mrz.func(Nrold))/(mrz.dfunc(Nrold)); if(Nr!=0) ea=mrz.ea(); else ea=es; if (iter==0) wee += (iter+1)+"\t"+df.format(Nrold)+"\t"+ df.format(Nr)+"\t-----\n"; else wee += (iter+1)+"\t"+df.format(Nrold)+"\t"+ df.format(Nr)+"\t"+df.format(ea)+"\n"; if(ea<es) break; }//end for structure }//end method NewtonsRaphson }//end class NewtonsRaphson

Listing 6 contains the source code of the Newton-Raphson method. This contains the process of the said method. The inputs are located in the Mother class MRZ. Module 3: Linear Algebraic Equations

21

Listing 7. Listing for Secant Method /*ModSecant Class - class containing the method of the "Modified Secant method".*/ public class ModSecant extends MRZ { public void Secant(){ //initialize String wee ="Secant Method\n----------\nNo of iter.\tXo\t\tXr\t\tEa\t\n"; double fa,fb; Nr=N0; for( int iter = 0; iter<imax;iter++){ Nrold=Nr; fa = mrz.func(Nrold); fb = mrz.func(Nrold+(sigma*Nrold)); Nr = Nrold -(sigma*Nrold*fa)/(fb-fa); if(Nr!=0)ea=mrz.ea(); else ea=es; if(iter==0) wee += (iter+1)+"\t"+df.format(Nrold)+"\t"+ df.format(Nr)+"\t-----\n"; else wee += (iter+1)+"\t"+df.format(Nrold)+"\t"+ df.format(Nr)+"\t"+df.format(ea)+"\n"; if(ea<es) break; }//end for structure }//end method ModSecant }//end method ModSecant

Listing 7 contains the source code of the class ModSecant. Just like the previous subclasses, this only contains the process proper of the method. The inputs are located in the Mother class MRZ. The next is Listing 8, which contains the source code of the class Brent, like previous subclasses, this contains the process of the method. The input proper is located in the Mother class MRZ. Module 3: Linear Algebraic Equations

22

Listing 8. Brents Method

/*Brent Class - class containing the method of the "Brent's method".*/ public class Brent extends MRZ { public void Brent (){ //Initialize String wee = "Brent's Method\n----------\nNo of iter.\tXr\t\tEa\n"; double fc,c, c0, c1, c2,temp, mtflag, d; int mflag,iter = 1; c = Nl; d = c; fl = mrz.func(Nl);//fa=fl fu = mrz.func(Nu);//fb=fu fc = mrz.func(c); if ( Math.abs(fl) < Math.abs(fu)) { temp = Nl; Nl = Nu; Nu = temp; temp = fl; fl = fu; fu = temp; } mflag = 1; while ( (Math.abs(fu) > eps) && ( Math.abs(Nu-Nl) > eps)) { Nrold = Nr; if ( (fl != fc) && fu != fc) { c0 = Nl*fu*fc/((fl-fu)*(fl-fc)); c1 = Nu*fl*fc/((fu-fl)*(fu-fc)); c2 = c*fl*fu/((fc-fl)*(fc-fu)); Module 3: Linear Algebraic Equations Nr = c0 + c1 + c2; } else Nr = Nu - fu*(Nu-Nl)/(fu - fl); if ( ( Nr < (3*(Nl+Nu)/4) || Nr > Nu) || ( (mflag == 1) && Math.abs(Nr-Nu) >= (Math.abs(Nu-c)/2) ) || ( (mflag == 0) && Math.abs(Nr-Nu) >= (Math.abs(c-d)/2) ) ) { Nr = (Nl+Nu)/2; mflag = 1; }

23

else mflag = 0; fr = mrz.func(Nr); d = c; c = Nu; fc = fu; if(Nr !=0)ea=mrz.ea(); else ea=es; if ( (fl*fr)< 0) Nu = Nr; else Nl = Nr; if ( Math.abs(fl) < Math.abs(fu)) { temp = Nl; Nl = Nu; Nu = temp; temp = fl; fl = fu; Chapter IV fu = temp; } if (iter==1) Result wee += iter+"\t"+df.format(Nr)+"\t-----\n"; else wee += iter+"\t"+df.format(Nr)+"\t"+ea+"\n"; A. Graphical Result if (ea<es) break; iter++; }//end while structure }//end method Brent }//end class Brent

24

Module 3: Linear Algebraic Equations

Chapter IV
Results and Discussion A. Graphical Representation

Figure 1. Graphical Representation for over no. of Iterations Figure 1 shows the graphical representation between the approximate errors( ) and the number of iterations. The results were obtained through the use of the different methods stated.

25

Module 3: Linear Algebraic Equations

B. Screenshot of outputs The following figures are the actual results or screenshots obtained using the source codes accessible on Chapter 3.

Figure 2. Screenshot of the Result for Bisection Method

Figure 3. Screenshot of the Result for False Position Method

26

Module 3: Linear Algebraic Equations

Figure 4. Screenshot of the Result for Fixed Point Iteration

Figure 5. Screenshot of the Result for Newton-Raphson Method

27

Module 3: Linear Algebraic Equations

Figure 6. Screenshot of the Result for Secant Method

Figure 7. Screenshot of the result for Brents Method

28

Module 3: Linear Algebraic Equations

C. Table of Results The following are the tabular presentation of the results obtained after employing the different methods for solving the function eq. 5.

Table 1. Results for Bisection Method Iterations 1 2 3 4 5 6 7 8 9 10 11 Nr 15000000000 12500000000 11250000000 11875000000 11562500000 11718750000 11796875000 11757812500 11738281250 11748046875 11752929688 a ----20 11.1111111 5.26315789 2.7027027 1.33333333 0.66225166 0.33222591 0.16638935 0.08312552 0.04154549

Table 1 shows the obtained results for solving the roots of eqn. 5 using the Bisection Method. As shown, the root was obtained after 11 iterations and is equal to Nr = 11752929688, where the condition a < s was satisfied after 11 iterations such that a = 0.0415454, which is less than the inputted stopping s =0.05. The limits used in solving the problem are 1x1010 and 2x1010, the lower and upper limits respectively. Module 3: Linear Algebraic Equations

Table 2. Results for False Position Method Iterations 1 2 3 4 Nr 11655417267 11751253575 11761402241 11756613357 a ----0.81554115 0.08628788 0.04073353

29

Table 2 shows the obtained results for solving the roots of the function eqn. 5 using the False Position Method. As seen above, the root was obtained after 4

iterations, which was evaluated from the lower and upper limits, 1x1010 and 2x1010 respectively, where the value of the approximation error is a = 0.04073353, which satisfies the condition a < s, where s = 0.05.

Table 3. Results for Fixed-Point Iteration Method Iterations 1 2 3 4 5 Nr 11456538023 11709015931 11749157662 11755447971 11756431421 a ----2.15626923 0.34165624 0.05350973 0.00836521

Table 3 shows the obtained results for solving the roots of the function in eqn. 5 using the Fixed-Point Iteration Method. From the table, a root of Nr = 11756431421 is obtained after 5 iterations, where the condition a < s is satisfied, where a = 0.00836521 and s = 0.05. The initial guess used is 1x1010.

Table 4. Results for Newton-Raphson Method Module 3: Linear Algebraic Equations Iterations 1 2 3 Nr 11790305201 11756623930 11756613591 a ----0.28648762 0.00008794

Table 4 shows the obtained results for solving the function in eqn.5 using the Newton-Raphson Method. From the table, a root of Nr = 11756613591 is obtained

30

after 3 iterations with a relative approximate error of a = 0.00008794, which satisfies the condition a < s, where s = 0.05. The initial guess used is 1x1010.

Table 5. Results for Secant Method Iterations 1 2 3 Nr 11780101085 11756741026 11756614257 a ----0.19869502 0.00107828

Table 5 shows the results after computing for the root of the function in eqn. 5 using Modified Secant Method where the root was found out to be equal to Nr=11756614257. This root was obtained in the 3rd iteration where the relative approximate error is equal a=0.00107828 which is less than the required stopping condition s=0.5. The perturbation factor used is 0.05, and the initial estimate used is 1x1010.

Table 6. Results for Brents Method Iterations 1 2 3 4 5 6 7 8 9 10 Nr 15000000000 12500000000 11250000000 11875000000 11562500000 11718750000 11796875000 11757812500 11738281250 11748046875 a ----20 11.11111111 5.263157895 2.702702703 1.333333333 0.662251656 0.332225914 0.166389351 0.08312552

31

Module 3: Linear Algebraic Equations

The table above shows the results obtained after computing for the root of the function in eqn. 5 by employing Brents Method. As shown above, the root, Nr = 11748046875, was obtained in the 10th iteration where the computed approximate error Es=0.08312552 satisfies the terminating condition a<s where s = 0.05. In evaluating the root of the function using the formula for Brents Method, the lower and upper limit used were 1x1010 and 2x1010 respectively, and the numerical tolerance was chosen to be equal to 0.000001.

32

Module 3: Linear Algebraic Equations

Chapter V
Conclusion

The Newton-Raphson Method gives the least approximate true error over other methods in finding the root of equation (5). Equation (5) is much more approximately equal to zero when the root obtained using the Fixed Point Iteration method is substituted. In addition, these methods give a lesser relative approximation error, though a and t for this technique has a considerable difference compared to the other methods. With our given function, the Newton Raphson is the most efficient technique in finding the root of the function in equation (5). This is true since only a single value is used to predict succeeding values for the root estimate since it uses the least number of iterations to obtain the root. A better accuracy is also attained with this method since, it ensures a better convergence other than the methods, and since equation (5) is a linear function the Muller and Bairstows Method cannot be applied because primarily these methods can only be applied for polynomial functions.

33

Module 3: Linear Algebraic Equations

You might also like