MP II Interface Ansh-Merged
MP II Interface Ansh-Merged
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 𝑦(𝑥𝑜) = 𝑦𝑜
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:
𝐾₁ = ℎ ∗ 𝑓((𝑥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
Code 3:
Output 3:
𝐾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
Output 4:
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
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𝑥 𝑑𝑥
𝑦
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
𝑁 = 𝑒 −𝜆𝑡+𝐶
𝑁 = 𝑒 −𝜆𝑡 𝑒 𝐶
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.
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
𝑠
𝑇 − 𝑇𝑠 = 𝑒 −𝐾𝑡 +𝐶
𝑇0 − 𝑇𝑠 = 𝑒 𝐶
𝐶 = 𝑙𝑛(𝑇0 − 𝑇𝑠 )
𝑇 − 𝑇𝑠 = 𝑒 −𝐾𝑡 𝑒 ln (𝑇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 − 𝑒𝑥𝑝(− ))
𝑅𝐶
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).
(𝑏 − 𝑎)(𝑓(𝑎) + 𝑓(𝑏))
2
So,
𝑏
𝑓(𝑎) + 𝑓(𝑏)
∫ 𝑓(𝑥)𝑑𝑥 = (𝑏 – 𝑎)
𝑎 2
This formula will give meaningful result only when the interval (a,b) is very small
Therefore
𝑥𝑖 +1
ℎ
∫ 𝑓(𝑥) 𝑑𝑥 = (𝑓 + 𝑓𝑖+1 )
𝑥𝑖 2 𝑖
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.
where 𝑥𝑖+1 − 𝑥𝑖 = ℎ
𝑏 𝑥𝑖 𝑥𝑛
∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝑓(𝑥)𝑑𝑥 +. . . . . . . . . . + ∫ 𝑓(𝑥)𝑑𝑥
𝑎 𝑥0 𝑥𝑛−1
ℎ ℎ ℎ
= (𝑓0 + 𝑓1 ) + (𝑓1 + 𝑓2 ) +. . . (𝑓𝑛−1 + 𝑓𝑛 )
2 2 2
ℎ
= (𝑓0 + 2𝑓1 + 2𝑓2 +. . . +2𝑓𝑛−1 + 𝑓𝑛 )
2
Output 10: