Necesito ayuda con los programas en C para: Metodo de Biseccion, newton Raphson y Secante

nikkie
14 de Marzo del 2004
Si tienen estos programas POR FAVOR envienmelos al correo [email protected]. Se los agradecere MUCHISISIMO.

noel solw
14 de Marzo del 2004
te emvio un programa que implementa el metodo de biseccion, espero que te ayude en algo

// program k2c6b.CPP - page 39
// numerical solution - bisection
// solve the equation : x^3 + 7xý + 6x - 14 = 0.
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// - 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
*/

noel solw
14 de Marzo del 2004
// program k2c7.CPP - page 39
// numerical solution - Newton's method
// equation : x - cos(x) = 0
// c++ exercices book - dr. gershon kagan (first edition : 2001)

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

const double aprox = 0.001;

void main()
{
cout.setf(ios::fixed);
cout << setprecision(4);
cout << "numerical solution - Newton's method " << endl << endl;
cout << "equation : x - cos(x) = 0 aproximation = "
<< aprox << endl << endl;
double x = 2, xo;
while(fabs(x-xo) > aprox)
{
xo = x;
x = xo - (xo - cos(xo))/(1 + sin(xo));
cout << setw(15) << x << setw(15) << xo << setw(15)
<< fabs(x-xo) << endl;
}
cout << endl << "cos(" << x << ") = " << x << endl;
cout << endl << "end of program - good bye ! ! ! " << endl;
getch();
} // MAIN

/*
numerical solution - Newton's method

equation : x - cos(x) = 0 aproximation = 0.001

0.7345 2 1.2655
0.7391 0.7345 0.0046
0.7391 0.7391 0

cos(0.7391) = 0.7391

end of program - good bye ! ! !
*/