Anda di halaman 1dari 4

UNIVERSIDAD CENTRAL DEL ECUADOR

FACULTAD DE INGENIERÍA QUÍMICA

ANÁLISIS NUMÉRICO

NOMBRE: Francisco González-Valerio


Programas fuente de Interpolación y aproximación lineal
1. Series de Taylor y cálculo de los valores de una función
clear all;clc
x=input('Introduce el valor de x: ');
n=input('Introduce el valor de n: ');
z=0;
for i=0:n
y=x^i/factorial(i);
z=z+y;
end
fprintf('El valor de exp(x) es %.5g \n',z);

2. Introducción a la interpolación

% NUMERICAL METHODS: MATLAB Programs


%(c) 1999 by John H. Mathews and Kurtis D. Fink
%To accompany the textbook:
%NUMERICAL METHODS Using MATLAB,
%by John H. Mathews and Kurtis D. Fink
%ISBN 0-13-270042-5, (c) 1999
%PRENTICE HALL, INC.
%Upper Saddle River, NJ 07458
w=length(X);
n=w-1;
L=zeros(w,w);

for k=1:n+1
V=1;
for j=1:n+1
if k~=j
V=conv(V,poly(X(j)))/(X(k)-X(j));
end
end
L(k,:)=V;
end

C=Y*L

3. Interpolación de lagrange
function [C,L]=lagran(X,Y)

%Input - X is a vector that contains a list of abscissas


% - Y is a vector that contains a list of ordinates
%Output - C is a matrix that contains the coefficents of
% the Lagrange interpolatory polynomial
% - L is a matrix that contains the Lagrange
% coefficient polynomials

% NUMERICAL METHODS: MATLAB Programs


%(c) 1999 by John H. Mathews and Kurtis D. Fink
%To accompany the textbook:
%NUMERICAL METHODS Using MATLAB,
%by John H. Mathews and Kurtis D. Fink
%ISBN 0-13-270042-5, (c) 1999
%PRENTICE HALL, INC.
%Upper Saddle River, NJ 07458

w=length(X);
n=w-1;
L=zeros(w,w);

%Form the Lagrange coefficient polynomials

for k=1:n+1
V=1;
for j=1:n+1
if k~=j
V=conv(V,poly(X(j)))/(X(k)-X(j));
end
end
L(k,:)=V;
end

%Determine the coefficients of the Lagrange interpolator


%polynomial

C=Y*L
4. Polinomio interpolador de Newton
function [p0,err,k,y]=newton(f,df,p0,delta,epsilon,max1)

%Input - f is the object function input as a string 'f'


% - df is the derivative of f input as a string 'df'
% - p0 is the initial approximation to a zero of f
% - delta is the tolerance for p0
% - epsilon is the tolerance for the function values y
% - max1 is the maximum number of iterations
%Output - p0 is the Newton-Raphson approximation to the zero
% - err is the error estimate for p0
% - k is the number of iterations
% - y is the function value f(p0)

% NUMERICAL METHODS: MATLAB Programs


%(c) 1999 by John H. Mathews and Kurtis D. Fink
%To accompany the textbook:
%NUMERICAL METHODS Using MATLAB,
%by John H. Mathews and Kurtis D. Fink
%ISBN 0-13-270042-5, (c) 1999
%PRENTICE HALL, INC.
%Upper Saddle River, NJ 07458
for k=1:max1
p1=p0-feval(f,p0)/feval(df,p0);
err=abs(p1-p0);
relerr=2*err/(abs(p1)+delta);
p0=p1;
y=feval(f,p0);
if (err<delta)|(relerr<delta)|(abs(y)<epsilon),break,end
end

5. Polinomios de Chevysheb
function [C,X,Y]=cheby(fun,n,a,b)

%Input - fun is the string function to be approximated


% - N is the degree of the Chebyshev interpolating polynomial
% - a is the left endpoint
% - b is the right endpoint
%Output - C is the coefficient list for the polynomial
% - X contains the abscissas
% - Y contains the ordinates

% NUMERICAL METHODS: MATLAB Programs


%(c) 1999 by John H. Mathews and Kurtis D. Fink
%To accompany the textbook:
%NUMERICAL METHODS Using MATLAB,
%by John H. Mathews and Kurtis D. Fink
%ISBN 0-13-270042-5, (c) 1999
%PRENTICE HALL, INC.
%Upper Saddle River, NJ 07458

if nargin==2, a=-1;b=1;end
d=pi/(2*n+2);
C=zeros(1,n+1);

for k=1:n+1
X(k)=cos((2*k-1)*d);
end
X=(b-a)*X/2+(a+b)/2;
x=X;
Y=eval(fun);

for k =1:n+1
z=(2*k-1)*d;
for j=1:n+1
C(j)=C(j)+Y(k)*cos((j-1)*z);
end
end

C=2*C/(n+1);
C(1)=C(1)/2;

6. Aproximaciones de Padé
s=tf('s');
fprintf('Ingrese la función en la variable s');
p=exp(-2.6*s)/(s^2+0.6*s-2);
step(p)
hold on
n=input('Ingrese el grado de aproximación');
gs=pade(p,n)
step(gs)
grid

Anda mungkin juga menyukai