10.05.2013 Views

texto: metodos numericos para ecuaciones diferenciales ordinarias

texto: metodos numericos para ecuaciones diferenciales ordinarias

texto: metodos numericos para ecuaciones diferenciales ordinarias

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.4.1. Algoritmo del Método de Runge-Kutta de Cuarto Orden<br />

Este algoritmo calcula la solución del problema de valor inicial (1.1) en puntos<br />

equidistantes x1 = x0 + h ,x2 = x0 + 2h, x3 = x0 + 3h, · · · ,xN = x0 + Nh, aquí f es<br />

tal que (1.1) tiene una solución única en [x0,xN].<br />

1. Entrada: Valores iniciales x0,y0, tamaño de paso h y número de pasos N<br />

2. Para n=0,...,N-1, hacer<br />

3. Parar<br />

k1 = hf(xn,yn)<br />

k2 = hf(xn + 1<br />

2 h,yn + 1<br />

2 k1)<br />

k3 = hf(xn + 1<br />

2 h,yn + 1<br />

2 k2)<br />

k4 = hf(xn + h,yn + k3)<br />

yn+1 = yn + 1<br />

6 (k1 + 2k2 + 2k3 + k4)<br />

Salida xn+1, yn+1<br />

3.4.2. Programa del Método de Runge-Kutta de Cuarto Orden<br />

function y=rungekutta(n,a,b,h)<br />

format long<br />

x=a:h:b;<br />

y=zeros(n,1);<br />

y(1)=0;<br />

for k=1:n<br />

end<br />

k1=h*fe(x(k),y(k))<br />

k2=h*fe(x(k)+0.5*h,y(k)+0.5*k1)<br />

k3=h*fe(x(k)+0.5*h,y(k)+0.5*k2)<br />

k4=h*fe(x(k)+h,y(k)+k3)<br />

y(k+1)=y(k)+(1/6)*(k1+2*k2+2*k3+k4);<br />

function y1=fe(x,y)<br />

y1=x*exp(3*x)-2*y;<br />

24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!