lunes, 12 de enero de 2015

Método de Regula Falsi en Matlab

Función principal 


function []=regu_fal(x1, x2, n);

fx1=f(x1);
fx2=f(x2);
c = x2 - ((f(x2)*(x2-x1))/(f(x2) - f(x1)))
fc=f(c)
if fx1*fx2<0;
     for i=1:n
     if fc<0
        x1=c;
        fx1=f(x1);
        c = x1 - (fx1*(x1-x2)/(fx1-fx2))
        fc = f(c)
       else
          x2=c;
          fx2=f(x2);
          c = x2 - (fx2*(x2-x1)/(fx2-fx1))
          fc = f(c)
      end
    end
else
    disp('Error en los Valores X1, X2');
end
end
Ecuación a resolver.

function fx = f(x);
	fx = x^3-9*x+1;  %% puedes cambiar por la funcion que gustes
	return;

No hay comentarios:

Publicar un comentario