ecuaciones diferenciales ordinarias

1
function RK2_00 dy/dt+(1/2)y=(1/2)t y(0)=4 % y' = -(1/2)y + (1/2)t con y(0)=4 % yex= 6 e^(-t/2) - 2 + t clc,clear % Datos y0=4; % Valores Iniciales t0=0; Dt=0.01; % incremento de tiempo NDt=1000; % cantidad de Dt a realizar w=0.5; % w=0.5 es Euler Mejorado % % w=1 es Euler Modificado; % Dimensionamiento t=zeros(NDt,1); % vector para el tiempo y=zeros(NDt,1); % vector para solución y(t) % Inicialización del primer estado solución t(1)=t0; y(1)=y0; % Runge-Kutta 2do Orden for j=1:NDt-1 k1=Dt*(-(1/2)*y(j) + (1/2)*t(j)); yg = y(j) + k1/(2*w); tg = t(j) + Dt/(2*w); k2=Dt*(-(1/2)*yg + (1/2)*tg); y(j+1) = y(j)+(1-w)*k1+w*k2; t(j+1) = t(j)+Dt; end figure(1) plot(t,y(:,1),'b'); grid on end

Upload: abel-nina

Post on 14-Dec-2015

217 views

Category:

Documents


2 download

DESCRIPTION

programas de matlab (euler y runge kutta)

TRANSCRIPT

Page 1: ecuaciones diferenciales ordinarias

function RK2_00 dy/dt+(1/2)y=(1/2)t y(0)=4% y' = -(1/2)y + (1/2)t con y(0)=4% yex= 6 e^(-t/2) - 2 + tclc,clear% Datosy0=4; % Valores Inicialest0=0;Dt=0.01; % incremento de tiempoNDt=1000; % cantidad de Dt a realizarw=0.5; % w=0.5 es Euler Mejorado% % w=1 es Euler Modificado;% Dimensionamientot=zeros(NDt,1); % vector para el tiempoy=zeros(NDt,1); % vector para solución y(t)% Inicialización del primer estado soluciónt(1)=t0;y(1)=y0;% Runge-Kutta 2do Ordenfor j=1:NDt-1

k1=Dt*(-(1/2)*y(j) + (1/2)*t(j)); yg = y(j) + k1/(2*w); tg = t(j) + Dt/(2*w);k2=Dt*(-(1/2)*yg + (1/2)*tg);y(j+1) = y(j)+(1-w)*k1+w*k2;t(j+1) = t(j)+Dt;

endfigure(1)plot(t,y(:,1),'b');grid onend