Você está na página 1de 16

UNIVERSIDAD NACIONAL DEL CENTRO DEL PER

TEXTO UNIVERSITARIO

LENGUAJE DE PROGRAMACION

ROSSBELL BELITO MORAN


LENGUAJE DE PROGRAMACION

HUANCAYO PERU

1. Calcular mediante los mtodos aproximados de Simpson y lobato la integral


siguiente

Para la solucin mediante el mtodo de Simpson tenemos:


>> quad(inline('2+ sin(2*sqrt(x))'),1,6)
ans = 8.1835
Para la solucin mediante el mtodo de lobato tenemos:
>> quadl (inline('2+ sin (2*sqrt (x))'),1,6)
ans = 8.1835
2. Ejecutar el siguiente programa y analizar los resultados.
%PROGRAMA PARA INTEGRALES DEFINIDAS POR EL METODO DE SIMPSON
clc;
disp('===================================================')
disp('---------------------------* METODO DE SIMPSON *-----------------------')
disp('===================================================')
syms x
A=input('ingrese funcin:')
B=input('ingrese primer limite:')
C=input('ingrese segundo limite:')
D=subs(A,B);
%Evala la funcin A para el valor de B
E=subs(A,C);
%Evala la funcin A para el valor de C
D=(B+C)/2;
F=subs(A,D);
%Evala la funcin para la semisuma de valores
G=(C-B)*(D+E+4*F)/6;
disp('-------------------------------')
fprintf('La solucin es: %10.6f\n',G);
disp('-------------------------------')
SALIDA:
===================================================
---------------------------* METODO DE SIMPSON *-----------------------===================================================
ingrese funcion:log(x/2)-x^3+x
A=
log(1/2*x)-x^3+x
ingrese primer limite:4
B=
4
ingrese segundo limite:2
C=
2

---------------------------------La solucin es: 32.459380


----------------------------------

3. CALCULAR EL AREA POR EL METODO DEL TRAPECIO

clc,
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%')
disp('
* CALCULO DE AREA APROX. POR EL METODO DEL TRAPECIO
*')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%')
disp('
Cargando...')
disp(' ')
disp('
para continuar presione una tecla cualquiera')
pause
clc,
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%')
disp('
* CALCULO DE AREA APROX. POR EL METODO DEL TRAPECIO
*')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%')
disp(' ')
f=input('Ingrese la funcin a integrar f(x) =','s');
a=input('Ingrese limite inferior :');
b=input('Ingrese limite superior :');
n=input('Ingrese nmeros de trapecios a considerar en la integracin
:');
while a==b;
'EL AREA DE LA REGIN ES CERO, si quiere calcular otra area ingrese
los datos'
f=input('Ingrese la funcin a integrar f(x) =','s');
a=input('Ingrese limite inferior :');
b=input('Ingrese limite superior :');
n=input('Ingrese nmeros de trapecios a considerar en la
integracin :');
end
h=(b-a)/n;
x=a:h:b;
fx=eval(f);y=abs(fx);
A=y(1)+y(n+1);
B=2*sum(y(2:n));
R=(h/2)*(A+B);
formatlong
A=abs(R);
disp('EL AREA DE LA REGION CALCULADA ES:')
disp(' ')
disp(A)
disp('LA GRAFICA DE LA REGION CALCULADA ES...')
if a<b;
holdon
x=a:0.0001:b;
y=eval(f);

bar(x,y,'c')
grid
else a>b;
holdon
x=a:-0.0001:b;
y=eval(f);
bar(x,y,'c')
grid
end

EJECUTANDO EL PROGRAMA:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
* CALCULO DE AREA POR EL METODO DEL TRAPECIO *
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
Ingrese la funcin a integrar f(x) =sqrt(126-x.^3)
Ingrese limite inferior :1
Ingrese limite superior :4
Ingrese nmeros de trapecios a considerar en la integracin :10
EL AREA DE LA REGION CALCULADA ES:
30.556962269691816
LA GRAFICA DE LA REGION CALCULADA ES...

12

10

0
0.5

1.5

2.5

3.5

4.5

4. CALCULAR EL AREA POR EL MTODO DE SIMPSON


%Programa para integrar por el mtodo del trapecio
clc,
disp('#################################################')
disp('-------------*regla parabolica(simpson)*-------------')
disp('#################################################')
f=input('Ingrese la funcin f(x) =','s');
a=input('Ingrese limite superior :');
b=input('Ingrese limite inferior :');
n=input('Ingrese el nmeros de`parabolas a integrar :');
h=(a-b)/n;
x=b:h:a;
fx=eval(f);
y=abs(fx);
A=y(1)+y(n+1);
B=4*sum(y(2:2:n));
C=2*sum(y(3:2:n-1));
integral=(h/3)*(A+B+C);
fprintf('el rea es:%12.6f\n',integral);
disp('#############################')
disp('-------fin del programa-----')
disp('#############################')
%grafica
subplot(1,2,1)
plot(x,fx)
subplot(1,2,2)
bar(x,fx,'g')

#################################################
-------------*REGLA PARABOLICA(SIMPSON)*------------#################################################
Ingrese la funcin f(x) =x.^2+5.*x
Ingrese limitesuperior :4
Ingrese limiteinferior :0
Ingrese el nmeros de`parabolas a integrar :8
el rea es: 61.333333
#############################

-------fin del programa----#############################

40

40

35

35

30

30

25

25

20

20

15

15

10

10

0
-2

5. ESTE PROGRAMA SIRVE PARA INTEGRAR POR INTEGRALES


NUMRICAS POR EL MTODO DE SIMPSON UNA FUNCIN DADA Y
PARA GRAFICAR DICHA FUNCIN.
clc,clear all
disp(' INTEGRACION NUMERICA CON EL METODO DE SIMPSON')
f=input('ingrese la funcin a integrar f(x)= ','s');%FUNCION
a=input('ingrese limite inferior: ');
b=input('ingrese limite superior: ');
fprintf('ingrese nmero de trapecios\n');
n=input('ingrese numero de trapecios: ');
n=2*n;xmin=a-1;xmax=b+1;
h=(b-a)/n;

x=a:h:b;
fx=eval(f);
y=abs(fx);%valor absoluto
suma1=y(1)+y(n+1);
suma2=4*sum(y(2:2:n));
suma3=2*sum(y(3:2:n-1));
suma=suma1+suma2+suma3;
integral=(h/3)*suma;
fprintf('el rea es :',integral);%grafica
xp=xmin:0.2:xmax;
x=xp;
yp=eval(f);
plot(xp,yp,'g');%'g'color de la grafica
hold on% activa la opcion
x=a:0.05:b;
y=eval(f);%evalua la funcion
bar(x,y,'r');%grafica en barras

SALIDA
INTEGRACION NUMERICA CON EL METODO DE SIMPSON
ingrese la funcin a integrar f(x)= 5*x+6
ingrese limite inferior: 2
ingrese limite superior: 5
ingrese nmero de trapecios
ingrese numero de trapecios: 4
el rea es :70.500000000

40
35
30
25
20
15
10
5
0

1.5

2.5

3.5

4.5

5.5

REGLA DE SIMPSON
En este procedimiento, se toma el intervalo de anchura 2h, comprendido
entre xi y xi+2, y se sustituye la funcin f(x) por la parbola que pasa
por tres puntos (xi, yi), (xi+1, yi+1), y (xi+2, yi+2). El valor del rea
aproximada, sombreada en la figura, se calcula con un poco ms de
trabajo y el resultado es

PROGRAMA 1

clc
disp('')
disp('.........................................')
disp('...........REGLA DE SIMPSON............')
%utilizando este metodo solo para integrar
disp('.........................................')
disp(' ')
A=input(' f(x)=');
a=input('ingrese el limite inferior=');
b=input('ingrese el limite superior=');
while a>b;
disp(' ')
disp('.........el primer limite es inferior');
disp(' ')
a=input('ingrese el limite inferior=');
b=input('ingrese el limite superior=');
end
fa=subs(A,a);
fb=subs(A,b);
c=(a+b)/2;
fc=subs(A,c);
intA=((b-a)/6)*(fa+4*fc+fb);

disp(' ')
disp('integrando sale...');
disp(intA)

APLICACIN

PROGRAMA 2
%PROGRAMA PARA INTEGRALES DEFINIDAS POR EL METODO DE
SIMPSON
clc;
disp('===================================================')
disp('---------------------------* METODO DE SIMPSON *-----------------------')
disp('===================================================')
syms x
A=input('ingrese funcin:')
B=input('ingrese primer limite:')
C=input('ingrese segundo limite:')
D=subs(A,B);
%Evala la funcin A para el valor de B
E=subs(A,C);
%Evala la funcin A para el valor de C
D=(B+C)/2;
F=subs(A,D);
%Evala la funcin para la semisuma de valores
G=(C-B)*(D+E+4*F)/6;
disp('-------------------------------')
fprintf('La solucin es: %10.6f\n',G);
disp('-------------------------------')

SALIDA:
===================================================
---------------------------* METODO DE SIMPSON *-----------------------===================================================
ingrese funcion:log(x/2)-x^3+x
A = log(1/2*x)-x^3+x
ingrese primer limite:4
B=4
ingrese segundo limite:2
C=2
----------------------------------La solucin es: 32.459380----------------------------------

PROGRAMA 3
clc;
disp('=================================================')
disp('------------------------* METODO DE SIMPSON *-------------------------')
disp('=================================================')
f=input('ingrese la funcin integral f(x)=','s');
a=input('ingrese limite inferior:');
b=input('ingrese limite superior:');
fprintf('ingrees numero de trapecios a \n');
n=input('considerar en la integracin:')
n=2*n;xmin=a-1; xmax=b+1;
h=(b-a)/n;
x=a:h:b;
fx=eval(f);y=abs(fx);
suma1=y(1)+y(n+1);suma2=3*sum(y(2:3:n-1));
suma3=3*sum(y(3:3:n));suma4=2*sum(y(4:3:n-2));
suma=suma1+suma2+suma3+suma4;
integral=(3/4)*h*suma;
fprintf('El area es:%10.9f\n',integral);
%grafica
xp=xmin:0.2:xmax;
x=xp
yp=eval(f);
plot(xp,yp,'g');
hold on
x=a:0.05:b;
y=eval(f);
bar(x,y,'r');
grid on

SALIDA:
==============================================
----------------------* METODO DE SIMPSON *-------------------==============================================
ingrese la funcion integral f(x)=sqrt(x.^5+x.*3+2)
ingrese limite inferior:2
ingrese limite superior:4
ingrees numero de trapecios a
considerar en la integracion:40
n=

40

El area es:65.038996358
x = Columns 1 through 6
1.0000 1.2000 1.4000 1.6000 1.8000 2.0000
Columns 7 through 12
2.2000 2.4000 2.6000 2.8000 3.0000 3.2000
Columns 13 through 18
3.4000 3.6000 3.8000 4.0000 4.2000 4.4000
Columns 19 through 21
4.6000 4.8000 5.0000

PROGRAMA 4
clc;
disp('========================================================
==')
disp('*PROGRAMA PARA HALLAR EL AREA USANDO EL METODO DE
SIMPSON*')
disp('========================================================
==')
f=input('ingrese la funcin integral f(x)=','s');
a=input('ingrese limite inferior:');
b=input('ingrese limite superior:');
n=input('ingrese el numero de trapecios considerar:');
n=2*n;xmin=a; xmax=b;
h=(b-a)/n;
x=a:h:b;
F=eval(f);y=abs(F);
suma1=y(1)+y(n+1);suma2=3*sum(y(2:3:n-1));
suma3=3*sum(y(3:3:n));suma4=2*sum(y(4:3:n-2));
suma=suma1+suma2+suma3+suma4;

integral=(3/4)*h*suma;
fprintf('El AREA ES:%10.9f\n',integral);
%grafica
xp=xmin:0.2:xmax;
x=xp;
yp=eval(f);
plot(xp,yp,'y');
hold on
x=a:0.05:b;
y=eval(f);
bar(x,y,'y');
grid on
SALIDA
============================================================
*PROGRAMA PARA HALLAR EL AREA USANDO EL METODO DE
SIMPSON*
============================================================
ingrese la funcin integral f(x)=x.^(2+sin(x))
ingrese limite inferior:0
ingrese limite superior:pi
ingrese el numero de trapecios considerar:20
El AREA ES:29.589833339
12

10

0
-0.5

0.5

1.5

2.5

3.5

PROGRAMA 5
%mtodo de integracin numrica de funciones por el mtodo de simpson 3/8
f=input('
ingrese la funcin a integrar f(x) = ','s');
a=input('
ingrese limite inferior :
');
b=input('
ingrese limite superior :
');
fprintf('
ingrese numero de trapecios a \ n');
n=input('
considerar en la integracin :
');
n=2*n; xmin=a-1;xmax=b+1;
h=(b-a)/n;
x=a:h:b;
fx=eval(f);y=abs(fx);
suma1=y(1)+y(n+1); suma2=3*sum(y(2:3:n-1));
suma3=3*sum(y(3:3:n)); suma4=2*sum(y(4:3:n-2));
suma= suma1+suma2+suma3+suma4;
integral=(3/8)*h*suma;
fprintf('El rea es : %10.9f\n',integral);
%grafica
xp= xmin:0.2:xmax;
x=xp
yp=eval(f);
plot(xp,yp,'g');
hold on
x=a:0.05:b;
y=eval(f);
bar(x,y,'r');
grid on

SALIDA:
ingrese la funcin a integrar f(x) = sqrt(x.^5+x.*3+2)
ingrese limite inferior :
2
ingrese limite superior :
4
ingrese numero de trapecios a
considerar en la integracin :
El rea es : 32.519498179
x=
Columns 1 through 4
1.0000 1.2000 1.4000 1.6000
Columns 5 through 8
1.8000 2.0000 2.2000 2.4000
Columns 9 through 12
2.6000 2.8000 3.0000 3.2000
Columns 13 through 16
3.4000 3.6000 3.8000 4.0000
Columns 17 through 20
4.2000 4.4000 4.6000 4.8000
Column 21
5.0000

40

Você também pode gostar