Está en la página 1de 29

UNIVERSIDAD PRIVADA DEL VALLE

FACULTAD DE TECNOLOGIA
Evaluación
INGENIERIA CIVIL
CAMPUS TIQUIPAYA

METODOS NUMERICOS

Informe de Practica Nº 7

Grupo “B”

Estudiante:

Docente: Ing.

Cochabamba 12 de Mayo del 2020

Gestión I – 2020

PRACTICA DE METODOS NUMERICOS


4.- Integre la función siguiente en forma analítica y con el empleo de la regla del
trapecio mediante el programa, con n=1, 2, 3 y 4: ∫ (𝑥 + 4 /𝑥 ) ^2 𝑑x Ls:4;Li:2

syms x y
f=input('funcion a integrar: ');
a=input('lim sup a: ');
b=input('lim sup b: ');
n=input('paso n: ');
fx0=subs(f,x,a)
fxn=subs(f,x,b)
h=(b-a)/n
f1=subs(f,x,a+h)
I1=(h/2)*(fx0+2*f1+fxn);
I=eval(I1);

funcion a integrar: (x+4/x)^2


lim sup a: 4
lim sup b: 2
paso n: 1
fx0 =25
fxn =16
h = -2
f1 =16

funcion a integrar: (x+4/x)^2


lim sup a: 4
lim sup b: 2
paso n: 2
fx0 =25
fxn =16
h = -1
f1 =169/9
>>
funcion a integrar: (x+4/x)^2
lim sup a: 4
lim sup b: 2
paso n: 3
fx0 =25
fxn =16
h = -0.6667
f1 =4624/225
>>
funcion a integrar: (x+4/x)^2
lim sup a: 4
lim sup b: 2
paso n: 4
fx0 =25

fxn =16
h = -0.5000
f1 =4225/196
>>

5.- Integre la función siguiente tanto en forma analítica como numérica. Emplee las
reglas de trapecio y Simpson 1/3 para integrar numéricamente la función mediante el
programa. Para ambos casos, utilice la versión de aplicación múltiple, con n=4. Calcule
los errores relativos porcentuales para los resultados numéricos.
 SERIES DE TAYLOR
1.
function taylorerror
format rat
f1=input('ingrese f1=','s');
X1=input('ingrese X1=');
n=input('ingrese n=');
Xa=input('ingrese Xa=');
f=inline(f1)
Y1=f(X1)
P=0
P=Y1
syms x
for i=1:1:n-1
df=diff(sym (f1),i)
f2=inline(df)
P=P+((f2(X1)/factorial(i))*(x-X1)^i)
end
r1=f(Xa)
f3=inline(P)
r2=f3(Xa)
e=abs(r1-r2)
disp('el resultado es=')
disp(P)
P1=expand(P)
disp('el error es=')
disp(e)

>> taylorerror
ingrese f1=(exp(x))/2
ingrese X1=0
ingrese n=4
ingrese Xa=0.3

f =

Inline function:
f(x) = (exp(x))/2
Y1 =

1/2

P =

P =

1/2

df =

exp(x)/2
f2 =

Inline function:
f2(x) = exp(x).*(1.0./2.0)

P =

x/2 + 1/2

df =

exp(x)/2

f2 =

Inline function:
f2(x) = exp(x).*(1.0./2.0)

P =

x^2/4 + x/2 + 1/2

df =

exp(x)/2

f2 =

Inline function:
f2(x) = exp(x).*(1.0./2.0)

P =

x^3/12 + x^2/4 + x/2 + 1/2


r1 =

1198/1775

f3 =

Inline function:
f3(x) =
x.*(1.0./2.0)+x.^2.*(1.0./4.0)+x.^3.*(1.0./1.2e1)+1.0./2.0

r2 =

473/701

e =
55/306571
el resultado es=
x^3/12 + x^2/4 + x/2 + 1/2

P1 =

x^3/12 + x^2/4 + x/2 + 1/2

el error es=
55/306571

>> x=-1:0.1:3;
>> f=(exp(x))/2;
>> f1=(exp(0))/2;
>> f2=x/2 + 1/2;
>> f3=x.^2/4 + x/2 + 1/2;
>> f4=x.^3/12 + x.^2/4 + x/2 + 1/2;
>> plot(x,f,'g',x,f1,'r',x,f2,'b',x,f3,'k',x,f4,'m')
12

10

0
-1 -0.5 0 0.5 1 1.5 2 2.5 3

2.
function taylorerror
format short
f1=input('ingrese f1=','s');
X1=input('ingrese X1=');
n=input('ingrese n=');
Xa=input('ingrese Xa=');
f=inline(f1)
Y1=f(X1)
P=0;
P=Y1
syms x
for i=1:1:n-1
df=diff(sym (f1),i)
f2=inline(df)
P=P+((f2(X1)/factorial(i))*(x-X1)^i)
end
r1=f(Xa)
f3=inline(P)
r2=f3(Xa)
e=abs(r1-r2)
disp('el resultado es=')
disp(P)
P1=expand(P)
disp('el error es=')
disp(e)

>> taylorerror
ingrese f1=5*log(x+3)
ingrese X1=-2
ingrese n=3
ingrese Xa=-1.6

f =

Inline function:
f(x) = 5*log(x+3)
Y1 =

P =

df =

5/(x + 3)

f2 =

Inline function:
f2(x) = 5.0./(x+3.0)

P =

5*x + 10

df =

-5/(x + 3)^2

f2 =

Inline function:
f2(x) = 1.0./(x+3.0).^2.*-5.0

P =

5*x - (5*(x + 2)^2)/2 + 10

r1 =

1.6824

f3 =

Inline function:
f3(x) = x.*5.0-(x+2.0).^2.*(5.0./2.0)+1.0e1

r2 =

1.6000

e =

0.0824
el resultado es=
5*x - (5*(x + 2)^2)/2 + 10

P1 =

- 5*x - (5*x^2)/2

el error es=
0.0824

>> x=-2.5:0.1:1;
>> f=5*log(x+3);
>> f1=5*log(-2+3);
>> f2=5*x + 10;
>> f3=5*x - (5*(x + 2).^2)/2 + 10;
>> plot(x,f,'g',x,f1,'r',x,f2,'b',x,f3,'k')

15

10

-5

-10
-2.5 -2 -1.5 -1 -0.5 0 0.5 1

3.
function taylorerror
format rat
f1=input('ingrese f1=','s');
X1=input('ingrese X1=');
n=input('ingrese n=');
Xa=input('ingrese Xa=');
f=inline(f1)
Y1=f(X1)
P=0;
P=Y1
syms x
for i=1:1:n-1
df=diff(sym (f1),i)
f2=inline(df)
P=P+((f2(X1)/factorial(i))*(x-X1)^i)
end
r1=f(Xa)
f3=inline(P)
r2=f3(Xa)
e=abs(r1-r2)
disp('el resultado es=')
disp(P)
P1=expand(P)
disp('el error es=')
disp(e)

>> taylorerror
ingrese f1=sqrt(x-1)
ingrese X1=2
ingrese n=4
ingrese Xa=2.4

f =

Inline function:
f(x) = sqrt(x-1)

Y1 =

P =

df =

1/(2*(x - 1)^(1/2))

f2 =

Inline function:
f2(x) = 1.0./sqrt(x-1.0).*(1.0./2.0)

P =

x/2

df =

-1/(4*(x - 1)^(3/2))

f2 =

Inline function:
f2(x) = 1.0./(x-1.0).^(3.0./2.0).*(-1.0./4.0)

P =

x/2 - (x - 2)^2/8

df =
3/(8*(x - 1)^(5/2))

f2 =

Inline function:
f2(x) = 1.0./(x-1.0).^(5.0./2.0).*(3.0./8.0)

P =

x/2 - (x - 2)^2/8 + (x - 2)^3/16

r1 =

846/715

f3 =

Inline function:
f3(x) = x.*(1.0./2.0)-(x-2.0).^2.*(1.0./8.0)+(x-
2.0).^3.*(1.0./1.6e1)

r2 =

148/125

e =

25/31886

el resultado es=
x/2 - (x - 2)^2/8 + (x - 2)^3/16

P1 =

x^3/16 - x^2/2 + (7*x)/4 - 1

el error es=
25/31886

>> x=1:0.1:5;
>> f=sqrt(x-1);
>> f1=sqrt(2-1);
>> f2=x/2;
>> f3=x/2 - (x - 2).^2/8;
>> f4=x/2 - (x - 2).^2/8 + (x - 2).^3/16;
>> plot(x,f,'g',x,f1,'r',x,f2,'b',x,f3,'k',x,f4,'m')

3.5

2.5

1.5

0.5

0
1 1.5 2 2.5 3 3.5 4 4.5 5

4.
function taylorerror
format rat
f1=input('ingrese f1=','s');
X1=input('ingrese X1=');
n=input('ingrese n=');
Xa=input('ingrese Xa=');
f=inline(f1)
Y1=f(X1)
P=0;
P=Y1
syms x
for i=1:1:n-1
df=diff(sym (f1),i)
f2=inline(df)
P=P+((f2(X1)/factorial(i))*(x-X1)^i)
end
r1=f(Xa)
f3=inline(P)
r2=f3(Xa)
e=abs(r1-r2)
disp('el resultado es=')
disp(P)
P1=expand(P)
disp('el error es=')
disp(e)

>> taylorerror
ingrese f1=x^3+x+1
ingrese X1=1
ingrese n=4
ingrese Xa=1.3

f =

Inline function:
f(x) = x^3+x+1

Y1 =

P =

df =

3*x^2 + 1

f2 =

Inline function:
f2(x) = x.^2.*3.0+1.0

P =

4*x - 1

df =

6*x

f2 =

Inline function:
f2(x) = x.*6.0

P =

4*x + 3*(x - 1)^2 - 1

df =

f2 =

Inline function:
f2(x) = 6.0

P =

4*x + 3*(x - 1)^2 + (x - 1)^3 - 1

r1 =
4497/1000

f3 =

Inline function:
f3(x) = x.*4.0+(x-1.0).^2.*3.0+(x-1.0).^3-1.0

r2 =

4497/1000

e =

1/1125899906842624

el resultado es=
4*x + 3*(x - 1)^2 + (x - 1)^3 - 1

P1 =

x^3 + x + 1

el error es=
1/1125899906842624

>> x=0:0.1:3;
>> f=x.^3+x+1;
>> f1=1^3+1+1;
>> f2=4*x - 1;
>> f3=4*x + 3*(x - 1).^2 - 1;
>> f4=4*x + 3*(x - 1).^2 + (x - 1).^3 - 1;
>> plot(x,f,'g',x,f1,'r',x,f2,'b',x,f3,'k',x,f4,'m')

35

30

25

20

15

10

-5
0 0.5 1 1.5 2 2.5 3

5.
function taylorerror
format rat
f1=input('ingrese f1=','s');
X1=input('ingrese X1=');
n=input('ingrese n=');
Xa=input('ingrese Xa=');
f=inline(f1)
Y1=f(X1)
P=0;
P=Y1
syms x
for i=1:1:n-1
df=diff(sym (f1),i)
f2=inline(df)
P=P+((f2(X1)/factorial(i))*(x-X1)^i)
end
r1=f(Xa)
f3=inline(P)
r2=f3(Xa)
e=abs(r1-r2)
disp('el resultado es=')
disp(P)
P1=expand(P)
disp('el error es=')
disp(e)

>> taylorerror
ingrese f1=sin(x)+2
ingrese X1=pi/2
ingrese n=4
ingrese Xa=4*pi/7

f =

Inline function:
f(x) = sin(x)+2

Y1 =

P =

df =

cos(x)

f2 =

Inline function:
f2(x) = cos(x)

P =

(4967757600021511*x)/81129638414606681695789005144064 -
(4967757600021511*pi)/162259276829213363391578010288128 + 3

df =

-sin(x)
f2 =

Inline function:
f2(x) = -sin(x)

P =

(4967757600021511*x)/81129638414606681695789005144064 -
(4967757600021511*pi)/162259276829213363391578010288128 - (x -
pi/2)^2/2 + 3

df =

-cos(x)

f2 =

Inline function:
f2(x) = -cos(x)

P =

(4967757600021511*x)/81129638414606681695789005144064 -
(4967757600021511*pi)/162259276829213363391578010288128 - (x -
pi/2)^2/2 - (6623676800028681*(x -
pi/2)^3)/649037107316853453566312041152512 + 3

r1 =

1068/359

f3 =

Inline function:
f3(x) = x.*6.123233995736766e-17-pi.*3.061616997868383e-17-(x-
pi.*(1.0./2.0)).^2.*(1.0./2.0)-(x-
pi.*(1.0./2.0)).^3.*1.020538999289461e-17+3.0

r2 =

827/278

e =

34/322353

el resultado es=
(4967757600021511*x)/81129638414606681695789005144064 -
(4967757600021511*pi)/162259276829213363391578010288128 - (x -
pi/2)^2/2 - (6623676800028681*(x -
pi/2)^3)/649037107316853453566312041152512 + 3

P1 =

(4967757600021511*x)/81129638414606681695789005144064 -
(4967757600021511*pi)/162259276829213363391578010288128 + (pi*x)/2 -
(19871030400086043*x*pi^2)/2596148429267413814265248164610048 +
(19871030400086043*pi*x^2)/1298074214633706907132624082305024 - pi^2/8
+ (6623676800028681*pi^3)/5192296858534827628530496329220096 - x^2/2 -
(6623676800028681*x^3)/649037107316853453566312041152512 + 3

el error es=
34/322353

>> x=0:0.1:pi;
>> f=sin(x)+2;
>> f1=sin(pi/2)+2;
>> f2=(4967757600021511*x)/81129638414606681695789005144064 -
(4967757600021511*pi)/162259276829213363391578010288128 + 3;
>> f3=(4967757600021511*x)/81129638414606681695789005144064 -
(4967757600021511*pi)/162259276829213363391578010288128 - (x -
pi/2).^2/2 + 3;
>> f4=(4967757600021511*x)/81129638414606681695789005144064 -
(4967757600021511*pi)/162259276829213363391578010288128 - (x -
pi/2).^2/2 - (6623676800028681*(x -
pi/2).^3)/649037107316853453566312041152512 + 3;
>> plot(x,f,'g',x,f1,'r',x,f2,'b',x,f3,'k',x,f4,'m')

2.8

2.6

2.4

2.2

1.8

1.6
0 0.5 1 1.5 2 2.5 3 3.5

6.
function taylorerror
format rat
f1=input('ingrese f1=','s');
X1=input('ingrese X1=');
n=input('ingrese n=');
Xa=input('ingrese Xa=');
f=inline(f1)
Y1=f(X1)
P=0;
P=Y1
syms x
for i=1:1:n-1
df=diff(sym (f1),i)
f2=inline(df)
P=P+((f2(X1)/factorial(i))*(x-X1)^i)
end
r1=f(Xa)
f3=inline(P)
r2=f3(Xa)
e=abs(r1-r2)
disp('el resultado es=')
disp(P)
P1=expand(P)
disp('el error es=')
disp(e)

>> taylorerror
ingrese f1=cos(x)+1
ingrese X1=0
ingrese n=3
ingrese Xa=pi/12

f =

Inline function:
f(x) = cos(x)+1

Y1 =

P =

2
df =

-sin(x)

f2 =

Inline function:
f2(x) = -sin(x)

P =

df =

-cos(x)

f2 =
Inline function:
f2(x) = -cos(x)

P =

2 - x^2/2

r1 =

1327/675

f3 =

Inline function:
f3(x) = x.^2.*(-1.0./2.0)+2.0

r2 =

631/321

e =

13/66569

el resultado es=
2 - x^2/2

P1 =

2 - x^2/2

el error es=
13/66569

>> x=0:0.1:pi/2;
>> f=cos(x)+1;
>> f1=cos(0)+1;
>> f2=2;
>> f3=2 - x.^2/2;
>> plot(x,f,'g',x,f1,'r',x,f2,'b',x,f3,'k')
2

1.8

1.6

1.4

1.2

0.8
0 0.5 1 1.5

 PROBLEMAS DE OPTIMIZACION (MAXIMOS Y MINIMOS)


1.
function max
f1=input('ingrese f(x)=','s');
a=input('ingresar limite inferior intervalo:')
b=input('ingresar limite superior intervalo:')
syms x
df=diff(sym(f1),x)
X=solve(df,x)
f=inline(f1)
ddf=diff(sym(df),x)
f5=inline(ddf)
n=length(X)
for i=1:1:n
if f5(X(i))<0
disp('el punto')
disp([X(i),f(X(i))])
disp('maximo')
end
if f5(X(i))>0
disp('el punto')
disp([X(i),f(X(i))])
disp('minimo')
end
if f5(X(i))==0
disp('el punto')
disp([X(i),f(X(i))])
disp('igual')
end
end
x1=a:0.1:b;
y1=subs(f1,x,x1);
plot(x1,y1)

>> max
ingrese f(x)=x^2-4*x+5
f1 =

x^2-4*x+5

ingresar limite inferior intervalo:0

a =

ingresar limite superior intervalo:3

b =

df =

2*x - 4

X =

f =

Inline function:
f(x) = x^2-4*x+5

ddf =

f5 =

Inline function:
f5(x) = 2.0

n =

el punto
[ 2, 1]

Minimo
5

4.5

3.5

2.5

1.5

1
0 0.5 1 1.5 2 2.5 3

2.
function max
f1=input('ingrese f(x)=','s');
a=input('ingresar limite inferior intervalo:')
b=input('ingresar limite superior intervalo:')
syms x
df=diff(sym(f1),x)
X=solve(df,x)
f=inline(f1)
ddf=diff(sym(df),x)
f5=inline(ddf)
n=length(X)
for i=1:1:n
if f5(X(i))<0
disp('el punto')
disp([X(i),f(X(i))])
disp('maximo')
end
if f5(X(i))>0
disp('el punto')
disp([X(i),f(X(i))])
disp('minimo')
end
if f5(X(i))==0
disp('el punto')
disp([X(i),f(X(i))])
disp('igual')
end
end
x1=a:0.1:b;
y1=subs(f1,x,x1);
plot(x1,y1)

>> max
ingrese f(x)=x^4-4*x^2
ingresar limite inferior intervalo:-0.5

a =

-0.5000

ingresar limite superior intervalo:2

b =
2

df =

4*x^3 - 8*x

X =

0
2^(1/2)
-2^(1/2)

f =

Inline function:
f(x) = x^4-4*x^2

ddf =

12*x^2 - 8

f5 =

Inline function:
f5(x) = x.^2.*1.2e1-8.0

n =

el punto
[ 0, 0]

maximo
el punto
[ 2^(1/2), -4]

minimo
el punto
[ -2^(1/2), -4]

Minimo
0

-0.5

-1

-1.5

-2

-2.5

-3

-3.5

-4
-0.5 0 0.5 1 1.5 2

3.
function max
f1=input('ingrese f(x)=','s');
a=input('ingresar limite inferior intervalo:')
b=input('ingresar limite superior intervalo:')
syms x
df=diff(sym(f1),x)
X=solve(df,x)
f=inline(f1)
ddf=diff(sym(df),x)
f5=inline(ddf)
n=length(X)
for i=1:1:n
if f5(X(i))<0
disp('el punto')
disp([X(i),f(X(i))])
disp('maximo')
end
if f5(X(i))>0
disp('el punto')
disp([X(i),f(X(i))])
disp('minimo')
end
if f5(X(i))==0
disp('el punto')
disp([X(i),f(X(i))])
disp('igual')
end
end
x1=a:0.1:b;
y1=subs(f1,x,x1);
plot(x1,y1)

>> max
ingrese f(x)=((x-1)^2)^1/3
ingresar limite inferior intervalo:-2

a =

-2

ingresar limite superior intervalo:4


b =

df =

(2*x)/3 - 2/3

X =

f =

Inline function:
f(x) = ((x-1)^2)^1/3

ddf =

2/3

f5 =

Inline function:
f5(x) = 2.0./3.0

n =

el punto
[ 1, 0]

Minimo

2.5

1.5

0.5

0
-2 -1 0 1 2 3 4

4.
function max
f1=input('ingrese f(x)=','s');
a=input('ingresar limite inferior intervalo:')
b=input('ingresar limite superior intervalo:')
syms x
df=diff(sym(f1),x)
X=solve(df,x)
f=inline(f1)
ddf=diff(sym(df),x)
f5=inline(ddf)
n=length(X)
for i=1:1:n
if f5(X(i))<0
disp('el punto')
disp([X(i),f(X(i))])
disp('maximo')
end
if f5(X(i))>0
disp('el punto')
disp([X(i),f(X(i))])
disp('minimo')
end
if f5(X(i))==0
disp('el punto')
disp([X(i),f(X(i))])
disp('igual')
end
end
x1=a:0.1:b;
y1=subs(f1,x,x1);
plot(x1,y1)

>> max
ingrese f(x)=x*exp(x)
ingresar limite inferior intervalo:-2

a =

-2

ingresar limite superior intervalo:1

b =

df =

exp(x) + x*exp(x)

X =

-1

f =

Inline function:
f(x) = x*exp(x)
ddf =

2*exp(x) + x*exp(x)

f5 =

Inline function:
f5(x) = exp(x).*2.0+x.*exp(x)

n =

el punto
[ -1, -exp(-1)]

Minimo

2.5

1.5

0.5

-0.5
-2 -1.5 -1 -0.5 0 0.5 1

5. Tiene cúspide no se puede determinar los máximos y minimos

6.
function max
f1=input('ingrese f(x)=','s');
a=input('ingresar limite inferior intervalo:')
b=input('ingresar limite superior intervalo:')
syms x
df=diff(sym(f1),x)
X=solve(df,x)
f=inline(f1)
ddf=diff(sym(df),x)
f5=inline(ddf)
n=length(X)
for i=1:1:n
if f5(X(i))<0
disp('el punto')
disp([X(i),f(X(i))])
disp('maximo')
end
if f5(X(i))>0
disp('el punto')
disp([X(i),f(X(i))])
disp('minimo')
end
if f5(X(i))==0
disp('el punto')
disp([X(i),f(X(i))])
disp('igual')
end
end
x1=a:0.1:b;
y1=subs(f1,x,x1);
plot(x1,y1)

>> max
ingrese f(x)=(4*x)/(x^2+4)
ingresar limite inferior intervalo:-3

a =

-3

ingresar limite superior intervalo:3

b =

df =

4/(x^2 + 4) - (8*x^2)/(x^2 + 4)^2

X =

-2
2

f =

Inline function:
f(x) = (4*x)/(x^2+4)

ddf =

(32*x^3)/(x^2 + 4)^3 - (24*x)/(x^2 + 4)^2

f5 =

Inline function:
f5(x) =
x.*1.0./(x.^2+4.0).^2.*-2.4e1+x.^3.*1.0./(x.^2+4.0).^3.*3.2e1

n =
2

el punto
[ -2, -1]

minimo
el punto
[ 2, 1]

Máximo

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
-3 -2 -1 0 1 2 3

También podría gustarte