Diferencia entre revisiones de «Logística con umbral A7»
De MateWiki
(Página creada con «{{ TrabajoED | Logística con umbral A-7 | Ecuaciones Diferenciales|Curso 2014-15 | Bautista Mendo, Jorge ...») |
|||
| Línea 9: | Línea 9: | ||
Domínguez Trufero, Miguel }} | Domínguez Trufero, Miguel }} | ||
| + | == PVI == | ||
| + | {{matlab|codigo= | ||
| + | clear all | ||
| + | %DATOS DEL PROBLEMA | ||
| + | t0=0;tN=100; %tiempos inicial y final | ||
| + | y0=60; %condición inicial | ||
| + | %El tamaño de paso lo haremos con h=1,0.1,0.01 | ||
| + | h=input('Introduce tamaño de paso:'); %Tamaño de paso | ||
| + | N=(tN-t0)/h; %discretización | ||
| + | r=0.04;m1=30;m2=100; %constantes de la ecuación | ||
| + | t=t0:h:tN; %vector de tiempos | ||
| + | %Vector y su condición inicial en cada metodo | ||
| + | y=zeros(1,N+1); y(1)=y0; %Runge-Kutta | ||
| + | z=zeros(1,N+1);z(1)=y0; %Euler | ||
| + | he=zeros(1,N+1);he(1)=y0; %Heun | ||
| + | for i=1:N | ||
| + | %Método Runge-Kutta: | ||
| + | K1=-r*y(i)*(1-y(i)/m1)*(1-y(i)/m2); | ||
| + | K2=-r*(y(i)+1/2*K1*h)*(1-((y(i)+1/2*K1*h)/m1))*(1-((y(i)+1/2*K1*h)/m2)); | ||
| + | K3=-r*(y(i)+1/2*K2*h)*(1-((y(i)+1/2*K2*h)/m1))*(1-((y(i)+1/2*K2*h)/m2)); | ||
| + | K4=-r*(y(i)+K3*h)*(1-((y(i)+K3*h)/m1))*(1-((y(i)+K3*h)/m2)); | ||
| + | y(i+1)= y(i)+h/6*(K1+2*K2+2*K3+K4); | ||
| + | %Método Euler: | ||
| + | z(i+1)=z(i)+h*(-r*(z(i)+1/2*K1*h)*(1-(z(i)+1/2*K1*h)/m1)*(1-(z(i)+1/2*K1*h)/m2)); | ||
| + | %Método de Heun: | ||
| + | Kh1=-r*he(i)*(1-he(i)/m1)*(1-he(i)/m2); | ||
| + | Kh2=-r*(he(i)+Kh1*h)*(1-((he(i)+Kh1*h)/m1))*(1-((he(i)+Kh1*h)/m2)); | ||
| + | he(i+1)= he(i)+h/2*(Kh1+Kh2); | ||
| + | end | ||
| + | %Dibujamos las distintas gráficas: | ||
| + | subplot(3,1,1); | ||
| + | plot(t,y,'b','linewidth',2) | ||
| + | legend('RUNGE-KUTTA','location','best') | ||
| + | subplot(3,1,2); | ||
| + | plot(t,z,'r','linewidth',2) | ||
| + | legend('EULER','location','best') | ||
| + | subplot(3,1,3); | ||
| + | plot(t,he,'g','linewidth',2) | ||
| + | legend('HEUN','location','best') | ||
| + | %Cálculo errores | ||
| + | C1=max(abs(y-z)) %error entre Runge-Kutta y Euler | ||
| + | C2=max(abs(z-he)) %error entre Euler y Heun | ||
| + | C3=max(abs(he-y)) %error entre Heun y Runge-Kutta | ||
| + | }} | ||
| − | + | Paso 0.1 | |
| − | + | [[Archivo:Paso 0.1.jpg]] | |
| − | + | ||
[[Categoría:Ecuaciones Diferentiales]] | [[Categoría:Ecuaciones Diferentiales]] | ||
[[Categoría:ED14/15]] | [[Categoría:ED14/15]] | ||
[[Categoría:Trabajos 2014-15]] | [[Categoría:Trabajos 2014-15]] | ||
Revisión del 13:16 25 feb 2015
| Trabajo realizado por estudiantes | |
|---|---|
| Título | Logística con umbral A-7 |
| Asignatura | Ecuaciones Diferenciales |
| Curso | Curso 2014-15 |
| Autores | Bautista Mendo, Jorge
Casanova Lozano, Javier Chueca Rincón, Jaime Crespo Ferrer, Enrique Domínguez Trufero, Miguel |
| Este artículo ha sido escrito por estudiantes como parte de su evaluación en la asignatura | |
PVI
clear all
%DATOS DEL PROBLEMA
t0=0;tN=100; %tiempos inicial y final
y0=60; %condición inicial
%El tamaño de paso lo haremos con h=1,0.1,0.01
h=input('Introduce tamaño de paso:'); %Tamaño de paso
N=(tN-t0)/h; %discretización
r=0.04;m1=30;m2=100; %constantes de la ecuación
t=t0:h:tN; %vector de tiempos
%Vector y su condición inicial en cada metodo
y=zeros(1,N+1); y(1)=y0; %Runge-Kutta
z=zeros(1,N+1);z(1)=y0; %Euler
he=zeros(1,N+1);he(1)=y0; %Heun
for i=1:N
%Método Runge-Kutta:
K1=-r*y(i)*(1-y(i)/m1)*(1-y(i)/m2);
K2=-r*(y(i)+1/2*K1*h)*(1-((y(i)+1/2*K1*h)/m1))*(1-((y(i)+1/2*K1*h)/m2));
K3=-r*(y(i)+1/2*K2*h)*(1-((y(i)+1/2*K2*h)/m1))*(1-((y(i)+1/2*K2*h)/m2));
K4=-r*(y(i)+K3*h)*(1-((y(i)+K3*h)/m1))*(1-((y(i)+K3*h)/m2));
y(i+1)= y(i)+h/6*(K1+2*K2+2*K3+K4);
%Método Euler:
z(i+1)=z(i)+h*(-r*(z(i)+1/2*K1*h)*(1-(z(i)+1/2*K1*h)/m1)*(1-(z(i)+1/2*K1*h)/m2));
%Método de Heun:
Kh1=-r*he(i)*(1-he(i)/m1)*(1-he(i)/m2);
Kh2=-r*(he(i)+Kh1*h)*(1-((he(i)+Kh1*h)/m1))*(1-((he(i)+Kh1*h)/m2));
he(i+1)= he(i)+h/2*(Kh1+Kh2);
end
%Dibujamos las distintas gráficas:
subplot(3,1,1);
plot(t,y,'b','linewidth',2)
legend('RUNGE-KUTTA','location','best')
subplot(3,1,2);
plot(t,z,'r','linewidth',2)
legend('EULER','location','best')
subplot(3,1,3);
plot(t,he,'g','linewidth',2)
legend('HEUN','location','best')
%Cálculo errores
C1=max(abs(y-z)) %error entre Runge-Kutta y Euler
C2=max(abs(z-he)) %error entre Euler y Heun
C3=max(abs(he-y)) %error entre Heun y Runge-Kutta
Paso 0.1
Archivo:Paso 0.1.jpg