solution_hw12

# solution_hw12 - y(1,i+1)=y(1,i)+(k11+2*k21+2*k31+k41)*h/6;

This preview shows pages 1–4. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
function [f1 f2]=fun(x,y,z) f1=-2*y+5*exp(-x); f2=-y*z^2/2; function [y]=RungeKutta(fun,xint,yint,xfinal,h) x=xint:h:xfinal; y(1,1)=yint(1); y(2,1)=yint(2); n=length(x) for i=1:n-1 [k11 k12]=feval(fun,x(i),y(1,i),y(2,i)); [k21 k22]=feval(fun,x(i)+h/2,y(1,i)+k11*h/2,y(2,i)+k12*h/2); [k31 k32]=feval(fun,x(i)+h/2,y(1,i)+k21*h/2,y(2,i)+k22*h/2); [k41 k42]=feval(fun,x(i)+h/2,y(1,i)+k31*h,y(2,i)+k32*h);
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: y(1,i+1)=y(1,i)+(k11+2*k21+2*k31+k41)*h/6; y(2,i+1)=y(2,i)+(k12+2*k22+2*k32+k42)*h/6; end figure(1) plot(x,y(1,:), 'o-' ,x,y(2,:), '*-' ); title( 'RungeKutta method' ); xlabel( 'x' ); ylabel( 'y' ); grid on ; x0=0; y0=[2 4]'; h=0.2; xf=1; y=RungeKutta( 'fun' ,x0,y0,xf,h) 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0.5 1 1.5 2 2.5 3 3.5 4 RungeKutta method x y...
View Full Document

## This note was uploaded on 04/21/2010 for the course PGE 310 taught by Professor Klaus during the Spring '06 term at University of Texas.

### Page1 / 4

solution_hw12 - y(1,i+1)=y(1,i)+(k11+2*k21+2*k31+k41)*h/6;

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online