Programa

Páginas: 2 (337 palabras) Publicado: 19 de noviembre de 2012
1) Archivo trapecio.m
function q = trapecio( f,a,b )
%UNTITLED Summary of this function goes here
%
Detailed explanation goes here
ya = feval(f,a);
yb = feval(f,b);
q =(b-a)*(ya+yb)/2;
end
function y = ejemplo( x )
%UNTITLED2 Summary of this function goes here
%
Detailed explanation goes here
y=exp(-x^2);
end
>> trapecio(‘ejemplo’,0,5)
Matlab devuelve:
ans =2.5000
-------------------------------------------------2) Archivo TrapC.m
function I = TrapC( f,a,b,n )
%UNTITLED3 Summary of this function goes here
%
Detailed explanation goes hereh=(b-a)/n;
S=feval(f,b);
for i=1:n-1
x(i)=a+i*h;
S=S+2*feval(f,x(i));
end
S= S+feval(f,b);
I=h*S/2;
function y=ejemplo2(x)
y=1/x;
>> TrapC(‘ejemplo2’,1,2,2)
Matlab devuelve:
ans =0.5833
-------------------------------------3) Archivo Simpson1T.m
function s = Simpson1T( f,a,b )
%UNTITLED4 Summary of this function goes here
%
Detailed explanation goes here
ya =feval(f,a);
yb = feval(f,b);
c = (a+b)/2;
yc = feval(f,c);
q = (b-a)*(ya+4*yc+yb)/6,
end

function y = Ejemplo3( x )
%UNTITLED5 Summary of this function goes here
%
Detailed explanationgoes here
y = exp(-x^2);
end
>> Simpson1T('Ejemplo3',0,2)
Matlab devuelve:
q=
0.8299
--------------------------------4) SimpsonC.m
function J = SimpC( f,a,b,n )
%UNTITLED6 Summary ofthis function goes here
%
Detailed explanation goes here
h = (b-a)/n;
S = feval(f,a);
for i = 1:2:n-1
x(i) = a+i*h;
S = S +4*feval(f,x(i)),
end
for i = 2:2:n-2
x(i)=a+i*h;
S =S+2*feval(f,x(i));
end
S = S + feval(f,b);
J = h*S/3
end
function y = ejemplo( x )
%UNTITLED2 Summary of this function goes here
%
Detailed explanation goes here
y=exp(-x^2);
end
>>TrapC(‘ejemplo’,0,2,4)
Matlab devuelve:
ans =
0.6352
----------------------------------------------------

Prof. M. en I. Gaston Vertiz C.

Email: gas.ver2009@yahoo.com.mx

Página 2

Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Programa
  • Program
  • Un Programa
  • Programas
  • Programas
  • Programa
  • Programador
  • Program

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS