Scilab Program - runge kutta 2nd order - IProgramX

Program

function[]=rk(x0,y0,xn,h,f)
      y(1)=y0
      j=(xn-x0)/h
      for i=1:j
          k1=h*f(x0,y(i))
          k2=h*f(x0+h,y(i)+k1)
          y(i+1)=y(i)+(k1+k2)/2
          x0=x0+h
         printf('\ny(%g)=%g\n',x0,y(i+1))
      end
      endfunction

Output:

  deff('y=f(x,y)','y=2+sqrt(x*y)')

  rk(1,1,1.6,0.1,f)

y(1.1)=1.30979

y(1.2)=1.63973

y(1.3)=1.99009

y(1.4)=2.36122

y(1.5)=2.75355

y(1.6)=3.16754

Post a Comment

0 Comments