lunes, 10 de diciembre de 2012

metodo de la secante en matlab

%-----------------
%METODO DE LA SECANTE
%-----------------
%---------------------------------------------------------------
%        EL METODO DE LA SECANTE, ES UN METODO PARA ENCONTRAR
%            LOS CEROS DE UNA FUNCION DE FORMA ITERACTIVA
%---------------------------------------------------------------
%           CHEQUEE QUE POSEA TODOS LOS DATOS A EMPLEAR
clear;                      
%ELIMINA TODAS LAS VARIABLES CREADAS PREVIAMENTE (EXCEPTO LAS GLOBALES)
clc;
%BORRA TODAS LAS SALIDAS ANTERIORES Y DEJA LIMPIA EL COMMAND WINDOW
disp (' ')
disp (' EL METODO DE LA SECANTE, ES UN METODO PARA ENCONTRAR')
disp ('     LOS CEROS DE UNA FUNCION DE FORMA ITERACTIVA    ')
disp (' ')
disp ('                 TRABAJO DE APLICACION               ')
disp (' ')
disp ('                          UNESR                      ')
disp (' ')
%---------------------------------------------------------------
%INGRESO Y ASIGNACION DE DATOS
%---------------------------------------------------------------
f=input('Ingrese la funcion:\n','s');;
f=inline(f);
x0=input('Ingrese el primer punto inicial:\n');;
x1=input('Ingrese el segundo punto inicial:\n');
xra=0;
xr=0;
tol=0.01;
i=1;
error_aprox=1;
error=0;
%---------------------------------------------------------------
%CALCULOS
%---------------------------------------------------------------
fx1=f(x1);
fx0=f(x0);
xr=x1-((x1-x0)/(fx1-fx0))*fx1;
%---------------------------------------------------------------
%TABLA
%---------------------------------------------------------------
fprintf('It.        X0              X1              Xr       Error aprox \n');
fprintf('%2d \t %11.7f \t %11.7f \t %11.7f \t %11.7f \n',i,x0,x1,xr,error);

No hay comentarios:

Publicar un comentario