# Bisection and False Position Methods

Page 1 of 1

## 2 Replies - 8534 Views - Last Post: 15 September 2009 - 10:26 PMRate Topic: 1 Votes //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=126100&amp;s=553dfec7829287627f53e71656d92b46&md5check=' + ipb.vars['secure_hash'], cur_rating: 5, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Sandthief

Reputation: 1
• Posts: 18
• Joined: 07-June 09

# Bisection and False Position Methods

Posted 15 September 2009 - 09:07 PM

Well, first of all, I'll place the code, Bisec is Bisection Method and FalPos is False Position, both are made to find approximate roots of a given math function.

```#include <stdlib.h>
#include <stdio.h>
#include <math.h>

double Raices(double xi, double xd, double errtolerado, int maxiter, int *ban, double (*metodo)(double xder, double xizq, double (*func)(double y)), double (*f)(double a, double (*curva)(double x)))
{
double xa, xv, erraprox;
if(f(xi,sin)*f(xd,sin)>=0)
{
*ban=0;
return 0;
}

for(int n=1; n<=maxiter; n++)
{
xa=metodo(xi, xd, f);
if(f(xi,sin)*f(xa,sin)<0)
xd=xa;
else
{
if(f(xi,sin)*f(xa,sin)>0)
xi=xa;
else
{
*ban=2;
return xa;
}
}
if(n>1)
erraprox=fabs((xa-xv)/(xa));
xv=xa;
{
*ban=2;
return xa;
}
}
*ban=1;
return xa;
}

double Bisec(double xi, double xd, double (*f)(double x))
{
double xa;
xa=(xi+xd)/2;
return xa;
}

double FalPos(double xi, double xd, double (*f)(double x))
{
double xa;
xa= xd-((f(xd)*(xi-xd))/(f(xi)-f(xd)));
return xa;
}

double MiFunc(double a, double (*f)(double x))
{
double y;
y=a*f(a);
return y;
}

int main()
{
double xi, xd, errtol, xap;
int maxiter, ban, op;
system("cls");
printf("Este programa buscara las raices de x*sen(x), introduzca el intervalo\n en la forma de xi,xd: ");
scanf("%f,%f", &xi, &xd);
printf("\n\nIntroduzca el error maximo tolerado, valores del 0 al 100: ");
scanf("%f", &errtol);
printf("\n\nIntroduzca el numero maximo de iteraciones: ");
scanf("%i", &maxiter);
printf("\n\nElija el método, 1 para Bissecion, 2 para Falsa Posicion, otro numero acabara el programa: ");
scanf("%i", op);
switch(op)
{
case 1:
xap=Raices(xi,xd,errtol,maxiter,&ban,Bisec,MiFunc);
break;
case 2:
xap=Raices(xi, xd, errtol, maxiter, &ban, FalPos, MiFunc);
break;
default:
printf("\n\nFin de Programa\n\n");
system("pause");
break;
}
switch(ban)
{
case 0:
printf("\n\nNo Existe la raiz en el intervalo\n\n");
system("pause");
break;
case 1:
printf("\n\nLa raiz existe, pero el error no es aceptable, pruebe otro metodo:\nRaiz: %f\n\n", xap);
system("pause");
break;
case 2:
printf("\n\nLa raiz aproximada es: %f", xap);
system("pause");
break;
}
}

```

The issue is when I try to call the functions from main, I can't find how to make the compiler happy. Any help is welcome.

Is This A Good Question/Topic? 1

## Replies To: Bisection and False Position Methods

### #2 poncho4all

Reputation: 123
• Posts: 1,413
• Joined: 15-July 09

## Re: Bisection and False Position Methods

Posted 15 September 2009 - 09:15 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:

* Post the code you're having problems with
* Post the exact error you're receiving, if you are receiving one
* If no error explain what the code is doing versus what you want it to do
* Post your question in the body of your post, not the description field
* Post your code like this: [code]code goes here [/code]

### #3 Sandthief

Reputation: 1
• Posts: 18
• Joined: 07-June 09

## Re: Bisection and False Position Methods

Posted 15 September 2009 - 10:26 PM

For now, it's on line 17, the error says: invalid conversion from `double (*)(double, double (*)(double))' to `double (*)(double)' . Why does this happen? The program doesn't compile and I wrote it on Dev-C++.