Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
utilice el método de Euler para aproximar y(2.3) tomando h = 0.1 en cada paso del proceso
iterativo.
CÓDIGO:
close all
clear all
clc
f=inline('sqrt(x^2+y^2)');
%ANALITICAMENTE
x0=2;
xf=2.3;
h=0.1;
y0=0.5;
y=y0;
k=1;
for x=x0:h:xf
x_runge(k)=x;
y_runge(k)=y;
k1=f(x,y);
k2=f(x+h/2,y+k1*h/2);
k3=f(x+h/2,y+k2*h/2);
k4=f(x+h,y+k3*h);
y=y+(h/6)*(k1+2*k2+2*k3+k4);
k=k+1;
end
%Euler
y=y0;
j=1;
for x=x0:h:xf
x_euler(j)=x;
y_euler(j)=y;
y=y+h*f(x,y);
j=j+1;
end
disp('x_runge')
disp(x_runge)
disp('y_runge')
disp(y_runge)
disp('x_euler')
disp(x_euler)
disp('y_euler')
disp(y_euler)
%PARA GRAFICAR
figure(1)
plot(x_runge,y_runge,'k')
hold on
plot(x_euler,y_euler,'b')
title('Eejercicio no.1')
legend('Runge-Kutta','Euler')
grid
RESULTADO:
x_runge
y_runge
x_euler
y_euler
utilice el método de Euler para aproximar y(1.3) tomando h = 0.1 en cada paso del proceso
iterativo.
CÓDIGO:
close all
clear all
clc
f=inline('log(x+y)');
%ANALITICAMENTE
x0=1;
xf=1.3;
h=0.1;
y0=1.5;
y=y0;
k=1;
for x=x0:h:xf
x_runge(k)=x;
y_runge(k)=y;
k1=f(x,y);
k2=f(x+h/2,y+k1*h/2);
k3=f(x+h/2,y+k2*h/2);
k4=f(x+h,y+k3*h);
y=y+(h/6)*(k1+2*k2+2*k3+k4);
k=k+1;
end
%Euler
y=y0;
j=1;
for x=x0:h:xf
x_euler(j)=x;
y_euler(j)=y;
y=y+h*f(x,y);
j=j+1;
end
disp('x_runge')
disp(x_runge)
disp('y_runge')
disp(y_runge)
disp('x_euler')
disp(x_euler)
disp('y_euler')
disp(y_euler)
%PARA GRAFICAR
figure(1)
plot(x_runge,y_runge,'k')
hold on
plot(x_euler,y_euler,'b')
title('Eejercicio no.2')
legend('Runge-Kutta','Euler')
grid
RESULTADO:
x_runge
y_runge
1.5000 1.5954 1.6982 1.8081
x_euler
y_euler
3. Si se drena el agua desde un tanque cilíndrico vertical por medio de abrir una
válvula en la base, el líquido fluirá rápido cuando el tanque este lleno y despacio
conforme se drene. Consecuencia de la Ley de Torricelli, la tasa a la que el nivel del
agua disminuye es:
donde k es una constante que depende de la forma del agujero, del área de la sección
transversa del tanque y del área de la sección transversal del agujero de drenaje. La
profundidad del agua y se mide en metros y el tiempo t en minutos. Si k = 0.06, determine
cuánto tiempo se requiera para vaciar el tanque si el nivel del fluido se encuentra en un
inicio a 3 m. Resuelva con la aplicación de la ecuación de Euler. Utilice un paso de 0.5
minutos.
CÓDIGO:
close all
clear all
clc
k=0.06;
y=3;
t=0;
while y>0
y=y+(-k*sqrt(y))*0.5;
t=t+0.5;
end
disp('Tiempo en minutos')
disp(t-0.5);
RESULTADO:
Tiempo en minutos
56
CÓDIGO:
clear all
close all
clc
y=1;
x0=0;
xf=2;
h1=0.5;
y1=0;
y2=0;
for i=x0:h1:xf-h1
x=i;
fxy=y*(x^2)-1.1*y;
y1=y1+fxy*h1
end
h2=0.25;
for i=x0:h2:xf-h2
x=i;
fxy=y*(x^2)-1.1*y;
y2=y2+fxy*h2
end
[xx,yy]=meshgrid(2:1:2);
fxyy=yy.*(x.^2)-1.1.*yy;
surf(xx,yy,fxyy)
RESULTADO:
𝑑𝑦
= −2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5
𝑑𝑥
Con condición inicial y(0)=1, desde x=0 hasta x=4. Utilice los incrementos 0.5 y 0.01. Grafique
los resultados y compárelos contra la solución analítica.
CÓDIGO:
clear all
close all
clc
y=1;
x0=0;
xf=4;
h1=0.5;
y1=0;
y2=0;
for i=x0:h1:xf-h1
x=i;
fxy=-2*x^3+12*x^2-20*x+8.5;
y1=y1+fxy*h1
end
h2=0.01;
for i=x0:h2:xf-h2
x=i;
fxy=-2*x^3+12*x^2-20*x+8.5;
y2=y2+fxy*h2
end
RESULTADO:
6. Aplique la fórmula de Euler para hallar una aproximación al valor indicado con
cuatro decimales de precisión. Primero use h=0.1 y después h=0.05
𝑦
𝑦′ = 𝑥𝑦 2 +
𝑥
y(1)=1, y(1.5)
CÓDIGO:
clear all
close all
clc
y=1;
x0=1;
xf=1.5;
h1=0.1;
y1=0;
y2=0;
for i=x0:h1:xf-h1
x=i;
fxy=x*(y^2)+(y/x);
y1=y1+fxy*h1
end
h2=0.05;
for i=x0:h2:xf-h2
x=i;
fxy=x*(y^2)+(y/x);
y2=y2+fxy*h2
end
RESULTADO:
Con h=0.1:
y(1.5)=1.0226
Con h=0.05:
y(1.5)=1.0264