Runge Kutta second order

//Runge Kutta 2nd 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,yo+k1)
    y1=yo+(1/2)*(k1+k2)
    xo=xo+h
    disp([xo y1])
    yo=y1
end

Output
-->exec('D:\Scilab prog by me\Runge Kutta second 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.225

    0.2    1.5105

    0.3    1.86981

1 comment:

  1. Thanks for the code. It is very helpful for me.
    If you were you tuber than can you please tell the name of your channel ......, I wanna visit at your channel

    ReplyDelete