idc101 (introduction to computation) : lab session 11santh/eleventhexe.pdfiiser, pune (semester i,...

3
IISER, Pune (Semester I, 2017) IDC 101 (Introduction to Computation) IDC101 (Introduction to Computation) : Lab session 11 General Instruction : (Please read these instructions carefully before proceeding to the excercises section) The problems in this excercise gets you accustomed to writing simple codes to solve differential equations by Eulers methods and Runge-Kutte 4th order method. It will also help you understand the acuracy of each of the methods. You will have to invoke matplotlib libraries for plotting the functions. Some useful formulaes: For a differential equation of the form: = (, ) 1. Simple Euler's Method: !!! = ( ! ) + ! 2. Improved Eulers method : !!! = ( ! ) + ( ! , ! ) + [ ! + , ! + ( ! , ! )] 2 3. RK4 or Runge-Kutta fourth order method !!! = ( ! ) + ! ! ( ! + 2 ! + 2 ! + ! ) + (! ) where, ! = ( ! , ! ) ! = ( ! + /2, ! + ! /2 ) ! = ( ! + /2, ! + ! /2 ) ! = ( ! + , ! + ! ) Where h is the step size. Ignore the term (! ) 4. Consider the following functions with initial conditions: and bounds: = ! + 1

Upload: vohanh

Post on 01-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

IISER, Pune (Semester I, 2017) IDC 101 (Introduction to Computation)

IDC101 (Introduction to Computation) : Lab session 11 General Instruction : (Please read these instructions carefully before proceeding to the excercises section) The problems in this excercise gets you accustomed to writing simple codes to solve differential equations by Eulers methods and Runge-Kutte 4th order method. It will also help you understand the acuracy of each of the methods. You will have to invoke matplotlib libraries for plotting the functions. Some useful formulaes: For a differential equation of the form:

𝑦′ = 𝑓(𝑥, 𝑦) 1. Simple Euler's Method:

𝑦!!! = 𝑦(𝑥! ) + ℎ 𝑓! 2. Improved Eulers method :

𝑦!!! = 𝑦(𝑥! ) + ℎ𝑓(𝑥! , 𝑦!) + 𝑓[𝑥! + ℎ, 𝑦! + ℎ𝑓(𝑥! , 𝑦!)]

2

3. RK4 or Runge-Kutta fourth order method

𝑦!!! = 𝑦(𝑥! ) + !!( 𝑓! + 2𝑓! + 2𝑓! + 𝑓! ) + 𝑂(ℎ!)

where,

𝑓! = ℎ𝑓(𝑥! , 𝑦! )

𝑓! = ℎ𝑓(𝑥! + ℎ/2, 𝑦! + 𝑓!/2 )

𝑓! = ℎ𝑓(𝑥! + ℎ/2, 𝑦! + 𝑓!/2 )

𝑓! = ℎ𝑓(𝑥! + ℎ, 𝑦! + 𝑓! )

Where h is the step size. Ignore the term 𝑂(ℎ!) 4. Consider the following functions with initial conditions: and bounds:

𝑦′ = 𝑦! + 1

IISER, Pune (Semester I, 2017) IDC 101 (Introduction to Computation)

...Equation no. (1) In the interval 0 ≤ 𝑥 ≤ 1 for initial condition 𝑦(0) = 0 ------------------------------------------------------------------------------------------------

!"(!)!"

= −3𝑛(𝑡) ...Equation no. (2)

In the interval 0 ≤ 𝑡 ≤ 10 for initial condition 𝑛(𝑡 = 0) = 100.

------------------------------------------------------------------------------------------------

𝑑𝑦𝑑𝑥

=5𝑥! − 𝑦𝑒! + 𝑦

...Equation no. (3)

------------------------------------------------------------------------------------------------

In the interval 0 ≤ 𝑥 ≤ 1 for initial condition 𝑦 = 1 at 𝑥 = 0

𝑑𝑦𝑑𝑥

= (𝑥 − 𝑦) 𝑠𝑖𝑛(𝑥𝑦) ...Equation no. (4)

In the interval 0 ≤ 𝑥 ≤ 2 for initial condition 𝑦 = 5 at 𝑥 = 0

------------------------------------------------------------------------------------------------

Excercises 1. Peform the following:

a) Solve equations 1 and 2 above, analytically. b) Generate the values of the functions numerically using Eulers two

methods in the intervals mentioned. c) Plot these values as a function of the independent variable. d) Now use Eulers two methods to solve those differential equations and

IISER, Pune (Semester I, 2017) IDC 101 (Introduction to Computation)

plot the values of the calculated solution on the same graph as that which is generated analytically.

e) Use the Runge-Kutta method and repeat d). f) Calculate the difference between the analytically calculated value and the

value calculated by numerical integration. Calculate sum of the absolute value of the residuals (sum of the differences betwen numerical and the analytical values) and compare this for all the methods. Understand which method is more accurate. You can repeat this excercise for different step sizes and see which method becomes faster, i.e. for the smallest no of steps, which method become accurate faster.

2. Peform the following excercies:

a) Solve equations 3 and 4 above, numerically, using all the three methods in the intervals mentioned. Use appropriate step size.