SUB RUTINAS DE LOS PROGRAMAS


F.M
function y=f(x)
 y=x.^10-1;


FACTO.M
function[p]=facto(n)
% este programa es una sub rutina que sirve para calcular el factorial de
% un numero cualquiera.
%%%%%%%%%%%%%%%%%%%%%%%
p=1;
if n==0
   p=1;
else for i=1:n
   p=p*i;
   end
end


FUNP.M
function y=funp(x)
% function y=funp(x)
% caculo de la 2da iteracion del punto fijo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y=exp(-x);


FUNP1.M
function y=funp1(x)
% function y=funp1(x)
% caculo de la 2da iteracion del NEWTON-RANPHSON
%%%%%%%%%%%%%%%%%%%%%
y=exp(-x)-x;


FUNP2.M
function y=funp2(x)
% function y=funp2(x)
% caculo de la 1era. derivada en el metodo NEWTON-RANPHSON
%%%%%%%%%%%%%%%%%%%%%%
y=-exp(-x)-1;


FUNC.M
function y=func(x)
y=log(x);


FUNC2.M
function y=func2(x)
y=ln(x)


P_DIFD.M
function fdd=p_difd(x,f,n)
%
% Subrutina para las diferencias finitas divididas
%%%%%%%%%%%%%%%%%%%
for i=1:n
    fdd(i,1)=f(i);
end
for j=2:n
    for i=1:n-j+1
 fdd(i,j)=(fdd(i+1,j-1)-fdd(i,j-1))/(x(i+j-1)-x(i));
    end
end


PROG341.M
function fdd=prog341(x,f,n)
%%%%%%%%%%%
%
% Esta es una subrutina necesaria para algunos programas
% en los cuales se ira especificando su uso.
%
%%%%%%%%%%%%
for i=1:n
    fdd(i,1)=f(i);
end
for j=2:n
    for i=1:n-j+1
 fdd(i,j)=(fdd(i+1,j-1)-fdd(i,j-1))/(x(i+j-1)-x(i));
    end
end


PROG161.M
function s=prog161(ord,A,n)
% function s=prog161(ORD,A,N)
% Sub-Rutina que calcula el vector de escalamiento "s"
%%%%%%%%%%%%%%%
for i=1:n;
    ord(i)=i;
    s(i)=abs(A(i,1));
    for j=2:n;
        if abs(A(i,j)) > s(i)
           s(i)=abs(A(i,j));
        end
    end
end


PROG162.M
function [A,c]=prog162(s,c,A,ord,n)
% function [A,c]=prog162(s,c,A,ORD,N)
% Sub-Rutina que devuelve a la matriz aumentada en una matriz  triangular superior.
%%%%%%%%%%%%%%%%%%%
for k=1:n-1
    prog164(s,A,ord,n,k)
    for i=k+1:n;
        factor=A(ord(i),k)/A(ord(k),k);
        for j=k+1:n;
            A(ord(i),j)=A(ord(i),j)-factor*A(ord(k),j);
        end
        c(ord(i))=c(ord(i))-factor*c(ord(k));
    end
end


PROG163.M
function x=prog163(c,A,ord,n)
% function x=prog163(c,A,ord,n)
% Sub-Rutina que devuelve el vector "x", es decir la solución del sistema de ecuaciones "Ax = b"
%%%%%%%%%%%%%%%%%%%%%%%%
x(n)=c(ord(n))/A(ord(n),n);
for i=n-1:-1:1
    sum=0;
    for j=i+1:n;
 sum=sum+A(ord(i),j)*x(j);
    end
    x(i)=(c(ord(i))-sum)/A(ord(i),i);
end


PROG164.M
function prog164(s,A,ord,n,k)
% function prog164(s,A,ord,n,k)
% Sub-Rutina que calcula el pivoteo parcial
%%%%%%%%%%%%%%%%%
pivot=k;
big=abs(A(ord(k),k)/s(ord(k)));
for ii=k+1:n
    dummy=abs(A(ord(ii),k))/s(ord(ii));
    if dummy > big
       big=dummy;
       pivot=ii;
    end
end
idum=ord(pivot);
ord(pivot)=ord(k);
ord(k)=idum;


PIVOT.M
% ESTE PROGRAMA SIRVE PARA CALCULAR LAS RAICES DE UN
% SISTEMA DE ECUACIONES (CON PIVOTEO)
%  A = matriz de coeficientes del sistema
%  b = vector columna
%%%%%%%%%%%%%%%%%%%%
pivot=k;
big=abs(a(k,k));
for ii=k+1:m
    dummy=abs(a(ii,k));
    if (dummy>big)
        big=dummy;
        pivot=ii;
    end
end
if pivot ~= k
   for jj=1:m
       dummy=a(pivot,jj);
       a(pivot,jj)=a(k,jj);
       a(k,jj)=dummy;
   end
   dummy=c(pivot);
   c(pivot)=c(k);
   c(k)=dummy;
end


PIVOT1.M
%  A = matriz de coeficientes del sistema
%%%%%%%%%%
pivot=k;
big=abs(a(k,k));
for ii=k+1:m
    dummy=abs(a(ii,k));
    if (dummy>big)
        big=dummy;
        pivot=ii;
    end
end
if pivot ~= k
   for jj=1:m
       dummy=a(pivot,jj);
       a(pivot,jj)=a(k,jj);
       a(k,jj)=dummy;
   end
end


SUBST.M
function x=subst(c,x,A,ord,n)
% function x=subst(c,x,A,ord,n)
% SUB-RUTINA SUBST(c,x,A,ord,n)
%%%%%%%%%%%%%%%%%
x(n)=c(ord(n))/A(ord(n),n);
for i=n-1:-1:1
    sum=0;
    for j=i+1:n;
 sum=sum+A(ord(i),j)*x(j);
    end
    x(i)=(c(ord(i))-sum)/A(ord(i),i);
end

                        Ir al principio                                                                        Volver a la pagina principal