Sei sulla pagina 1di 31

UNIVERSIDAD NACIONAL HERMILIO VALDIZAN

EAP: ING.CIVIL
CURSO: METODOS NUMERICOS

1.programas de trapecio simple y Simpson simple


a.-trapacio simple

function trapsim
global fun
fun=input('ingrese la funcion\n','s');
b=input('ingrese el limite superior de la integral\n');
a=input('ingrese el limite inferior de la integral\n');
h=b-a
x=a;
fa=eval(fun);
x=b;
fb=eval(fun);
I=(h/2)*(fa+fb);
fprintf('El valor aproximado es =%12.10f',I)

b. Simpson simple

function simpson
global fun
fun=input('ingrese la funcion\n','s');
b=input('ingrese el limite superior de la funcion\n');
a=input('ingrese el limite inferior de la integral\n');
h=(b-a)/2
x=a;
fa=eval(fun);
x=b;
fb=eval(fun);
x=a+h;
fc=eval(fun);
I=(3*h/8)*(fa+4*fc+fb)
fprintf('El valor aproximado de la integral es =%12.10f',I)

c. regla de los tres octavos

function regla3/8
global fun
fun=input('ingrese la funcion\n','s');
b=input('ingrese el limite superior de la funcion\n');
a=input('ingrese el limite inferior de la integral\n');
h=(b-a)/3
x=a;
fa=eval(fun);
x=a+h;
fc=eval(fun);
x=a+2*h;
fd=eval(fun);
x=b;
fb=eval(fun);
I=(3*h/8)*(fa+3*fc+3*fd+fb)
fprintf('El valor aproximado de la integral es =%12.10f',I)

2. programa de la regla del trapecio compuesto y Simpson compuesto

2.1 trapecio compuesto

function trapcomp
global fun
fun=input('ingrese la funcion\n','s');
b=input('ingrese el limite superior de la integral\n');
a=input('ingrese el limite inferior de la integral\n');
M=input('ingrese el numero de intervalos\n');
h=(b-a)/M;
I=0;
for k=1:M-1
x=a+h*k
f1=eval(fun)
I=I+f1
end
x=a
fa=eval(fun)
x=b
fb=eval(fun)
I=((h/2)*(fa+fb))+(h)*(I)
fprintf('El valor aproximado es =%12.10f',I)

2.2 Simpson compuesto

function simpscomp
global fun
fun=input('ingrese la funcion\n','s');
b=input('ingrese el limite superior de la integral\n');
a=input('ingrese el limite inferior de la integral\n');
n=input('ingrese el numero de intervalos');
h=(b-a)/(2*n)
i1=0
i2=0
for k=1:n-1
x=a+h*(2*k)
f1=eval(fun)
i1=i1+f1
end
for k=1:n
x=a+h*(2*k-1)
f2=eval(fun)
i2=i2+f2
end
x=a
fa=eval(fun)
x=b
fb=eval(fun)
i=(h/3)*((fa+fb)+(2*i1)+(4*i2))
fprintf('el valor aproximado de la integral es =%12.10f',i)

3. calculo de la integral por la regla del trapecio, Simpson y 3/8

I=

a. regla de trapecio

utilizar el comando trapsim en el comando window

ingrese la funcion

tan(x)

ingrese el limite superior de la integral

pi/4

ingrese el limite inferior de la integral

h =
0.7854

El valor aproximado es =0.3926990817>>

b. regla de simpson

utilizar el comando simpson en el comando window

ingrese la funcion

tan(x)

ingrese el limite superior de la funcion

pi/4

ingrese el limite inferior de la integral

h =

0.3927

I =

0.3913

El valor aproximado de la integral es =0.3912540840>>

c. regla de trapecio

utilizar el comando regla3/8 en el comando window

ingrese la funcion
tan(x)

ingrese el limite superior de la funcion

pi/4

ingrese el limite inferior de la integral

h =

0.2618

I =

0.3471

El valor aproximado de la integral es =0.3471360122>>

De los tres resultados anteriores el mas aproximado es por la regla de tres


octavos

4. calcular: I=
a.usar regla de Simpson compuesto :
a.1 con n=4 utilizar el comando simpscomp en el comando window
ingrese la funcion
tan(x)
ingrese el limite superior de la integral
pi/4
ingrese el limite inferior de la integral
0
ingrese le numero de intervalos 4

h =

0.0982
i1 =

i2 =

x =

0.1963

f1 =

0.1989

i1 =

0.1989

x =

0.3927

f1 =

0.4142

i1 =

0.6131
x =

0.5890

f1 =

0.6682

i1 =

1.2813

x =

0.0982

f2 =

0.0985

i2 =

0.0985

x =

0.2945

f2 =

0.3033

i2 =
0.4018

x =

0.4909

f2 =

0.5345

i2 =

0.9363

x =

0.6872

f2 =

0.8207

i2 =

1.7570

x =

fa =

0
x =

0.7854

fb =

1.0000

i =

0.3466

el valor aproximado de la integral es =0.3465805405>>

a.2 con n=8 utilizar el comando simpscomp en el comando window

ingrese la funcion
tan(x)
ingrese el limite superior de la integral
pi/4
ingrese el limite inferior de la integral
0
ingrese le numero de intervalos>> 8

h =

0.0491

i1 =

i2 =

0
x =

0.0982

f1 =

0.0985

i1 =

0.0985

x =

0.1963

f1 =

0.1989

i1 =

0.2974

x =

0.2945

f1 =

0.3033

i1 =
0.6008

x =

0.3927

f1 =

0.4142

i1 =

1.0150

x =

0.4909

f1 =

0.5345

i1 =

1.5495

x =

0.5890

f1 =

0.6682
i1 =

2.2177

x =

0.6872

f1 =

0.8207

i1 =

3.0383

x =

0.0491

f2 =

0.0491

i2 =

0.0491

x =

0.1473

f2 =
0.1483

i2 =

0.1975

x =

0.2454

f2 =

0.2505

i2 =

0.4479

x =

0.3436

f2 =

0.3578

i2 =

0.8058

x =

0.4418
f2 =

0.4730

i2 =

1.2787

x =

0.5400

f2 =

0.5994

i2 =

1.8781

x =

0.6381

f2 =

0.7417

i2 =

2.6197
x =

0.7363

f2 =

0.9063

i2 =

3.5261

x =

fa =

x =

0.7854

fb =

1.0000

i =

0.3466

el valor aproximado de la integral es =0.3465740373>>


5. programa. la integración de romberg
function romberg
global fun
fun=input('ingrese la funcion\n','s');
b=input('ingrese el limite superior de la integral\n');
a=input('ingrese el limite inferior de la integral\n');
n=input('ingrese el numero de intervalos\n');
h=(b-a);
M=1;
J=0;
R=zeros(n,n);
x=a;
f1=eval(fun);
x=b;
f2=eval(fun);
R(1,1)=h*(f1+f2)/2;
while(J<(n-1))
J=J+1;
h=h/2;
s=0
for p=1:M
x=a+h*(2*p-1);
f3=eval(fun)
s=s+f3;
end
R(J+1,1)=(1/2)*(R(J,1))+h*s;
M=2*M
for k=1:J
R(J+1,k+1)=R(J+1,k)+(R(J+1,k)-R(J,k))/(4^k-1)
end
end
i=R(J+1,J+1)
ezplot(fun),grid on

6. clacular la integral utilizando romberg.

I= , con n=6 , ejecutamos el comando romberg en el comando


window

ingrese la funcion

(x.^2+x+1)*cos(x)

ingrese el limite superior de la integral

pi/2
ingrese el limite inferior de la integral

ingrese el numero de intervalos

s =

f3 =

1.6986

M =

R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0
0 0 0 0 0 0

0 0 0 0 0 0

s =

f3 =

1.4292

f3 =

1.3647

M =

R =
0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

s =

f3 =

1.2112
f3 =

1.6097

f3 =

1.6365

f3 =

0.8318

M =

R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0
1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 2.0382 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 2.0382 2.0382 0 0

0 0 0 0 0 0

0 0 0 0 0 0
s =

f3 =

1.1025

f3 =

1.3218

f3 =

1.5273

f3 =

1.6693

f3 =
1.6902

f3 =

1.5302

f3 =

1.1336

f3 =

0.4549

M =

16

R =
0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 2.0382 2.0382 0 0

2.0333 2.0382 0 0 0 0

0 0 0 0 0 0

R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 2.0382 2.0382 0 0

2.0333 2.0382 2.0382 0 0 0

0 0 0 0 0 0

R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 2.0382 2.0382 0 0

2.0333 2.0382 2.0382 2.0382 0 0

0 0 0 0 0 0
R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 2.0382 2.0382 0 0

2.0333 2.0382 2.0382 2.0382 2.0382 0

0 0 0 0 0 0

s =

f3 =

1.0502

f3 =

1.1563
f3 =

1.2665

f3 =

1.3762

f3 =

1.4798

f3 =

1.5709

f3 =

1.6428
f3 =

1.6882

f3 =

1.6996

f3 =

1.6695

f3 =

1.5904

f3 =

1.4553

f3 =
1.2577

f3 =

0.9918

f3 =

0.6529

f3 =

0.2374

M =

32

R =
0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 2.0382 2.0382 0 0

2.0333 2.0382 2.0382 2.0382 2.0382 0

2.0370 2.0382 0 0 0 0

R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 2.0382 2.0382 0 0

2.0333 2.0382 2.0382 2.0382 2.0382 0

2.0370 2.0382 2.0382 0 0 0

R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 2.0382 2.0382 0 0

2.0333 2.0382 2.0382 2.0382 2.0382 0

2.0370 2.0382 2.0382 2.0382 0 0


R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 2.0382 2.0382 0 0

2.0333 2.0382 2.0382 2.0382 2.0382 0

2.0370 2.0382 2.0382 2.0382 2.0382 0

R =

0.7854 0 0 0 0 0

1.7268 2.0406 0 0 0 0

1.9605 2.0384 2.0383 0 0 0

2.0188 2.0382 2.0382 2.0382 0 0

2.0333 2.0382 2.0382 2.0382 2.0382 0

2.0370 2.0382 2.0382 2.0382 2.0382 2.0382

i =

2.0382
7. programa de romberg modificado para aproximar I=

Cuando la tolerancia = Escriba aquí la ecuación.

Potrebbero piacerti anche