Computational dynamics: modeling the dynamics of a car Prof. Eric Darve Homework 1 Total number of points = 75. Problem 1: Linear first order ODEs 15 points. Find the general solution for the following ODEs. Show your work. 1. 𝑦 ′ + 𝑦 = 4𝑥. 2. 𝑦 ′ + 2𝑥𝑦 = 2𝑥. 3. 𝑦 ′ + 3𝑦 = 10 cos(𝑥). Problem 2: Particular solutions 10 points. Find the particular solution for the following ODEs. Show your work. 1. 𝑦 ′ + 𝑦 = 2, 𝑦 (0) = 3. 2. 2𝑦 ′ + 𝑦 = 𝑥 2 , 𝑦 (0) = 7. Problem 3: Second order ODEs 20 points. Convert the following 2nd order ODEs to a system of first-order ODEs. The functions in the first-order ODEs should be denoted by 𝑦1 , 𝑦2 , . . . , 𝑦𝑛 . When writing down the system, the left-hand sides should be equal to 𝑦𝑖′ while the right-hand sides should be functions of 𝑦1 , . . . , 𝑦𝑛 . Example: 𝑦 ′′ + 𝑦 = 1 should be converted to: 𝑦1′ = 𝑦2, 𝑦2′ = −𝑦1 − 1, where we have set 𝑦1 = 𝑦 and 𝑦2 = 𝑦 ′. 1. 𝑦 ′′ = 𝑡𝑦. 2. 𝑦 ′′ + 𝑦 = 𝑡 2 + ln(1 + 𝑡) (𝑦 ′) 2 . 3. 𝑧 1′′ + 𝑧 1 + 𝑧 2 = 𝑡, 𝑧 2′′ + (𝑧 1′ ) 2 = 𝑧 2 . Hint: for this question you will need 4 functions 𝑦1 , . . . , 𝑦4 . Set 𝑦1 = 𝑧 1 and 𝑦2 = 𝑧 2 . 4. 𝑧 1′′ = cos(𝑧 2 ), 𝑧 2′′ + 𝑧 2′ = 𝑡. Problem 4: Python functions and for loop 10 points. The Fibonacci sequence satisfies: 𝑓𝑛+2 = 𝑓𝑛+1 + 𝑓𝑛 , 𝑓0 = 0, 𝑓1 = 1 Write a function fibonacci that takes as input an integer n and returns a numpy array f with entries [𝑓0, . . . , 𝑓𝑛 ]. This function should use a for loop to calculate the Fibonacci sequence f. Bonus: the entries in the numpy array f should have type np.int64 instead of the default np.float64. Page 1 Computational dynamics: modeling the dynamics of a car Prof. Eric Darve Call your function using 𝑛 = 30. Print and turn in the output. Calculate as well 𝜙 𝑛 − (−𝜙) −𝑛 , 𝑔𝑛 = √ 5 √ 1+ 5 𝜙= 2 What do you observe? Turn in your code and the output. Problem 5: Python classes 10 points. Write a Python class for complex numbers. This Python class should have a method __init__ which takes as argument two floats, the real and imaginary parts. Implement a method __repr__ which can be used to print the number. Implement a method __add__ and __mul__ to add and multiply two complex numbers. Test your methods on several examples to make sure they work correctly. Turn in your code and the results of your tests. Problem 6: Plotting functions using Plotly 10 points. Use Plotly to plot the functions 𝑦1 (𝑥) = cos(4𝑥) exp(−𝑥) and 𝑦2 (𝑥) = sin(4𝑥) exp(−𝑥) for 𝑥 ∈ [0, 4] on the same figure. Label the 𝑥 and 𝑦 axes. Add a title to your plot and include a legend. Turn in your code and the plot. Page 2