Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to solve it using python? 2. (6 points) Write a function called damping whic

ID: 3700115 • Letter: H

Question

How to solve it using python?

2. (6 points) Write a function called damping which takes input parameters m, b, k, F, u0, to, tf and N. The function uses scipy.integrate.odeint to compute a numerical approximation of the corresponding solution of the nonlinear damping equation: The input parameters are: o m, b and k are positive numbers in the nonlinear damping equation o F is a function of one variable F(t) in the nonlinear damping equation o uO is a list of numbers of length 2 defining the initial conditions [y(to),y(to)] o to is the start of the interval of integration [to,tl o tf is the end of the interval of integration [to, tfl o N is an integer specifying the number of evenly spaced points from to to ty (inclusively) over which to compute the solution The function damping plots the approximation of the solution y(t) and returns a 2D Numpy array with 2 columns: o column at index 0 is the array of N evenly spaced t values from to to ty (inclusively) o column at index 1 is the array of y values of the solution

Explanation / Answer

import scipy.integrate as sc import numpy as np import matplotlib.pyplot as plt def damping(m,b,k,F,u0,t0,tf,N): t=np.linspace(t0,tf,N) def ode(y,t,m,b,k,F): y1,y2=y Dydt=[y2,1/(m)*(F(t)-k*y1-b*y2*abs(y2))] return Dydt sol=sc.odeint(ode,u0,t,args=(m,b,k,F)) sol=np.column_stack([t,sol[:,1]]) plt.plot(sol[:, 0], sol[:, 1]) plt.show() return sol

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote