0% found this document useful (0 votes)
6 views16 pages

MP II Interface Ansh-Merged

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views16 pages

MP II Interface Ansh-Merged

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Kirori Mal College

University of Delhi
Mathematical Physics – II (Practical File)

Submitted By: -
❖ Name: Ansh Prasad
❖ Course: B.Sc. Physics Honors
❖ Year/Sem: 1st / 2nd Sem
❖ College Roll No.: 2430227
❖ Examination Roll No.: 24036567033
Submitted To: -
Dr. Prachi Yadav
Department of Physics,
Kirori Mal College,
University of Delhi.
Euler Method:
Euler's method is a straightforward numerical technique for solving ordinary differential
equations (ODEs). Let's consider a first-order ODE of the form:
𝑑𝑦
= 𝑓(𝑥, 𝑦)
𝑑𝑥
with an initial condition 𝑦(𝑥𝑜) = 𝑦𝑜

In General, Euler method solution for ODE can be written as

𝑦(𝑛 + 1) = 𝑦(𝑛) + ℎ ∗ 𝑓[𝑥(𝑛), 𝑦(𝑛)]

𝑥(𝑛 + 1) = 𝑥(𝑛) + ℎ, where he is step size.

AIM 1 → The differential equation is


𝑑𝑦
= 𝑥 + 𝑦
𝑑𝑥
By using Euler Method, Find the value of y at x = 1, If the step size is 0.2 and the value of y
corresponding to x = 0 to zero.

Code 1:

Output 1:
AIM 2 → The differential equation is
𝑑𝑦
= 1 + 𝑦2
𝑑𝑥
Find the value of y at x = 1 If the step size is 0.2 and the value of y corresponding to x = 0 to
zero.

Code 2:

Output 2:

Runge kutta second order method (RK-2):


Let's consider a first-order ODE of the form:
𝑑𝑦
= 𝑓(𝑥, 𝑦)
𝑑𝑥
with an initial condition 𝑦(𝑥0) = 𝑦0 The increment in y is computed from the formulae

𝐾₁ = ℎ ∗ 𝑓((𝑥0)(𝑦0))

𝐾2 = ℎ ∗ 𝑓(𝑥0 + ℎ, 𝑦0 + 𝐾1 )
1
∆𝑦 = (𝐾 + 𝐾2 )
2 1
1
Then 𝑥1 = 𝑥0 + ℎ and 𝑦1 = 𝑦0 + ∆ 𝑦 = 𝑦0 + (𝐾1 + 𝐾2 ) In the similar manner the
2
increment in y for second interval is computed from the formulae

𝐾1 = ℎ ∗ 𝑓((𝑥1 )(𝑦1 ))

𝐾2 = ℎ ∗ 𝑓(𝑥1 + ℎ, 𝑦1 + 𝐾1 )
1
∆𝑦 = (𝐾1 + 𝐾2 ) and similarly for the next.
2

AIM 3 → The differential equation is


𝑑𝑦
= 𝑥 + 𝑦
𝑑𝑥
By using RK - 2 Method, Find the value of y at x = 1, If the step size is 0.2 and the value of y
corresponding to x = 0 to zero.

Code 3:

Output 3:

Runge kutta fourth order method (RK - 4):


Let's consider a first-order ODE of the form:
𝑑𝑦
= 𝑓(𝑥, 𝑦)
𝑑𝑥
with an initial condition 𝑦(𝑥0) = 𝑦0

The increment in y is computed from the formulae

𝐾1 = ℎ ∗ 𝑓 (𝑥0)(𝑦0))
ℎ 𝑘1
𝐾2 = ℎ ∗ 𝑓 (𝑥0 + , 𝑦0 + )
2 2
ℎ 𝐾2
𝐾3 = ℎ ∗ 𝑓 (𝑥0 + , 𝑦0 + )
2 2
𝐾4 = ℎ ∗ 𝑓 (𝑥0 + ℎ, 𝑦0 + 𝐾3 )
1
∆𝑦 = ∗ (𝐾1 + 2𝐾2 + 2𝐾3 + 𝐾4 )
6
Then 𝑥1 = 𝑥0 + ℎ and 𝑦1 = 𝑦0 + ∆𝑦 In the similar manner the increment in y for second
interval is computed from the formulae

𝐾1 = ℎ ∗ 𝑓((𝑥1 )(𝑦1 ) )
ℎ 𝑘1
𝐾2 = ℎ ∗ 𝑓(𝑥1 + , 𝑦1 + )
2 2
ℎ 𝑘2
𝐾3 = ℎ ∗ 𝑓(𝑥1 + , 𝑦1 + )
2 2
𝐾4 = ℎ ∗ 𝑓(𝑥1 + ℎ, 𝑦1 + 𝐾3 )
1
∆𝑦 = ∗ (𝐾1 + 2𝐾2 + 2𝐾3 + 𝐾4 ) and similarly for the next.
6

AIM 4 → The differential equation is


𝑑𝑦
= 𝑥 + 𝑦
𝑑𝑥
By using RK - 4 Method, Find the value of y at x = 1, If the step size is 0.2 and the value of y
corresponding to x = 0 to zero.
Code 4:

Output 4:

Modified Euler method:


Let's consider a first-order ODE of the form:
𝑑𝑦
= 𝑓(𝑥, 𝑦)
𝑑𝑥
with an initial condition 𝑦(𝑥0) = 𝑦0, step size h, 𝑥𝑛+1 = 𝑥𝑛 + ℎ

Use Euler's method to estimate (First Estimate:) y1, The value of y at x1.

𝑦12 = 𝑦𝑛 + ℎ ∗ 𝑓(𝑥𝑛 , 𝑦𝑛 )

Use the first estimate to find a more accurate estimate y12 (Second Estimate :)

𝑦12 = 𝑦𝑛 + [𝑓(𝑥𝑛 , 𝑦𝑛 ) + 𝑓(𝑥𝑛+1 , 𝑦11 )]
2

AIM 5 → The differential equation is


𝑑𝑦
= 𝑥 + 𝑦
𝑑𝑥
By using Modified Euler Method, Find the value of y at x = 1, If the step size is 0.2 and the value
of y corresponding to x = 0 to zero.

Code 5:

Output 5:

Problem a:
The differential equation is
𝑑𝑦
= 2𝑥𝑦
𝑑𝑥
Find the value of y at x = 1, If the step size is 0.05 and the value of y corresponding to x = 0 to 1.

Solution:
𝑑𝑦
The given differential equation is 𝑑𝑥 = 2𝑥𝑦. This is a first-order linear ordinary differential
equation that can be solved using separation of variables. Separate variables by dividing both
sides by y and multiplying both sides by dx
1
𝑑𝑦 = 2𝑥𝑑𝑥 Now integrate both sides:
𝑦
1
∫ 𝑑𝑦 = ∫ 2𝑥 𝑑𝑥
𝑦

𝑙𝑛(𝑦) = 𝑥 2 + 𝐶 Simplify by combining exponents:


2 +𝑐
𝑦 = 𝑒𝑥
2
𝑦 = 𝑒 𝑥 . 𝑒 𝑐 where 𝑒 𝑐 = 𝐴 (positive constant)
2
𝑦 = 𝐴. 𝑒 𝑥 This is the Exact solution of the given differential equation.

AIM 6 → Solution of “ problem a ” by Euler Method, Exact Solution and Inbuilt Function
(Odeint) and Plots:

Code 6:
Output 6:

Radioactive Decay:
The radioactive decay first-order linear differential equation is given by:
𝑑𝑁
= −𝜆∗𝑁
𝑑𝑇
where 𝑁(𝑡) as the quantity of radioactive substance at time t

and 𝜆 is the decay constant. To solve it, we can separate variables and integrate both sides.
1 𝑑𝑁
= −𝜆
𝑁 𝑑𝑡
1
∫ 𝑑𝑁 = ∫ −𝜆𝑑𝑡
𝑁
Integrating both sides gives

𝐼𝑛 𝑁 = −𝜆𝑡 + 𝐶 Exponentiate both sides to solve for N:

𝑁 = 𝑒 −𝜆𝑡+𝐶

𝑁 = 𝑒 −𝜆𝑡 𝑒 𝐶

𝑁 = 𝑁0 . 𝑒 −𝜆𝑡 Exact solution

Where 𝑒 𝑐 = 𝑁0
AIM 7 → To Plot Radioactive Decay ODE by Euler, Exact and In-built function.
Code 7:

Output 7:
Newton Cooling Law:
Newton's Law of Cooling first-order linear ordinary differential equation.
𝑑𝑇
= − 𝐾 (𝑇 − 𝑇𝑠 )
𝑑𝑡
𝑑𝑇
Where 𝑑𝑡 is the rate of change of temperature.

K is constant.

T is the temperature of the object.

Ts is the temperature of the surroundings.

Let's assume the initial temperature of the object is T0 at time t = 0. To solve it, we can use
separation of variables and integrate both sides.
1 𝑑𝑇
= −𝐾
𝑇 − 𝑇𝑠 𝑑𝑡
1
∫ 𝑇 − 𝑇 𝑑𝑇 = ∫ − 𝐾 𝑑𝑡 integrating both sides
𝑠

𝑙𝑛(𝑇 − 𝑇𝑠 ) = − 𝐾 𝑡 + 𝐶, where C is constant

Exponentiate both sides to solve

𝑇 − 𝑇𝑠 = 𝑒 −𝐾𝑡 +𝐶

𝑇 − 𝑇𝑠 = 𝑒 −𝐾𝑡 𝑒 𝐶 Applying initial conditions

𝑇0 − 𝑇𝑠 = 𝑒 𝐶

𝑇0 = 𝑇𝑠 + 𝑒 𝐶 , solving it for constant C

𝐶 = 𝑙𝑛(𝑇0 − 𝑇𝑠 )

put the value of C in the equation

𝑇 − 𝑇𝑠 = 𝑒 −𝐾𝑡 𝑒 ln (𝑇0 − 𝑇𝑠 )

𝑇 = 𝑇𝑠 + (𝑇0 − 𝑇𝑠 ) . 𝑒 −𝐾𝑡 Exact solution

𝑇0 is the initial temperature of the object at t = 0

AIM 8 → To plot Newton’s cooling law ODE by Euler method, Exact solution and
Inbuilt solver.
Program 8:

Output 8:
RC-charging Differential equation:
The first order differential equation of RC(Charging) Circuit is:
𝑑𝑞 𝑞 − 𝑉𝐶
= (−1) ( )
𝑑𝑡 𝑅𝐶
Solution of this equation is
𝑡
𝑞 = 𝑉𝐶(1 − 𝑒𝑥𝑝(− ))
𝑅𝐶

AIM 9 → To plot RC Charging by Euler, Exact and inbuilt solver.


Code 9:

Output 9:
TRAPEZOIDAL RULE
Consider the function f(x)
𝑏
We know that integrate ∫𝑎 𝑓(𝑥)𝑑𝑥 is the area bounded by the curve y=f(x) and a x-axis in
between ordinates x=a and x=b We can assume that it is a trapezoid. The two parallel sides
are f(a) and f(b).

So the area of the trapezoid is

(𝑏 − 𝑎)(𝑓(𝑎) + 𝑓(𝑏))
2
So,
𝑏
𝑓(𝑎) + 𝑓(𝑏)
∫ 𝑓(𝑥)𝑑𝑥 = (𝑏 – 𝑎)
𝑎 2

This formula is called the trapezoidal rule.

This formula will give meaningful result only when the interval (a,b) is very small

Therefore
𝑥𝑖 +1

∫ 𝑓(𝑥) 𝑑𝑥 = (𝑓 + 𝑓𝑖+1 )
𝑥𝑖 2 𝑖

Where h is very small.

If we want to find the integral over an interval (a,b), we must first divide the interval into a
number of small equal subintervals.

𝑎 = 𝑥0 < 𝑥1 < 𝑥2 < . . . . . < 𝑥𝑛 = 𝑏

where 𝑥𝑖+1 − 𝑥𝑖 = ℎ
𝑏 𝑥𝑖 𝑥𝑛
∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝑓(𝑥)𝑑𝑥 +. . . . . . . . . . + ∫ 𝑓(𝑥)𝑑𝑥
𝑎 𝑥0 𝑥𝑛−1

ℎ ℎ ℎ
= (𝑓0 + 𝑓1 ) + (𝑓1 + 𝑓2 ) +. . . (𝑓𝑛−1 + 𝑓𝑛 )
2 2 2

= (𝑓0 + 2𝑓1 + 2𝑓2 +. . . +2𝑓𝑛−1 + 𝑓𝑛 )
2

This formula is used to evaluate the integral

AIM 10 → To Integrate the function 𝑓(𝑥) = 𝑥 2 using trapezoidal method.


Code 10:

Output 10:

You might also like