La Web del Programador: Comunidad de Programadores
 
    Pregunta:  24398 - COMO PROGRAMAR EL METODO DE MULLER
Autor:  Martha Guadalupe Verdin Chavez
Escribo porque necesito hacer un programa en Pascal que encuentre las raices imaginarias de una funcion por el metodo de Muller, no se como hacer que la funcion reconozca las operaciones con imaginarios. Cualquier cosa que tuvieran y que pudiera servirme se las agradeceria mucho, de antemano gracias.

  Respuesta:  Alexis Leung
// Metodo de Muller

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

double f(double);

int main()
{
double x0,x1,x2,h,h1,h2,g1,g2,d,D,b,p,E;
double const TOL = 0.000001;
int const NMAX = 20;
int i;

cout << "\nIntroduzca la aproximacion x0: ";
cin >> x0;
cout << "\nIntroduzca la aproximacion x1: ";
cin >> x1;
cout << "\nIntroduzca la aproximacion x2: ";
cin >> x2;

h1 = x1 - x0;
h2 = x2 - x1;
g1 = (f(x1)-f(x0))/h1;
g2 = (f(x2)-f(x1))/h2;
d = (g2 - g1)/(h2-h1);
i = 3;

while (i<=NMAX)
{
b = g2 + h2*d;
D = pow(((b*b)-(4*f(x2)*d)),0.5);

if(fabs(b - D)<fabs(b+D))
E = b + D;
else
E = b - D;

h = (-2*f(x2))/E;
p = x2 + h;

if(fabs(h)<TOL)
{
cout << "\nLa aproximacion encontrada es: "
<< p << endl;
break;
}

x0 = x1;
x1 = x2;
x2 = p;
h1 = x1 - x0;
h2 = x2 - x1;
g1 = (f(x1)-f(x0))/h1;
g2 = (f(x2)-f(x1))/h2;
d = (g2-g1)/(h2-h1);
i++;
}

if(i>NMAX)
cout << "\nEl procedimiento fallo" << endl;

getch();
}

double f(double x)
{
double p;

p = 3*pow(x,5.0) - 4*pow(x,4.0) - pow(x,3.0) + 2*pow(x,2.0) - 3*x - 2;
return(p);
}

/* Algoritmo:

Entrada: x0, x1, x2; tolerancia TOL; número maximo de iteracione N0.
Salida: Solución aproximada, p o mensaje de falla.

Paso 1: Tome h1 = x1 - x0;
h2 = x2 - x1;
g1 = (f(x1) - f(x0))/h1;
g2 = (f(x2) - f(x1))/h2;
d = (g2 - g1)/(h2 + h1);
i = 3.

Paso 2: Mienstras i <= N0 haga pasos 3 - 7.

Paso 3 b = g2 + h2*d;
D = (b^2 - 4*f(x2)*d)^1/2.

Paso 4: Si |b-D|< |b+D| entonces tome E = b +D
sino tome E = b -D

Paso 5: Tome h = -2*f(x2)/E;
p = x2 + h.

Paso 6: Si |h| < TOL entonces
SALIDA(p);
PARE.

paso 7: h1 = x1 - x0;
h2 = x2 - x1;
g1 = (f(x1) - f(x0))/h1;
g2 = (f(x2) - f(x1))/h2;
d = (g2 - g1)/(h2 + h1);
i = i + 1.

Paso 8: SALIDA ("El método fallo").
PARE. */