Important alert: (current site time 6/2/2015 4:59:25 AM EDT)
  • My apologies, but the planet source code database and zip file downloads are not working reliably.The problem is with some hardware in the storage unit that hosts the planet source code servers in a virtual machine environment. A technician is working on the problem, but parts are slow to arrive. Thanks for your patience while we get this resolved. - Ian Ippolito: Creator of Planet Source Code

VB icon

Bisection Method(Interval Halving)

Submitted on: 8/24/2011 11:35:13 AM
By: Akash Khaitan 
Level: Advanced
User Rating: Unrated
Compatibility: C
Views: 4686
author picture
(About the author)
     Takes a function, range and tolerance as input and outputs the bisection table. To compile use gcc -o filename filename.c -lmuparser

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. 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.
  2. 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.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
// Name: Bisection Method(Interval Halving)
// Description:Takes a function, range and tolerance as input and outputs the bisection table. To compile use gcc -o filename filename.c -lmuparser
// By: Akash Khaitan
//This code is copyrighted and has// limited warranties.Please see details.//**************************************

//Bisection Method
#include <muParserDLL.h>
#define PARSER_CONST_PI 3.141592653589793238462643
#define PARSER_CONST_E2.718281828459045235360287
#define PARSER_MAXVARS		10
int main()
	muFloat_t calc(muChar_t [],float);
 	muChar_t szLine[100];
	int tol=0,i=0;
 	float val3=0,val1=0,val2=0;
	muFloat_t fVal=1;
	printf("Enter the function : ");
	printf("Enter range of x : ");
	scanf("%f %f",&val1,&val2);
	printf("Enter the value of tolerane : ");
	printf("Iteration	X1		X2		X3		f(X3)\n");
		fVal = calc(szLine,val3);
 		printf("%d		%f	%f	%f	%f\n", i+1,val1,val2,val3,calc(szLine,val3));
	return 0;
muFloat_t calc(muChar_t szLine[],float val3)
	muFloat_t fVal=0,val=val3;
	muParserHandle_t hParser;
	hParser = mupCreate();
	mupDefineConst(hParser, "pi", PARSER_CONST_PI);
	mupDefineConst(hParser, "e", PARSER_CONST_E);
	mupDefineVar(hParser, "x", &val);
	mupSetExpr(hParser, szLine);
	fVal = mupEval(hParser);
	return fVal;

Other 19 submission(s) by this author


Report Bad Submission
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:

Your Vote

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 ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.