Método de la bisección

eb8cxw
07 de Febrero del 2006
Hola a [email protected]:
Una pregunta en el metodo de la bisección para calcular la aproximación en, por ejemplo un polinomio de quinto grado cual seria los puntos: a y b.
Y como se imprementaria en C++ en el método f(a) y f(b) y el cambio de signo.
Espero haberme explicado, gracias de antemano.

Noel Solw
07 de Febrero del 2006
// program k2c6b.CPP - page 39
// numerical solution - bisection
// solve the equation : x^3 + 7xý + 6x - 14 = 0.
// 7/7/2001
// written in Borland CPP ver 3.1

#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <math.h>

const double aprox = 0.0001;
const char *sign[2] = {" - "," + "};
int a2 = 7, a1 = 6,a0 = -14;

double f(double x)
{
return ((x+a2)*x+a1)*x+a0;
} // F

int FindRootArea()
{
double previous = f(0);
for(int x = 1;; x++)
{
double now = f(x);
if(previous*now <= 0)
break;
previous = now;
}
return x;
} // FIND ROOT AREA

double Process(double a, double b)
{
double c = (a + b)/2;
cout << setw(15) << a << setw(15) << c << setw(15) << b
<< setw(15) << b-a << endl;
if(fabs(a-b)<aprox)
return c;
if(f(a)*f(c) <= 0)
return Process(a,c);
else
return Process(c,b);
} // PROCESS

void main()
{
clrscr();
cout.setf(ios::fixed);
cout << setprecision(5);
cout << "numerical solution - bisection " << endl << endl;
cout << "solve the equation : " << "x^3"
<< sign[a2 > 0] << abs(a2) << "xý"
<< sign[a1 > 0] << abs(a1) << "x"
<< sign[a0 > 0] << abs(a0) << " = 0 "
<< " aproximation = " << aprox << endl << endl;
double b = FindRootArea();
double a = b-1;
double x = Process(a,b);
cout << endl;
cout << "x = " << x << setw(15) << "f(" << x << ") = " << f(x) << endl;
cout << endl << endl;
getch();
} // MAIN

/*
numerical solution - bisection

solve the equation : x^3 + 7xý + 6x - 14 = 0 aproximation = 0.0001

0 0.5 1 1
0.5 0.75 1 0.5
0.75 0.875 1 0.25
0.875 0.9375 1 0.125
0.9375 0.96875 1 0.0625
0.96875 0.98437 1 0.03125
0.98437 0.99219 1 0.01563
0.99219 0.99609 1 0.00781
0.99609 0.99805 1 0.00391
0.99805 0.99902 1 0.00195
0.99902 0.99951 1 0.00098
0.99951 0.99976 1 0.00049
0.99976 0.99988 1 0.00024
0.99988 0.99994 1 0.00012
0.99994 0.99997 1 0.00006

x = 0.99997 f(0.99997) = -0.0007
*/