metodos numericos
hola, necesito ayuda para hacer programas en c++ de metodos numericos, no se programar bien , asi ke si alguine tiene un programa ke resuelva metodo de biseccion, secante .. porfavor no sea malito ke me lo pase plissssssssss!!!...
lo mas pronto posible porfa..
gracias
lo mas pronto posible porfa..
gracias
a continuacion uin programa por el metodo de biseccion:
// 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
// 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
Otro programa, esta vez por el metodo de Newton:
// program k2c7.CPP - page 39
// numerical solution - Newton's method
// equation : x - cos(x) = 0
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// 7/7/2001
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <math.h>
const double aprox = 0.001;
void main()
{
clrscr();
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 ! ! !
*/
// program k2c7.CPP - page 39
// numerical solution - Newton's method
// equation : x - cos(x) = 0
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// 7/7/2001
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <math.h>
const double aprox = 0.001;
void main()
{
clrscr();
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 ! ! !
*/
pues tengo todos los metodos numericos, secante, simpson 1/3 y 3/8, newton, interpolacion, diferencias divididas, etct,etc.
Te recomiendo el libro de Nackamura "Applied numerical method".
O mas facil este es mi correo, escribe si los necesitas!
[email protected]
Te recomiendo el libro de Nackamura "Applied numerical method".
O mas facil este es mi correo, escribe si los necesitas!
[email protected]
