Answered step by step
Verified Expert Solution
Question
1 Approved Answer
All ODEs have something in common and we would like to abstract this commonalities into an abstract representation of an ODE which should capture
All ODEs have something in common and we would like to abstract this commonalities into an abstract representation of an ODE which should capture the essence of what it means to be an ODE. This is what is meant by abstraction in the four pillars for object oriented design. Having one common interface for all ODEs will make it easier for us when we want to work with them later. The most important aspect of an ODE is the definition of the right hand side of the derivative, ie the function fin =f(t.u) For the exponential decay ODE we will have ft. u)=--ax. We saw in the du previous exercise that we can implement this using the_call__ method. Create class ODEModel, with the following_call___ method def _call (self, t: float, u: np.ndarray) np.ndarray: raise Not ImplementedError that raises a Not ImplementedError. Any class that inherits from this class will use this _call method unless the class implement a special version of this method (like we did for the ExponentialDecay class). This means that whenever you create a new model that inherits from DEModel, your program will raise a Not ImplementedError whenever you try to call the call method if it has not yet been implemented in the subclass Pro tip - Using abstract base classes The most common way to implement an interface is by creating an abstract class using the abc library. See the section on abstract classes in the lecture notes for more info. Feel free to use the abc library to create the interface if you want. In that case, the class would look similar to the following code: import abc class ODEModel(abc.ABC): @abc.abstractmethod def _call_(self, t: float, u: mp.ndarray) np.ndarra pass Write this class in a file called ode-py-Once created, let your ExponentialDecay class inherit from 00Model by importing it from the newly created ode module. Verify that all your tests passes.
Step by Step Solution
★★★★★
3.36 Rating (149 Votes )
There are 3 Steps involved in it
Step: 1
To create an abstract base class for ODE models and have your Exponentialdecay class inherit from it ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started