2024 Week 6 - Jupyter Notebook
2024 Week 6 - Jupyter Notebook
Write a python code to evaluate the first derivative of the function 𝑓(𝑥) = 𝑥2 + 𝑥3 + 𝑥5 𝑥 = 1.1
at using the 2-
point forward difference scheme for ℎ = 0.1 .
3
Round the answer to decimal places using the Python function round() as below: ans = round(ans, 3)
Note: Do not use inbuilt methods/libraries to compute the derivative.
Out[2]: 15.048
Write a python code to find the first derivative of the function 𝑓(𝑥) = 𝑥 + 𝑥42 + 𝑥93 at 𝑥 = 2.0 using the 2-point
backward difference scheme for ℎ = 0.1
.
Round your answer to 3 decimal places. Note: Do not use inbuilt methods/libraries.
Out[3]: 3.243
Write a python code to find the first derivative of the function 𝑓(𝑥) = 𝑥𝑥22−1+1 at 𝑥 = 0.09 using the 3-point central
difference scheme for ℎ = 0.01
.
Round the answer to 1 decimal place. Note: Do not use inbuilt methods/libraries.
Out[4]: 0.4
Write a python code to solve the differential equation
𝑑𝑥
𝑑𝑡 = 1𝑥 + 1𝑡 .
Use Euler’s forward scheme with time step, ∆𝑡 = 0.001
to find the value of 𝑥(𝑡) 𝑡 = 2.0
at for the initial condition
𝑥(1) = 1.
Round the answer to two decimal places. Note: You should not use any inbuilt methods/libraries in your code.
Out[5]: 2.3
= 𝑥2 − 100𝑥.
Write a python code to solve the differential equation
𝑑𝑥
𝑑𝑡
Use Euler’s backward scheme with time step, Δ𝑡 = 0.001 to find the value of 𝑥(𝑡) at 𝑡 = 1 for the initial condition
𝑥(0) = 1.
Round the answer to two decimal places. Note: You should not use any inbuilt methods/libraries in your code.
Out[6]: 0.0
Out[7]: 0.04
𝑖
The differential equation which relates the current , voltage 𝑉 , resistance 𝑅 and inductance 𝐿 of a series
electrical circuit, is given by -
𝑑𝑖
𝑑𝑡 + 𝑅𝐿𝑖 = 𝑉𝐿.
Use Euler forward and Euler backward scheme to find the value of current 𝑖(𝑡 = 2)
for the initial condition
𝑖(𝑡 = 0) = 0.0 .
Use 𝑉 = 240.0,𝑅 = 20.0,𝐿 = 50.0 Δ𝑡 = 0.01
and .
Let's say the result from Euler forward scheme is e_forward and from euler backward scheme is e_backward.
Round them both to two decimal places.
Now calculate the following quantity
Out[8]: 15.13
Out[9]: 0.14
Write a Python program to solve the differential equation = 𝑡𝑥2 using Trapezoid method and evaluate
𝑑𝑥
𝑑𝑡
𝑥(𝑡 = 2.0).
Use time step, Δ𝑡 = 0.01 and the initial condition, 𝑥(𝑡 = 1) = 1 . Round your answer to 2 decimal places.
In [10]: 1 def trapezoid_method(x0, dt, t_end, t_start):
2 x = x0
3 t = t_start
4 while t < t_end:
5 t_next = t + dt
6 x_next = (x + (dt / 2) * (x / t**2)) / (1 - (dt / 2) * (1 / t_next**2)) # x_nex
7 x = x_next
8 t = t_next
9 return x
10
11 # Parameters
12 dt = 0.01 # Time step
13 t_end = 2.0 # Final time
14 x0 = 1.0 # Initial condition
15 t_start = 1.0 # Initial time
16
17 x_t_end = trapezoid_method(x0, dt, t_end, t_start)
18 round(x_t_end, 2)
Out[10]: 1.65
Write a python code to solve the differential equation = 𝑥 + 𝑦 using Euler Forward scheme and find the value
𝑑𝑦
𝑑𝑥
of 𝑦(𝑥 = 2) .
Take time step, Δ𝑥 = 0.01 and the initial condition to be 𝑦(𝑥 = 0) = 1.0.Round the answer to two decimal
places.
Out[11]: 11.63