Experiment 8 Differential Equation Second Order ( Runge Kutta Method )
Differential Equation Second Orde ( Runge Kutta Method )
CONCEPT
(a)(Differential Equation - Second Order) In many problems, the direct functional relation between the dependent variable y and the independent variable x is not known. However, the second rate of change in y with respect to x is known and is given by a function f(x, y). The idea is to deduce the function y(x) from the rate equation
d^2y/dx^2 = f(x, y(x))
(b)(Initial Value Problem) Any DE represent a family of curves/surfaces, however most problems pertains to picking out a particular curve which satisfies the given conditions. In nutshell, we seek a solution y(x) which satisfies the initial conditions
y(x0) = y0 & y'(x0) = v0
METHOD/CODE
(a)(Runge Kutta Method - Order 2) As an improvement over the Euler method, the incremental solution is represented by
y(x + h) = y(x) + (k1 + k2)/2 where
k1 = h ∗ f(x, y) & k2 = h ∗ f(x + h, y + k1)
The domain (a, b) is populated with N equispaced nodal points to get (a, x1, ..., xN , b) representative points where xi = a + ih and h = (b − a)/(N + 1). The corresponding yi is evaluated using the above recursive relation to yield (y0, y1, ..., yN , yN+1).
(b)(Reducing Order 2 to Order 1) The second order is reduced to the first order as dy dx = z whereof dz/dx = f(x, y(x))
APPLICATION
(a)(Simple Harmonic Oscillator) The time t and the displacement x bears the relation
d^2x/dt^2 = − (k/m)*x
for a simple harmonic oscillator, where all variables have their usual meaning.
(b) (RC Circuit) The time t and the displacement x bears the relation
d^2x/dt^2 = − (b/m)* (dx/dt) =− (b/m)*x
for a damped oscillator, where all variables have their usual meaning. Plot the time evolution of the respective solutions and highlight the main features of the solution. Make and display the tabulated output with time.
SCILAB CODE FOR THE GIVEN PROBLEM
\\************************************************************
//runge kutta
clc,clear
clf
told=0
b=100
N=100
r=input("put value of damping constant 1 for damped,0 for undamped=")
function h=step(told,b,N)
h=(b-told)/(N+1)
endfunction
k=100
m=250
eta=-(r/m)
tau=-(k/m)
xold=1
e=1
function b1=deri(t,x,z,tau,eta)
b1=tau*x+eta*z
endfunction
function l1=a(told,b,N,x,tau,z,eta)
l1=step(told,b,N)*deri(told,x,z,tau,eta)//value of l1
endfunction
function l2=g(told,b,N,x,tau,z,eta)
l2=step(told,b,N)*deri(told,x+(s(told,b,N,z)/2),z+(a(told,b,N,x,tau,z,eta)/2),tau,eta)//value of l2
endfunction
function k1=s(told,b,N,z)
k1=step(told,b,N)*z//value of k1
endfunction
function k2=l(told,b,N,z,x,tau,eta)
k2=step(told,b,N)*(z+(a(told,b,N,x,tau,z,eta)/2))//value of k2
endfunction
zold=0
for i=1:N+1
z=zold+(g(told,b,N,xold,tau,zold,eta))
x=xold+(l(told,b,N,zold,xold,tau,eta))
t=told+(i*(step(told,b,N)))
xold=x
zold=z
v(e:N+1)=zold
c(e:N+1)=t
w(e:N+1)=xold
e=e+1
end
scf(0)
plot(c,w,"g")
plot(c,v,"b")
legend("x vs t","z vs t")
xgrid(2)
scf
plot(w,v,"r")
//plot(w,v,"r")
xgrid(1)
Note - Enter 1 for Damped and 0 for UnDamped H.O.
FIG -1
FIG -2
Make Adjustment according to Your Given Problem .
NOTE :- If you have any Problem or Query Regarding this Blog Please Comment Down Or Reach us Out at scilabprogram@gmail.com
//university of Delhi //Department of Physics
Comments
Post a Comment