python and mathematics

Math 382 Homework 7 [corrected]
Total 60 Points
1. Write a python functioncobweb(f, x0, n, xmin, xmax, ymin, ymax)to draw a cobweb
plot of xed point iteration, where
f name of function to plot.
x0 starting point value of x.
n number of xed point iterations.
xmin minimum value for x-axis on plot
xmax maximum value for x-axis on plot
ymin minimum value for y-axis on plot
ymax maximum value for y-axis on plot
This is a reminder of what a typical cobweb plot looks like (not for the function you are
working with though, so your cobweb will look di erent).
Demonstrate that your cobweb plot works with the function call
cobweb(cos, 1.0, 200,0, 1.5, 0, 1)
2. Explore the convergence of the logistic map using your cobweb plot.
Run the function you wrote in problem 1 using the functionf(x) = rx(1 x) by de ning
the following three functions in python:
f(x) r*x*(1-x)
g(x) f(f(x))
h(x) f(f(f(x))
In particular, explore what happens by plotting the cobwebs for values of r as it varies from
3.8 to 3.85. You may need to make 20 to 30 plots over this region and compare them as r
is varied to see what is happening. First look at F, then G, then H. What do you think
is happening, and why do you think it is happening? Is there some range of values it is
occurring over? You will be graded on how you justify your answer.
1
3. The Fourier series of a functionf(x) on an interval [0;P] is given by
F(x)
a

2
+
n X
k=1

a
n
cos

2kx
P

+b
n
sin

2kx
P

(1)
where
a
0=
2
P
Z
P

f(x)dx (2)
a
k=
2
P
Z
P

f(x) cos

2kx
P

dx; k1 (3)
b
k=
2
P
Z
P

f(x) sin

2kx
P

dx (4)
(a) Write a python functionfouriercoefficients(f, P, n)that will return two listsa
andbcontaining the coecients[a

;a
1
;a
2
;:::;a
n
]and[0;b
1
;b
2
;:::;b
n
]respectively.
You may use the following code to nd the integral
Z
xmax
xmin
f(x)dx:
def trapez_integration(f, xmin,xmax, n=1000):
h=(float(xmax)-float(xmin))/float(n)
xvals = [xmin+i*h for i in range(n+1)]
fvals = [f(x) for x in xvals]
integral=0.5*h*sum( [p+q for p,q in zip(fvals[1:], fvals[:-1])] )
return integral
(b) Using the function f(x) = 1 xandP= 1, plot the Fourier series forF(x) on the
interval [ 1;2] usingn= 5;10;25 and 100. What do you observe asnbecomes larger?
The squiggles that remain near the discontinuities are called Gibb’s phenomenon.

READ ALSO :   Copyright

PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET AN AMAZING DISCOUNT 🙂