Experiment 7 Differential Equation First Order ( Euler Method )
Differential Equation First Order ( Euler Method )
CONCEPT:-
(a)(Differential Equation - First Order) In many problems, the direct functional relation between the dependent variable y and the independent variable x is not known. However, the 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
dy/dx = 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
CODE/METHOD
(a) (Euler Method - Forward) The derivative is approximated as y' = {y(x + h) − y(x)}/h and the ODE is represented by
{y(x + h) − y(x)}/h = f(x, y(x)) ⇒ y(x + h) = y(x) + hf(x, y(x))
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)
APPLICATION :-
(a) (Radioactive Decay) The time t and the population N bears the relation dN dt = −λN. Note f(t, N) = −N/τ where τ = 1/λ.
(b)(RC Circuit) The time t and the voltage V bears the relation dV /dt = −V /τ where τ = RC. Note f(t, V ) = −V /τ .
(c)(Stokes’ Law) The time t and the speed v bears the relation mdv/dt = −6πηav where all variables have their usual meaning. Note f(t, v) = −v/τ where τ = m/6πηa. Plot the time evolution of the respective solutions and highlight the main features of the solution. Make and display the tabulated output with time
Note Initial Values will be Given In the Question.
SCILAB CODE FOR THE GIVEN PROBLEM
//***Euler MEthod****
/****************************
clc, clear, clf
a=input("enter the value of left boundary condition for x of RC circuit= ")
b=input("enter the value of right boundary condition for xof RC circuit= ")
k=input("enter the value of left boundary condition for x of Radioactive
decay= ")
l=input("enter the value of right boundary condition for x of Radioactive
decay- ")
e=input("enter the value of left boundary condition for x of viscosity= ")
f=input("enter the value of right boundary condition for x of visxosity= ")
N=50
//RC Circuit
A= 5 //initial value of y in volts
Az=A/2 //half life
R= 1000 //value of R in ohms
C=0.000001 //value of C in Farads
u=1/(R*C) //u is a constant
hf1= log(0.5)/(-u)
h=(b-a)/(N+1) // calculating the value of step size for RC circuit
x(1)=a;y(1)=A; //initialising x and y
for i=1:N+1
y(i+1)= y(i)+h*(-u*y(i)) //forward difference formula
x(i+1)= x(i) + h
end
ex= A*exp(-u*x)
disp([x,y])
scf
plot(x,y,'*')
plot(hf1,Az,"*k")
plot(x,ex, 'r')
xlabel("time(sec))")
ylabel("voltage(v)")
set(gca(), 'grid',[1 1]*color('red'))
title ("RC Circuit")
note - With Limits 0 to 0.01 we will get the graph like this
//Radioactive Decay
lam= 0.3 //value of lambda
Nd= 10,000 //valyue of N- initial no of atoms
Ndz= Nd/2 //half life
dt= -lam//dt is a constant
hf2= log(0.5)/dt
ss= (l-k)/(N+1) //calculating the step size for Radioactive decay
xd(1)=k; yd(1)= Nd; //initialising x and y
for i=1:N+1
yd(i+1)=yd(i)+ss*(dt*yd(i)) //forward difference formula
xd(i+1)= xd(i) + ss
end
ex2= Nd*exp(dt*xd)
disp([xd,yd])
scf
plot(xd,yd,'*')
plot(xd,ex2, 'r')
plot(hf2,Ndz,"*k")
xlabel("time(sec)")
ylabel("Amount of substance(in thousands)")
set(gca(), 'grid',[1 1]*color('purple'))
title("radioactive decay")
//viscosity
Vo=1 //initial velocity in m s^-1
m=0.25 //mass of object in kg
sig= 0.09 //value of neta in kg m^-1 s^-1
Rv=0.007 // value of R
vt= -(6*%pi*sig*Rv)/m //vt is constant
sv= (f-e)/(N+1) //calculating the step size for viscosity
Vz= Vo/2 //half life
hf3=log(0.5)/ vt
xv(1)= e; yv(1)=Vo; //initialising x and y
for i=1:N+1
yv(i+1)=yv(i)+sv*(vt*yv(i)) //forward difference formula
xv(i+1)= xv(i) + sv
end
ex3= Vo*exp(vt*xv)
disp([xv,yv])
scf
plot(xv,yv,'*')
plot(xv,ex3, 'r')
plot(hf3,Vz,"*k")
xlabel("time(sec)")
ylabel("velocity(m/s)")
set(gca(), 'grid',[1 1]*color('green'))
title("viscosity")
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