You are on page 1of 4

Metodo de Gauss-Legendre en MatLab

El método Gauss - Lengendre, es una regla o cuadratura perteneciente a las formulas de Newton- Cotes para
la integración numérica con limites cerrados.
El código implementado a continuación se divide en dos funciones:

La función “gaussleg”, esta función es la que recibe los parámetros con los cuales se van hacer
los cálculos para generar la integración numérica.

La función “gauss”, es la función que genera las abscisas y pesos.
Función “Gaussleg”:
function [anss,abs1,wgt1] = gaussleg(f,a,b,gp,varargin)
format long
graf=(f);
f = fcnchk(f,’vectorized’);
if nargin < 4, gp = 106; end

% Default numbero de puntos Gauss.

[abs1, wgt1] = Gauss(gp);
Alphas = ((b-a)./2).*(abs1+1)+a;

% Mapeo f a [-1,1].

anss = sum(wgt1.*f(Alphas))*(b-a)/2;
if isnan(anss) | isinf(anss)
fprintf([‘\n\t Incrementando el numbero de puntos Gauss ‘…
por 1 porque esta a NaN.\n’])
[anss,abs1,wgt1] = gaussleg(f,a,b,gp+1);
end
h= (b-a) /gp;
x= a+ (0:gp)*h;
y=eval(graf);
plot(x,y,’b-‘);
grid;
title(‘Gauss Legendre’),
xlabel(‘x’);
ylabel(‘f(x)’);
Funcion Gauss:
function [x, w] = Gauss(n)
% Genera las abscisas y pesos para la Cuadratura Gauss-Legendre.
x = zeros(n,1);
w = x;
m = (n+1)/2;
for ii=1:m
z = cos(pi*(ii-.25)/(n+.5));
z1 = z+1;
while abs(z-z1)>eps

% estimado Inicial.

p1 = 1. or vector or matrix of symbolic expressions or functions. % La L. If w is the transformation variable of f. Input Arguments f Symbolic expression. p2 = p1. symbolic function. Default: The variable w. z1 = z. fourier(f. % Construye las abscissas. vector or matrix representing the evaluation point. % Construye los pesos.eval_point) computes the Fourier transform of f with respect to the transformation variable trans_var at the point eval_point. Derivada. This variable is often called the "frequency variable".trans_var. p2 = 0. trans_var Symbolic variable representing the transformation variable.eval_point) Description fourier(f. then the default evaluation point is the variable v. x.trans_var. p1 = ((2*jj-1)*z*p2-(jj-1)*p3)/jj. Default: The variable x. w(n+1-ii) = w(ii).P. Examples Compute the Fourier transform of this expression with respect to the variable syms x y f = exp(-x^2). eval_point Symbolic variable. Legendre end pp = n*(z*p1-p2)/(z^2-1). This variable is often called the "time variable" or the "space variable". % El polinomial. for jj = 1:n p3 = p2. y) ans = x at the evaluation point y: . z = z1-p1/pp. then the default variable is determined by symvar. end x(ii) = -z. expression. end fourier Fourier transform expand all in page Syntax fourier(f. w(ii) = 2/((1-z^2)*(pp^2)). If f does not contain x. x(n+1-ii) = z.

syms x t y f = exp(-x^2)*exp(-t^2). w) ans = w*fourier(f(t). y) ans = pi^(1/2)*exp(-t^2)*exp(-y^2/4) If you also do not specify the evaluation point. t. t) ans = f(t) For further computations.pi^(1/2)*exp(-y^2/4) Compute the Fourier transform of this expression calling the fourier function with one argument. w. w) ans = -pi*dirac(3. t. remove the assumption on variable x: syms x clear The Fourier transform of a function is related to the Fourier transform of its derivative: syms f(t) w fourier(diff(f(t).t0). w)*i . it returns an unevaluated call: syms f(t) w F = fourier(f. fourier uses the variable w: fourier(f) ans = pi^(1/2)*exp(-t^2)*exp(-w^2/4) Compute the following Fourier transforms that involve the Dirac and Heaviside functions: syms t w fourier(t^3. w) ans = exp(-t0*w*i)*(pi*dirac(w) . w) ifourier returns the original expression: ifourier(F. t. fourier(f. w) F = fourier(f(t).i/w) If fourier cannot find an explicit representation of the transform. If you do not specify the transformation variable. t. w)*2*i syms t0 fourier(heaviside(t . t). then fourier uses the variable x. t. t.

b. fourier([f1. the second argument must be a scalar. b. d]) ans = [ 2*pi*exp(x)*dirac(a). -2*pi*dirac(1. b]) ans = [ fourier(exp(x). c. a)*2*i. f2]. "Tables of Fourier Transforms and Fourier Transforms of Distributions".[a.Find the fourier transform of this matrix. f2(x) = x. then fourier expands the scalar arguments into arrays of the same size as the nonscalar arguments with all elements of the array equal to the scalar. w. syms w x y z a b c d fourier(x.1) . y. 1. x. 2*pi*x*dirac(b)] [ 2*pi*x*dirac(c). 2*pi*dirac(b)] [ -pi*(dirac(c . 2*pi*x*dirac(d)] Note that nonscalar input arguments must have the same size. When the first argument is a symbolic function. i*z]. d)] When the input arguments are nonscalars. a). z].[x.[a. fourier acts on them element-wise.. b)*2*i] More About expand all Fourier Transform Tips  Compute Fourier and Inverse Fourier Transforms References Oberhettinger F. d]) ans = [ pi*dirac(1. syms a b c d w x y z fourier([exp(x). sin(y). See Also ifourier | ilaplace | iztrans | laplace | ztrans . pi*dirac(1. syms f1(x) f2(x) a b f1(x) = exp(x). z]. x. If fourier is called with both scalar and nonscalar arguments.dirac(c + 1))*i.[a. Use matrices of the same size to specify the transformation variable and evaluation point. Springer. y. 1990.x.[w. c.