MLL703_minor_tutorial222222
MLL703_minor_tutorial222222
Instructions:
Question 1: Write a program that takes the input of a student's name and their marks, ensure
that the marks are entered as a floating-point number. Print the student's name and their marks,
along with the type of both variables. (3 marks)
• Take input of a, b, and c from the user using the input function.
• Use the if else statement.
o Syntax of if else is
if condition:
# block of code executed if the condition is true
elif another_condition:
# block of code executed if the previous condition is false
and this one is true
else:
# block of code executed if all the above conditions are false
1. Formulate the ordinary differential equation (ODE) that describes this decay
process.
2. Utilize the solve_ivp function from the scipy.integrate module to numerically solve
for the remaining quantity of the substance over time.
3. Plot the decay curve over the time interval from t=0 to t=50 using
the matplotlib.pyplot module.
4. Ensure that both axes are labeled using plt.xlabel and plt.ylabel, and provide a title for
the graph.
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
# Function representing the ODE: dy/dx = f(x, y)
def f(x, y):
return _____________ # ODE: y’+2y=x3*e-2x
plt.xlabel('x')
plt.ylabel('y')
plt.title("Comparison of Euler's Method and solve_ivp for ODE")
plt.legend()
plt.grid(True)
plt.show()