You are on page 1of 1

1 #include <cmath>

2 #include <iomanip>
3 using namespace std;
4 double f(double x)
5 {
6 return sin(x) + asin(x) - 1;
7 }
8 double fd(double x, double h)
9 {
10 return (f(x + h) - f(x)) / h;
11 }
12
13 double BiseccionNewton(double numa, double numb, double tol, double h)
14 {
15 double numc = (numa + numb) / 2;
16 int k = 1;
17 string metodo = "Biseccion";
18 cout << setw(4) << "k" << setw(12) << "a" << setw(12) << "b" << setw(12) << "c"
<< setw(15) << "Metodo" << endl;
19 cout <<"*********************************************************"<<endl;
20 while (fabs(f(numc)) > tol) {
21 cout << setw(4) << k << setw(12) << numa << setw(12) << numb << setw(12) <<
numc << setw(15) << metodo << endl;
22 if (f(numa) * f(numc) < 0)
23 {
24 numb = numc;
25 }
26 else
27 {
28 numa = numc;
29 }
30 if(abs(fd(numc, h))<tol)
31 {
32 numc =(numa+numb)/2;
33 metodo = "Biseccion";
34 }
35 else
36 {
37 numc = numc - f(numc) / fd(numc, h);
38 metodo = "Newton";
39 }
40 k++;
41 }
42 cout << "La solucion es x = " << numc << endl;
43 return numc;
44 }
45 int main() {
46 double numa, numb, tol, h;
47 cout << "METODO HIBRIDO BISECCION NEWTON" << endl;
48 cout << "Ingrese el valor inicial del intervalo: ";
49 cin >> numa;
50 cout << "Ingrese el valor final del intervalo: ";
51 cin >> numb;
52 cout << "Ingrese la tolerancia: ";
53 cin >> tol;
54 h = 0.00001;
55 BiseccionNewton(numa, numb, tol, h);
56 return 0;
57 }

You might also like