Integrales matlab

Páginas: 6 (1452 palabras) Publicado: 3 de enero de 2012
Métodos numéricos
METODO DEL TRAPECIO
function [A]= trapecio(y,a,b,n)
%esta funcion encuentra la integral de y en funcion de x,en un intervalo[a,b]
%utiliza newton cotes con P1(x)
%variables de entrada:
%y=f(x)
%a=limite inferior de integracion
%b=limite superior de integracion
%n=numero de particiones

h = (b-a)/n;
sum= 0;
x=a:h:n;
for i = 2:n
sum = sum +2*subs(y,'x',x(i));
end
A=h/2*(sum+subs(y,'x',x(1))+subs(y,'x',x(n+1)));
end

METODO DE SIMPSON 1/3
function [A] = simpson1_3( y,a,b,n)
%esta funcion encuentra la integral de y en funcion de x,en un intervalo[a,b]
%utiliza newton cotes con P2(x)
%variables de entrada:
%y=f(x)
%a=limite inferior de integracion
%b=limite superior de integracion
%n=numero de particiones
h=(b-a)/n;
x=a:h:b;
sum=0;for i=2:2:n
sum=sum+4*subs(y,'x',x(i));
end
for i=3:2:n-1
sum=sum+2*subs(y,'x',x(i));
end

A=1/3*h*(sum+subs(y,'x',x(1))+subs(y,'x',x(n+1)));
end


METODO DE SIMPSON 3/8
function [A] = simpson3_8( y,a,b,n)
%esta funcion encuentra la integral de y en funcion de x,en un intervalo[a,b]
%utiliza newton cotes con P3(x)
%variables de entrada:
%y=f(x)
%a=limite inferior deintegracion
%b=limite superior de integracion
%n=numero de particiones
h=(b-a)/n;
h=(b-a)/n;
x=a:h:b;
sum=0;
for i=4:3:n-2
sum=sum+2*subs(y,'x',x(i));
end
for i=2:3:n-1
sum=sum+3*subs(y,'x',x(i));
end
for i=3:3:n
sum=sum+3*subs(y,'x',x(i));
end
A=3/8*h*(sum+subs(y,'x',x(1))+subs(y,'x',x(n+1)));
end

METODO DE BOOLE
function [A] = boole(y,a,b,n)
%esta funcion encuentrala integral de y en funcion de x,en un intervalo[a,b]
%utiliza newton cotes con P4(x)
%variables de entrada:
%y=f(x)
%a=limite inferior de integracion
%b=limite superior de integracion
%n=numero de particiones
h=(b-a)/n;
h=(b-a)/n;
x=a:h:b;
sum=0
for i=2:4:n-2
sum=sum+32*subs(y,'x',x(i));
end
for i=3:4:n-1
sum=sum+12*subs(y,'x',x(i));
end
for i=4:4:nsum=sum+32*subs(y,'x',x(i));
end
for i=5:4:n-3
sum=sum+14*subs(y,'x',x(i));
end
A=2/45*h*(sum+7*subs(y,'x',x(1))+7*subs(y,'x',x(n+1)));
end

GRAFICA DE ERROR VS NUMERO DE PASO
function [e] = grafica( n,y)
%esta funcion grafica el error vs el paso

[p,m]=size(n);
for i=1:m
e(i)=abs(4.6333780181331074382490931343526-trapecio(y,0,1,n(i)));
end
plot(n,e)
xlabel('numero de pasos')ylabel('error')
title('grafica de numero de pasos vs error ')
legend('metodo de trapecio')
grid on
end

ENCONTRAR EL PASO IDEAL

function [ paso ] = mejorpaso(n,e)
%esta funcion encuentra el mejor numero de paso para cada funcion
% variable de entrada:n=numero de paso,e=error

[o,m]=size(n);
minimo=min(e);
for i=1:m
if (e(i)==minimo)
c=i;
end
end
paso=n(c);
endCODIFICACION DE SIMPSON-SIMPSON SIN OPERADOR GRAFICO
function [int]=integraldoblesimpson
% el programa resuelve la integral doble utilizando el metodo de simpson en
% x y en simpson en y
% no genera la matriz
z=input('INGRESE LA FUNCION F(x,y)= ','s');
a=input('Ingrese el limete inferior en x ');
b=input('Ingrese el limete superior en x ');
c=input('Ingrese el limete inferior en y ');d=input('Ingrese el limete superior en y ');
n=input('ingrese el numero de divisiones en [a,b] ');
m=input('ingrese el numero de divisiones en [c,d] ');
tic
h=(b-a)/(2*n);
g=(d-c)/(2*m);
c11=zeros(1,2*n+1);
c11(1,1)=1;c11(1,2*n+1)=1;
c11(2:2:2*n)=4;
c11(3:2:2*n-1)=2;
int=0;
for i=1:2*n+1
x=a+h*(i-1);y=c;
int=int+c11(i)*eval(z);
y=d;int=int+c11(i)*eval(z);
end
for i=1:2*n+1
x=a+h*(i-1);
for j=2:2:2*m
y=c+g*(j-1);
int=int+4*eval(z)*c11(i);
end
for j=3:2:2*m-1
y=c+g*(j-1);
int=int+2*eval(z)*c11(i);
end
end
int=int*g*h/9;
tiempo= toc;
disp('tiempo de ejecucion')
disp(tiempo)
end

CODIFICACION DE SIMPSON-SIMPSON CON OPERADOR GRAFICO
function [int]=integraldoblesimp...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Integrales En Matlab
  • Integrales por partes en matlab
  • Integrales Matlab
  • integrales en matlab
  • Resolucion De Integrales En Matlab (Ejemplos)
  • Calculo integral en matlab
  • Practica-integrales de convolucion-matlab
  • Calculo diferencial e integral en matlab

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS