Question & Answer: a. Execute this example of a function definition: def h(x): return sum ([sin (n*x)/n for n in srange (1, 20.0)]) b. Evaluate h(x), a…..

a. Execute this example of a function definition def h(x): return sum (tsin(nx)/n for n in srange (1,20.0)1 b. Evaluate h(x), and plot h(x) for x between 0 and 4 pi. c. Define a function that is equal to 2*x for x>O,and equal to-3*x for x <O. Plot the function to verify it behaves correcetly. Hint you will need to use an if statement.) . a Make a modified version of the function below -rename it to Simp int, change the documentation (docstring) accordingly, and have it compute a numerical integral using Simpsons rule instead of the trapezoid rule. Simpsons rule is b. Show the output of the original function, your function, and the command integnate for(e)rom a 0 t 1, with 10 ubdivisions of the integration interval. def trap int (f, a,b,n) : - #7hetriple quotes indicate a multiline comment, or ,docstring. Trapezoid rule numerical integrater. Inputs: f: a function of one variable, x a: the lower endpoint of integration b: the upper endpoint of integration n: the number of subdivisions forces floating-point computation # the size of the x-axis increment nn float (n) delx = (b-a) /nn answer. delx*(f(x-a1+f(x-b))/2.0 # endpoints of sum ore weighted differently for i in range (1,n) thia loops over the interior of the su answer delxf(xa delx) return float (answer) 6. Use the plot slope_field command to sketch the logistic vector field corresponding to the ODE y-4*y - y), for t in (05) and y in (-1,2) 7. When your lab is complete, change the name (by clicking on it) of the lab to: Labl-Yourl astName-YourFirst Name. a- sqrt(3) print(nla, digits -100)) 1.7320508075688772935274463415058723669428052538103806280558069794519330 16908800037081146186757248576 )槨 Please code in sage or python

a. Execute this example of a function definition: def h(x): return sum ([sin (n*x)/n for n in srange (1, 20.0)]) b. Evaluate h(x), and plot h(x) for x between 0 and 4*pi. c. Define a function that is equal to 2* x for x > 0, and equal to -3*x for x

Expert Answer

 

from math import sin, pi
import matplotlib.pyplot as plt

def h(x):
return sum([sin(n*x)/n for n in srange(1, 20.0)])

def frange(start, stop, step):
res = []
x = start
while x < stop:
res.append(x)
x += step
return res

x = srange(0, 4*pi)
y = [h(i) for i in x]
plt.plot(x, y)

def myfunc(x):
if x > 0:
return 2*x
else:
return -3*x

x = frange(-3, 3, 0.1)
y = [myfunc(i) for i in x]
plt.plot(x, y)

# code link: https://paste.ee/p/cy6ay (please add your statement for importing srange or use my frange method)

Still stressed from student homework?
Get quality assistance from academic writers!