Documentos de Académico
Documentos de Profesional
Documentos de Cultura
1
end
d i s p ( ’ l a i n t e g r a l d o b l e por e l metodo de simpson e s : ’ )
J=h / 3 ∗ ( J1+2∗J2+4∗J3 )
end
%d e r i v a d a h a c i a a d e l a n t e
g=i n p u t ( ’ i n g r e s e tu f u n c i o n e . g a s i @( x ) c o s ( x ) : ’ , ’ s ’ ) ;
f=s t r 2 f u n c ( g ) ;
h=i n p u t ( ’ i n g r e s e l a amplitud a t r a b a j a r : ’ ) ; %cuando e l v a l o r e s mas p e q u e o s
d=i n p u t ( ’ e l orden de l a d e r i v a d a a c a l c u l a r : ’ ) ; %orden 1 , 2 o 3
x=i n p u t ( ’ un punto donde q u i e r e s aproximar l a d e r i v a d a : ’ ) ;
i f d==1
Fd3=(4∗ f ( x+h)− f ( x+2∗h)−3∗ f ( x ) ) / ( 2 ∗ h ) ;
d i s p ( ’ p r i m e r a d e r i v a d a es ’ )
f p r i n t f ( ’ adelante : %.10 f \n ’ , Fd3 )
e l s e i f d==2
Fd3=( f ( x+2∗h)−2∗ f ( x+h)+ f ( x ) ) / ( h ^ 2 ) ;
d i s p ( ’ segunda d e r i v a d a es ’ )
f p r i n t f ( ’ a d e l a n t e : %.10 f \n ’ , Fd3 )
e l s e i f d==3
Fd3=( f ( x+3∗h)−3∗ f ( x+2∗h)+3∗ f ( x+h)− f ( x ) ) / ( h ^ 3 ) ;
d i s p ( ’ t e r c e r a d e r i v a d a es ’ )
f p r i n t f ( ’ a d e l a n t e : %.10 f \n ’ , Fd3 )
else
d i s p ( ’ ∗ ∗ f o r m u l a no d i s p o n i b l e ∗ ∗ ’ )
end
% Romberg
f = i n p u t ( ’ i n g r e s e tu f u n c i o n e . g a s i @( x ) c o s ( x ) : ’ , ’ s ’ ) ;
a = input ( ’ i n g r e s a r l i m i t e i n f e r i o r , a : ’);
b = input ( ’ i n g r e s a r l i m i t e superior , b : ’);
n = i n p u t ( ’ i n g r e s a r e l n m e r o de s u b i n t e r v a l o s , n : ’);
h = b−a ;
r = z e r o s ( 2 , n +1);
r ( 1 , 1 ) = h ∗ ( f ( a)+ f ( b ) ) / 2 ;
f p r i n t f ( ’ \ nRomberg i n t e g r a t i o n t a b l e : \ n ’ ) ;
f p r i n t f ( ’ \ n %11.8 f \n\n ’ , r ( 1 , 1 ) ) ;
for i = 2:n
sum = 0 ;
f o r k = 1 : 2 ^ ( i −2)
sum = sum+f ( a+(k −0.5)∗ h ) ;
2
end
r ( 2 , 1 ) = ( r (1 ,1)+ h∗sum ) / 2 ;
for j = 2: i
l = 2^(2∗( j −1));
r ( 2 , j ) = r ( 2 , j −1)+( r ( 2 , j −1)−r ( 1 , j −1))/( l −1);
end
for k = 1: i
f p r i n t f ( ’ %11.8 f ’ , r ( 2 , k ) ) ;
end
f p r i n t f ( ’ \ n\n ’ ) ;
h = h/2;
for j = 1: i
r (1 , j ) = r (2 , j ) ;
end
end
%d e r i v a d a h a c i a a t r a s
g=i n p u t ( ’ i n g r e s e tu f u n c i o n e . g a s i @( x ) c o s ( x ) : ’ , ’ s ’ ) ;
f=s t r 2 f u n c ( g ) ;
h=i n p u t ( ’ i n g r e s e h : ’ ) ; %cuando e l v a l o r e s mas p e q u e o s e t i e n e mejor r e s u l t a
d=i n p u t ( ’ numero de d e r i v a d a s a c a l c u l a r : ’ ) ;
x=i n p u t ( ’ un punto donde q u i e r e s aproximar l a d e r i v a d a : ’ ) ;
i f d==1
Bd3=(−4∗ f ( x−h)+ f ( x−2∗h)+3∗ f ( x ) ) / ( 2 ∗ h ) ;
d i s p ( ’ p r i m e r a d e r i v a d a es ’ )
f p r i n t f ( ’ a t r a s : %.10 f \n ’ , Bd3 )
e l s e i f d==2
Bd3=( f ( x−2∗h)−2∗ f ( x−h)+ f ( x ) ) / ( h ^ 2 ) ;
d i s p ( ’ segunda d e r i v a d a es ’ )
f p r i n t f ( ’ a t r a s : %.10 f \n ’ , Bd3 )
e l s e i f d==3
Bd3=(− f ( x−3∗h)−3∗ f ( x−h)+3∗ f ( x−2∗h)+ f ( x ) ) / ( h ^ 3 ) ;
d i s p ( ’ t e r c e r a d e r i v a d a es ’ )
f p r i n t f ( ’ a t r a s : %.10 f \n ’ , Bd3 )
else
d i s p ( ’ ∗ ∗ f o r m u l a no d i s p o n i b l e ∗ ∗ ’ )
end