Está en la página 1de 11

INSTITUTO POLITCNICO NACIONAL

UNIDAD PROFESIONAL INTERDISCIPLINARIA DE BIOTECNOLOGA

MTODOS NUMRICOS (TALLER)

GRUPO: 4AM1

TAREA 7

ECUACIONES DIFERENCIALES

REYES RODRGUEZ ALEJANDRO


RUIZ HERNNDEZ BRENDA ANGLICA

PROFESOR:
RAMREZ BARRIOS MIGUEL LUIS

MXICO D.F. A 09 DE JULIO DE 2015

EJERCICIO 1

( x 2+ 4 ) dy =2 x8 xy
dx

y(0)=1 en el intervalo [0,8]


Con h=0.01
t
0.1
1.5
5

Euler
0,991800709275664
0,372980400223570
0,250251754878624

Euler Modificada
0,990993291209243
0,373444493702320
0,250267858695072

Range
0,990993216665080
0,373434053823689
0,250267746193908

Euler Modificada
0,983358212356027
0,364525667846541
0,250256253463751

Range
0,983359660749962
0,364262358602156
0,250253435724293

Analtica
0,25001696764153
3

Con h=0.05
t
0.1
1.5
5

Euler
0,988808428647307
0,361688042229254
0,250182932384893

Analtica
0,25001665588821
7

%COMPARACIN DE LOS TRES MTODOS (ECUACIONES DIFERENCIALES)


function [xr xp1 xp2 xp3 tp1]=Tarea7Ej1
h=0.05;
ti=0 %Condicin Inicial
tf=8
x0=1 %Condicin Final
%Euler
x=x0;
i=1;
for t=ti:h:tf
x=x+h*f1(x,t);
xp1(i)=x;
tp1(i)=t;
i=i+1;
end
%Euler Modificado
x=x0;
i=1;
for t=ti:h:tf
x_aux=x+h*f1(x,t);
x=x+(h/2)*(f1(x,t)+f1(x_aux,t+h));
xp2(i)=x;
tp2(i)=t;
i=i+1;
end
%Range
x=x0;
i=1;
for t=ti:h:tf
k1=h*f1(x,t)
k2=h*f1(x+0.5*k1,t+0.5*h);
k3=h*f1(x+0.5*k2,t+0.5*h);
k4=h*f1(x+k3,t+h);
x=x+(1/6)*(k1+2*k2+2*k3+k4);
xp3(i)=x;
tp3(i)=t;
i=i+1;
end
tr=ti:h:tf;
xr=(tr.^8+16*tr.^6+96*tr.^4+256*tr.^2+1024)/(4*(tr.^2+4).^4);
%Agregar la Solucin de la Ecuacin
plot(tr,xr,'b');
hold on
plot(tp1,xp1,'k');
plot(tp2,xp2,'r');
plot(tp3,xp3,'g');
legend('Analitica','Euler','Euler Modificado','Range 4to
Orden')
end
function z=f1(x,t)
z=(2*t-8*t*x)/(t^2+4);
end

EJERCICIO 2

( e y +1 ) sin ( x ) dx=(1+ cos ( x ))dy


y(0)=0 en el intervalo [0,2]
Resolviendo para encontrar

dy
dx

se obtiene:

y
y
dy e ( e +1 ) sin ( x)
=
dx
cos ( x ) +1

La solucin de la Ecuacin Diferencial es:


log(4/(1+cos(x))-1)
Con h=0.01
t
0.1
1.5
2

Euler
0.0054959321372897
6
1.01411923748938
1.77799036217280

Euler Modificada
0.0060439524536017
0
1.00640902858382
1.78494564701490

Range
0.0060439204417539
1
1.01916684754578
1.78493129113507

Analtica
0,00549593213
7
1,014119237489
1,77799036217
2

Con h=0.05
t
0.1

Euler
0,0112313692524073

Euler Modificada
0,0112290404385123

1.5
2

1,07123257093886
1,86014425899998

1,07107499599563
1,85975318791075

Range
0,10000000000000
0
1,50000000000000
2

Analtica
0,007498443099846
3
1,04522601628948
1,82390319253633

%COMPARACIN DE LOS TRES MTODOS (ECUACIONES DIFERENCIALES)


function [xp1 xp2 xp3 tp1 tp2 tp3]=Tarea7Ej2
h=0.05;
ti=0 %Condicin Inicial
tf=2
x0=0 %Condicin Final
%Euler
x=x0;
i=1;
for t=ti:h:tf
x=x+h*f1(x,t);
xp1(i)=x;
tp1(i)=t;
i=i+1;
end
%Euler Modificado
x=x0;
i=1;
for t=ti:h:tf
x_aux=x+h*f1(x,t);
x=x+(h/2)*(f1(x,t)+f1(x_aux,t+h));
xp2(i)=x;
tp2(i)=t;
i=i+1;
end
%Range
x=x0;
i=1;
for t=ti:h:tf
k1=h*f1(x,t)
k2=h*f1(x+0.5*k1,t+0.5*h);
k3=h*f1(x+0.5*k2,t+0.5*h);
k4=h*f1(x+k3,t+h);
x=x+(1/6)*(k1+2*k2+2*k3+k4);
xp3(i)=x;
tp3(i)=t;
i=i+1;
end
tr=ti:h:tf;
xr=log(4./(1+cos(tr))-1); %Agregar la Solucin de la Ecuacin
plot(tr,xr,'b');
hold on
plot(tp1,xp1,'k');
plot(tp2,xp2,'r');
plot(tp3,xp3,'g');
legend('Analitica','Euler','Euler Modificado','Range 4to Orden')
end
function z=f1(x,t)
z=((exp(-x))*(exp(x)+1)*sin(t))/(cos(t)+1);
end

EJERCICIO 3
x 2 y ' = y xy
y(-1)=1 en el intervalo [-1,0]
Con h=0.01
t
-0.9
-0.5
0

Euler
-1.25060658969911
-3.33226509572109
NaN

Euler Modificada
-1.25422795089152
-3.39823319885161
NaN

Range
-1.25424502258329
-3.39855344722839
NaN

Analtica
-0.5197921531
-0.9356258755
Inf

Con h=0.05
t
Euler
-0.9
-1.34092251461988
-0.5
-3.47105999631867
0
NaN

Euler Modificada
-1.36625289507181
-3.84214736961781
NaN

Range
-1.36686344552321
-3.85166396113872
NaN

Analtica
-0.536694160
-0.966049489
Inf

%COMPARACIN DE LOS TRES MTODOS (ECUACIONES DIFERENCIALES)


function [xr xp1 xp2 xp3 tp1]=Tarea7Ej3
h=0.05;
ti=-1 %Condicin Inicial
tf=0
x0=-1 %Condicin Final
%Euler
x=x0;
i=1;
for t=ti:h:tf
x=x+h*f1(x,t);
xp1(i)=x;
tp1(i)=t;
i=i+1;
end
%Euler Modificado
x=x0;
i=1;
for t=ti:h:tf
x_aux=x+h*f1(x,t);
x=x+(h/2)*(f1(x,t)+f1(x_aux,t+h));
xp2(i)=x;
tp2(i)=t;
i=i+1;
end
%Range
x=x0;
i=1;
for t=ti:h:tf
k1=h*f1(x,t)
k2=h*f1(x+0.5*k1,t+0.5*h);
k3=h*f1(x+0.5*k2,t+0.5*h);
k4=h*f1(x+k3,t+h);
x=x+(1/6)*(k1+2*k2+2*k3+k4);
xp3(i)=x;
tp3(i)=t;
i=i+1;
end
tr=ti:h:tf;
xr=-1*(exp(tr+1)/tr*tr).^-1; %Agregar la Solucion
plot(tr,xr,'b');
hold on
plot(tp1,xp1,'k');
plot(tp2,xp2,'r');
plot(tp3,xp3,'g');
legend('Analitica','Euler','Euler Modificado','Range 4to Orden')
end
function z=f1(x,t)
z=x-t*x/t.^2;
end

EJERCICIO 4
dx
+5 x=20
dt
x(0)=2 en el intervalo [0,10]

Resolviendo para encontrar

dy
dx

se obtiene:

dy
=5( x4)
dx
La solucin de la Ecuacin Diferencial es:
x=

2
+4
e5 t

Con h=0.01
t
0.1

Euler
2,86239981544708

Euler Modificada
2,84582579677820

Range
2,84610034477739

1.5

3,99913444554848

3,99894433740829

3,99894777931439

3,99993339993413

3,99991325216971

3,99991362845474

4.00000000000000

3,99999941423206

3,99999941803295

4.00000000000000

3,99999999604458

3,99999999607874

4.00000000000000

3,99999999997329

3,99999999997358

10

4.00000000000000

4,00000000000000

4,00000000000000

Analtica
3,6967346701436
8
3,9997234578149
3
3,9999773000351
2
3,9999998470488
4
3,9999999989694
2
3,9999999999930
6
4

Con h=0.05
t
0.1

Euler
3,15625000000000

Euler Modificada
3,04632568359375

Range
3,05523846973665

1.5

3,99973212686475

3,99905044322542

3,99913824704077

3,99998491512226

3,99999942293884

3,99992925591492

3,99999995216266

3,99999942293884

3,99999952323448

3,99999999999952

3,99999999997030

3,99999999997835

Analtica
3,6967346701436
8
3,9997234578149
3
3,9999773000351
2
3,9999998470488
4
3,9999999999930

10

4,00000000000000

4,00000000000000

4,00000000000000

%COMPARACIN DE LOS TRES MTODOS (ECUACIONES DIFERENCIALES)


function [xr xp1 xp2 xp3 tp1]=Tarea7Ej4
h=0.05;
ti=0 %Condicin Inicial
tf=10
x0=2 %Condicin Final
%Euler
x=x0;
i=1;
for t=ti:h:tf
x=x+h*f1(x,t);
xp1(i)=x;
tp1(i)=t;
i=i+1;
end
%Euler Modificado
x=x0;
i=1;
for t=ti:h:tf
x_aux=x+h*f1(x,t);
x=x+(h/2)*(f1(x,t)+f1(x_aux,t+h));
xp2(i)=x;
tp2(i)=t;
i=i+1;
end
%Range
x=x0;
i=1;
for t=ti:h:tf
k1=h*f1(x,t)
k2=h*f1(x+0.5*k1,t+0.5*h);
k3=h*f1(x+0.5*k2,t+0.5*h);
k4=h*f1(x+k3,t+h);
x=x+(1/6)*(k1+2*k2+2*k3+k4);
xp3(i)=x;
tp3(i)=t;
i=i+1;
end
tr=ti:h:tf;
xr=((-2)*((exp(5*tr)))).^-1+4; %Agregar la Solucin de la Ecuacin
plot(tr,xr,'b');
hold on
plot(tp1,xp1,'k');
plot(tp2,xp2,'r');
plot(tp3,xp3,'g');
legend('Analitica','Euler','Euler Modificado','Range 4to Orden')
end
function z=f1(x,t)
z=-5*(x-4);
end

EJERCICIO 5

6
4

y ' + ( tanx ) y =cos2 x


y(0)=-1 en el intervalo [0,20]
Resolviendo para encontrar

dy
dx

se obtiene:

cos ( x)
dy
=
dx sec ( x ) y

La solucin de la Ecuacin Diferencial es:


y=cos ( x )(sin ( x )1)
Con h=0.01
t
Euler
0.1
-1.11524406587010
10
-184.346264626024
20
-25694.0426097533

Euler Modificada
-1.11578008619992
-187.760415963514
-26576.7900886176

Range
-1.11578412153690
-187.772465700306
-26579.7936076585

Analtica
0.0355254815737
1

Euler Modificada
-1.16039399139194
-192.605503563855
-26657.8109531612

Range
-1.16053377081663
-192.921041896281
-26734.2748052157

Analtica
0.0355254815737
1

Con h=0.05
t
0.1
10
20

Euler
-1.15693795270928
-176.342579835929
-22661.7570600621

%COMPARACIN DE LOS TRES MTODOS (ECUACIONES DIFERENCIALES)


function [xr xp1 xp2 xp3 tp1]=Tarea7Ej4
h=0.01;
ti=0 %Condicin Inicial
tf=20
x0=-1 %Condicin Final
%Euler
x=x0;
i=1;
for t=ti:h:tf
x=x+h*f1(x,t);
xp1(i)=x;
tp1(i)=t;
i=i+1;
end
%Euler Modificado
x=x0;
i=1;
for t=ti:h:tf
x_aux=x+h*f1(x,t);
x=x+(h/2)*(f1(x,t)+f1(x_aux,t+h));
xp2(i)=x;
tp2(i)=t;
i=i+1;
end
%Range
x=x0;
i=1;
for t=ti:h:tf
k1=h*f1(x,t)
k2=h*f1(x+0.5*k1,t+0.5*h);
k3=h*f1(x+0.5*k2,t+0.5*h);
k4=h*f1(x+k3,t+h);
x=x+(1/6)*(k1+2*k2+2*k3+k4);
xp3(i)=x;
tp3(i)=t;
i=i+1;
end
tr=ti:h:tf;
xr=cos(t)*(sin(t)-1); %Agregar la Solucion
plot(tr,xr,'b');
hold on
plot(tp1,xp1,'k');
plot(tp2,xp2,'r');
plot(tp3,xp3,'g');
legend('Analitica','Euler','Euler Modificado','Range 4to Orden')
end
function z=f1(x,t)
z=cos(t)/(1/cos(t))*x;
end

También podría gustarte