Important alert: (current site time 5/24/2013 10:17:37 PM EDT) Brand new: recommended reading for every programming language on the site | revamped discussion board | 7 Source Code CDs

# root finder

Email
 Submitted on: 7/16/2012 11:21:42 AM By: Sophonias Berhanu Level: Advanced User Rating: Unrated Compatibility: Borland C++ Views: 1531

finds roots to an equation using methods of bisection, false position, secant, iteration and newton's method

code:
Can't Copy and Paste this?
 Terms of Agreement:    By using this code, you agree to the following terms...    You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.    You may link to this code from another website, but ONLY if it is not wrapped in a frame.  You will abide by any additional copyright restrictions which the author may have placed in the code or code's description. ``` //************************************** // Name: root finder // Description:finds roots to an equation using methods of bisection, false position, secant, iteration and newton's method // By: Sophonias Berhanu // //This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=13806&lngWId=3//for details.//************************************** #include #include #include #include long double funct(long double x) { long double y; y=(sin(x)-x+(0.5)); return y; } long double functI(long double x) //funct(x)=0 => x=sin(x)+0.5// {//fixed point iteration method// long double y; y=(sin(x)+(0.5)); return y; } long double functN_D(long double x) //derivative of funct(x)// { //newton-rapson method// long double y; y=(cos(x)-1); return y; } long double newton(long double x0,int m,long double e,long double sigma) { int i; long double x1; for (i=0;isigma) { x1=x0-((funct(x0))/(functN_D(x0))); cout<sigma)) break; } if ((fabs(funct(x0))sigma)) cout<<"\n\n\n"<sigma)) cout<<"\n\n\n"<sigma)) cout<<"\n\n\n"<fabs(funct(ans))) cout<<"\n\n\n"<fabs(c-a)) { cout<<"\n\n\n"<>x0>>m>>e>>sigma; cout<>x0>>m>>e; cout<>a>>b>>m>>e; cout<>a>>b>>m>>e; if (funct(a)*funct(b)<0) { cout<>a>>b>>e; if (funct(a)*funct(b)<0) { cout<>choice; switch (choice) { case 1: Bisection_entry(); Bisection(a,b,e); break; case 2: False_position_entry(); False_position(a,b,m,e); break; case 3: Secant_entry(); Secant(x0,x1,m,e); break; case 4: Iteration_entry(); Iteration(x0,m,e); break; case 5: newton_entry(); newton(x0,m,e,sigma); break; getch(); } }while (choice!=6); } ```

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)