All ODEs have something in common and we would like to abstract this commonalities into an...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
To create an abstract base class for ODE models and have your Exponentialdecay class inherit from it ... View the full answer
Related Book For
A Concise Introduction to Logic
ISBN: 978-1305958098
13th edition
Authors: Patrick J. Hurley, Lori Watson
Posted Date:
Students also viewed these programming questions
-
Business Law - United States Principle vs Agent, the concept of representation. What are some past legal cases (atleast 3) and law sections that outline and specify the duty of obedience as an agent?...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
James was delivered at 39 weeks in a planned delivery. He was the largest of my babies, weighing 8 pounds, 4 ounces, and measuring 21.5 inches. He had a raspy cry, a full head of hair, and very light...
-
Distance between Cars (Refer to Example 6.) At 9:00 A.M. car A is traveling north at 50 miles per hour and is located 50 miles south of car B. Car B is travel- ing west at 20 miles per hour. (a) Let...
-
One technique for measuring the angle of a prism is shown in Figure P35.50. A parallel beam of light is directed on the angle so that parts of the beam reflect from opposite sides. Show that the...
-
Cost data on the activities of Columbia Manufacturing for May are as follows: (c) 4,250 direct labor hours were worked in May. Laborers work a 40-hour week and are paid $22 per hour for the regular...
-
Use a stem-and-leaf plot to display the data, which represent the numbers of hours 24 students study per week. Organize the data using the indicated type of graph. Describe any patterns. 20 24 25 18...
-
Wallis Company manufactures only one product and uses a standard cost system. The company uses a predetermined plant wide overhead rate that relies on direct labor-hours as the allocation base. All...
-
Your team was just hired as strategic marketing consultants for a small company that specializes in website translation. The company, which is two years old, translates and localizes websites for...
-
The trial balance of Pacilio Security Services Inc. as of January 1, 2017, had the following normal balances: Cash ................. 78 , 972 P e t t y C a s h . . . . . . . . . . . . . . . . 100 A c...
-
In January 2008, it was discovered that William Borchard, who handled due diligence for clients of PwC interested in mergers and acquisitions, divulged controversial plans to Gregory Raben, an...
-
Claire Corporations trial balance includes the following expenses: Raw materials used in production $5,500 Raw materials purchased 6,500 General manager salary 50,000 Sales manager salary 30,000...
-
An aircraft is at a standstill. It accelerates to 156.3 kt in 22.8 seconds. Calculate the acceleration in feet/sec^2.
-
Describe & discuss the purpose of a Construction Phase Plan (CPP); as part of the answer discuss what it is likely to contain, the main parties it intended to protect and why it may need to be...
-
An aircraft has an initial velocity of 19 knots and an acceleration of 10.84 feet/sec^2. What is the final velocity, in knots, after 15.9 seconds?
-
Two parakeets sit on a swing with their combined center of mass 19.65 cm below the pivot. At t= Os the parakeets are at their maximum backwards position At what time, in seconds, do the parakeets...
-
Let G denote the group of all 2 2 invertible matrices with entries from R. H = {A = G||A|=1} and H = {A = G|A is invertible upper triangular matrix such that a = 1}. Consider the following...
-
What is master production scheduling and how is it done?
-
All pixies who slide down moonbeams are fun-loving daredevils. Therefore, it is false that no pixies who slide down moonbeams are fun-loving daredevils. Use the modified Venn diagram technique to...
-
It is false that some suicide survivors are comeback kids. Therefore, some suicide survivors are not comeback kids. Use the traditional square of opposition to determine whether the following...
-
Schooner means sort of like a sailboat. Criticize the following definitions in light of the eight rules for lexical definitions:
-
Determine the longitudinal tensile strength of the hybrid carbon/aramid/ epoxy composite described in Problem 3.4 and Figure 3.10 of Chapter 3 if the fiber packing array is square with the closest...
-
For the IM-9/8551-7 carbon/epoxy composite rod design of Problem 3.3 in Chapter 3, what would be the increase in the longitudinal tensile strength compared with that of the original 6061-T6 aluminum...
-
Assuming that the failure mode for longitudinal compression of unidirectional E-glass/epoxy with fiber volume fraction \(v_{\mathrm{f}}=0.6\) is a transverse tensile rupture due to Poisson strains,...
Study smarter with the SolutionInn App