Академический Документы
Профессиональный Документы
Культура Документы
CICLO : IV
HVCA – 2017
MÉTODOS NUMÉRICOS
1.-MÉTODO NEWTON RAPHSON
#include <QCoreApplication>
#include <iostream>
#include <iomanip> // setprecision
#include <cmath>
#define PRECISION 10
#define MAX_ITERACIONES 100
#define INTERVALOS 6
double c;
double b;
double tolerancia; // Tolerancia
double x0; // Primera aproximación
double x1; // Siguiente aproximación
double error; // Diferencia entre dos
aproximaciones sucesivas: x1 - x0
int iteracion; // # de iteraciones
bool converge = true;
// Se ingresa el intervalo
cout << "\na = ";
cin >> c;
// Iteraciones
iteracion = 1;
do {
} else {
x1 = x0 - f(x0) / f_derivada(x0); //
Cálculo de la siguiente aproximación
error = fabs(x1 - x0); // El error es la
diferencia entre dos aproximaciones sucesivas
// Si no se cumple el criterio de
terminación, se pasa a la siguiente iteración
} else {
x0 = x1;
iteracion++;
}
}
} while (1);
// Respuesta final
if (converge) {
cout << "\n\nPara una tolerancia de " <<
tolerancia << " la raiz de f es: " << x1 << endl;
} else {
cout << "\n\nSe sobrepasó la máxima cantidad
de iteraciones permitidas" << endl;
}
cin.get();
cin.get();
return a.exec();
}
void tabula(double a, double b, int intervalos)
{
int puntos = intervalos + 1;
double f(double x)
{ double f;
f= x * exp(cos(x)) / 1.5 - 1;// funcion principal
return f;
}
double f_derivada(double x)
{double df;
df=exp(cos(x)) * (1 - x * sin(x)) / 1.5; //
derivada de la funcion principal
return df;
}
#include <QCoreApplication>
#include<QDebug>
#include"math.h"
float x0,Fx,dFx;
int N=40;
x0 = 0;
}
return a.exec();
}
#include <QCoreApplication>
#include<QDebug>
#include"math.h"
using namespace std;
float fun (float x);
while (Ea>error){
x2=(x1-((x0-x1)/(fun(x0)-fun(x1))*fun(x1)));//
f0rmula del metodo secante
qDebug (":%.10f",x2);
Ea=(fabs (x1-x2));
x0=x1;
x1=x2;
}
qDebug ("la raiz es:%.10f",x2);
return a.exec();
}
float fun(float x)
{float f;
f=x*x*x+2*x*x+10*x-20; //funcion principal
return f;
}
#include <QCoreApplication>
#include <iostream>
#include <iomanip> // setprecision
#include <cmath> // fabs
#define PRECISION 6
#define INTERVALOS 10
double c, b, tolerancia;
} else {
cout << "Tolerancia = ";
cin >> tolerancia;
cout <<
"\na\tb\tx\tf(a)\t\tf(b)\t\tf(x)\n" << endl;
do {
xr = b - f(b) * ((b - c) / (f(b) -
f(c)));
} else {
xa = xr; // Se guarda el valor de
la aproximación anterior
if (f(xr) * f(c) > 0) {
c = xr;
} else if (f(xr) * f(b) > 0) {
b = xr;
}
}
} while (1);
}
cin.get();
cin.get();
return a.exec();
}
double f(double x)
{double f;
f= exp(-1 * x) - cos(x); // funcion principal
return f;
}
5.- Método de Bisección
#include <QCoreApplication>
#include <iostream>
#include <iomanip> // setprecision
#include <cmath>
#define PRECISION 6
tabula(c, b);
float xr;
} else {
cout << "Tolerancia = ";
cin >> tolerancia;
xr = (c + b) / 2.0;
cout << c << "\t" << b << "\t" << xr <<
"\t" << f(c) << "\t" << f(b) << "\t" << f(xr) << endl;
} while (1);
}
cin.get();
cin.get();
return a.exec();
}
#define INTERVALOS 10
void tabula(float c, float b)
{
int puntos = INTERVALOS + 1;