Runge Kutta fourth order

//Runge Kutta 4rth order

deff('g=f(x,y)','g=2*y+x')
xo=input("Enter initial value of xo: ")
yo=input("Enter the value of yo: ")
h=input("Enter value of h: ")
xn=input("Enter Final value of xn: ")
n=(xn-xo)/h
for i=1:n
    k1=h*f(xo,yo)
    k2=h*f(xo+(h/2),yo+(k1/2))
    k3=h*f(xo+(h/2),yo+(k2/2))
    k4=h*f(xo+h,yo+k3)
    y1=yo+(1/6)*(k1+2*k2+2*k3+k4)
    xo=xo+h
    disp([xo y1])
    yo=y1
end

Output
-->exec('D:\Scilab prog by me\Runge Kutta fourth order.sce', -1)
Enter initial value of xo: 0
Enter the value of yo: 1
Enter value of h: 0.1
Enter Final value of xn: 0.3

    0.1    1.22675

    0.2    1.5147724

    0.3    1.8776331

7 comments:

  1. hiii....i have doubt with value of xn...what is it xactly????

    ReplyDelete
    Replies
    1. the value for which you have to find. for example if you have to find the value of y(0.2), then xn=0.2.

      Delete
  2. can you mathematically explain this code

    ReplyDelete
    Replies

    1. Runge-Kutta methodmath.okstate.edu › teaching › math4513_fall11 › Notes
      PDF

      see this

      Delete
  3. Is this code suitable for working in ubuntu OS ???

    ReplyDelete
  4. am searching for a solution to this differential equation
    N.(d^2 u)/〖dz〗^2 +Rig (d^4 u)/〖dz〗^4 +Es.u=0

    ReplyDelete
  5. Explain the condition yo= y1

    ReplyDelete