Vale, a ver, creo que tengo el de Steffensen, creo que he conseguido que funcione bien (perdonad, a lo mejor encontrais mi manera de programar un poco cutre, pero soy un poco novata xD):
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
//Funcion
double funcion (double x)
{
return pow(x,2) - cos(x);
}
int main()
{
double x;
double ant=1;
double cuad;
double fun;
double inter;
double fun2;
double res;
double epsilon=1;
int i=0;
while (epsilon>1.e-10)
{
fun=funcion(ant);
cuad=fun*fun;
inter=ant+fun;
fun2=funcion(inter);
x=ant-(cuad)/(fun2-fun);
epsilon=ant-x;
res=x;
ant=x;
i++;
}
cout << "Numero de iteraciones= " << i << endl;
cout << "Raiz de la funcion= " << setprecision(10) << res << endl;
system("pause");
}
En cuanto al del coseno, lo único que tengo es esto:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
float i=30; int j=10, m, k; double fact=1;
float t, res=0;
float uno=-1;
ofstream fichero;
fichero.open("cosenos.txt");
if(!fichero)
cout << "Error al abrir el fichero" << endl;
else
{
while (i<=150)
{
while(j>0)
{
k=2*j;
while (k>0)
{
fact=fact*k;
k--;
}
t=(pow(uno,j)*pow(i,2*j))/fact;
res=res+t;
cout << res << endl;
j--;
}
j=10;
fichero << setprecision(12) << i << "\t" << res << endl;
cout << setprecision(12) << i << "\t" << res << endl;
i=i+30;
res=0;
fact=1;
}
fichero.close();
}
system ("pause");
}
El profesor me lo miro y me dijo que era correcto, pero muy bien no tiene que estar, porque se me va a la porra...
Muchas gracias a todos!
