R Programs-NS
R Programs-NS
#Output
Practice Questions
1.
2.
3.
Runga-Kutta Method of 2nd Order
Consider the first order ordinary differential equation
𝑑𝑦
= 𝑓(𝑥, 𝑦)
𝑑𝑥
with initial condition y(x0)= y0
Let xn=x0+nh=xn-1+h, where h is the step size and n is the number of steps.
Formula:
K1 = hf(xn,yn)
K2 = hf(xn + h,yn + K1)
K=1/2(K1+ K2)
y(xn+1) = yn+1 = yn+K
#Output
Practice Questions
1.
2.
3.
Runga-Kutta Method of 4th Order
Consider the first order ordinary differential equation
𝑑𝑦
= 𝑓(𝑥, 𝑦)
𝑑𝑥
with initial condition y(x0)= y0
Let xn=x0+nh=xn-1+h, where h is the step size and n is the number of steps.
Formula:
K1 = hf(xn,yn)
K2 = hf(xn + h/2,yn + K1/2)
K3 = hf(xn + h/2,yn + K2/2)
K4 = hf(xn + h,yn + K3)
K=(K1+2K2+2K3+K4)/6
y(xn+1) = yn+1 = yn+K
#Output
Practice Questions
1.
2.
3.