CoCalc Public Filesgrading-guidelines / DUE-2016-04-29-grading-guidelines / Guidelines and sample solution.sagewsOpen in with one click!
Author: John Jeng

Math 480 - Homework 4: Due 6pm on April 29, 2016

HOMEWORK TOTAL: 100 POINTS

GRADING GUIDELINES

For this homework assignment:
  • Take off 5 points if they did not use `show()` as in the directions.
  • Grade points for each question based on output. Check if output is similar to this solution guide.
  • If they typed the wrong function for a problem but their procedure looks correct, only take off points for having the wrong function.
  • Award half credit to any part where they did not use Sage (ie. they solved by hand and typed the result in)

Problem 1 -- defining and evaluating a function:

  1. Define in Sage f(x)=sinh(x2+x1)+eπx+arcsin(x)+1x3xef(x) = \sinh(x^2+\sqrt{x-1}) + e^{\pi x} + \arcsin(x) + \frac{1}{x^3-x-e}.
  2. Compute f(1/2)f(1/2) symbolically (exactly).
  3. Compute f(1/2)f(1/2) numerically (so a decimal expansion).
  4. Plot f(x)f(x) from 1-1 to 11.

10 Points Total

2 points per part; 2 points for completion

f(x) = sinh(x^2 + sqrt(x-1)) + e^(pi*x) + arcsin(x) + 1/(x^3 - x - e) show(f) show(f(1/2)) show(N(f(0.5))) complex_plot(f, (-1, 1), (-1, 1))
x  1x3xe+arcsin(x)+e(πx)+sinh(x2+x1)\displaystyle x \ {\mapsto}\ \frac{1}{x^{3} - x - e} + \arcsin\left(x\right) + e^{\left(\pi x\right)} + \sinh\left(x^{2} + \sqrt{x - 1}\right)
16π88e+3+e(12π)+sinh(12+14)\displaystyle \frac{1}{6} \, \pi - \frac{8}{8 \, e + 3} + e^{\left(\frac{1}{2} \, \pi\right)} + \sinh\left(\sqrt{-\frac{1}{2}} + \frac{1}{4}\right)
5.20284206077875+0.670044049132845i\displaystyle 5.20284206077875 + 0.670044049132845i
%html <font color="red"><h2>10 Points Total</h2> <h4>2 points per part; 2 points for completion</h4> </font>

Problem 2 -- finding zeros numerically:

Let f(x)=x2+sin(x)f(x) = \displaystyle x^2 + \sin(x)

  1. Draw a plot of ff on the interval [2,2][-2,2].
  2. Differentiate ff
  3. Integrate ff
  4. Find all the zeros of f(x)f(x) numerically.

10 Points Total

2 points for parts 1, 2, and 3. 4 points total for part 4 (2 points per root)

f(x) = x^2 + sin(x) plot(f, -2,2) show(diff(f, x)) show(integrate(f, x)) f.find_root(-2,-1/2) f.find_root(-1/2,1/2) # (use brain) no other zeros because $x^2$ is big.
x  2x+cos(x)\displaystyle x \ {\mapsto}\ 2 \, x + \cos\left(x\right)
x  13x3cos(x)\displaystyle x \ {\mapsto}\ \frac{1}{3} \, x^{3} - \cos\left(x\right)
-0.8767262153950622 5.78218635220173e-23

Problem 3 -- The Cauchy Distribution

Let  f(x; x0, γ)=1πγ[γ2(xx0)2+γ2]\displaystyle\space f(x;\space x_0,\space\gamma) = \frac{1}{\pi\gamma}\left[\frac{\gamma^2}{(x - x_0)^2 + \gamma^2}\right]

  1. Plot and find the area under the curve of f([2,2])f([-2, 2]) for the following values of x0x_0 and γ\gamma on the interval x=[4,4]x = [-4,4]
  • x0=0,γ=1x_0 = 0,\hspace{3mm} \gamma = 1
  • x0=2,γ=2x_0 = 2,\hspace{3mm} \gamma = 2
  • x0=0,γ=0.5x_0 = 0,\hspace{3mm} \gamma = 0.5
  1. Integrate ff from -\infty to xx using the dummy variable tt as in f(t; x0, γ)f(t;\space x_0,\space\gamma).
  2. Plot the resulting function from 3 for x0=0,γ=0.5x_0 = 0,\hspace{3mm} \gamma = 0.5.

10 Points Total

6 points for part 1 (1 for each plot, 1 for each value)

3 points for part 2

1 points for part 3

# 1a. gamma = 1 x_0 = 0 f(x) = 1/(pi*gamma) * (gamma^2/((x - x_0)^2 + gamma^2)) p = plot(f, -2, 2, fill=True) + plot(f, -4, 4) show(p) show(N(integral(f(x), x, -2, 2))) show(integral(f, x, -2, 2))
0.704832764699133\displaystyle 0.704832764699133
2arctan(2)π\displaystyle \frac{2 \, \arctan\left(2\right)}{\pi}
# 1b. gamma = 2 x_0 = 2 f(x) = 1/(pi*gamma) * (gamma^2/((x - x_0)^2 + gamma^2)) p = plot(f, -2, 2, fill=True) + plot(f, -4, 4) show(p) show(N(integral(f, x, -2, 2))) show(integral(f, x, -2, 2))
0.352416382349567\displaystyle 0.352416382349567
arctan(2)π\displaystyle \frac{\arctan\left(2\right)}{\pi}
# 1c. gamma =0.5 x_0 = 0 f(x) = 1/(pi*gamma) * (gamma^2/((x - x_0)^2 + gamma^2)) p = plot(f, -2, 2, fill=True) + plot(f, -4, 4) show(p) show(N(integral(f, x, -2, 2))) show(integral(f, x, -2, 2))
0.844041739245261\displaystyle 0.844041739245261
2.0arctan(4)π\displaystyle \frac{2.0 \, \arctan\left(4\right)}{\pi}
f(t, x_0, gamma) = 1/(pi*gamma) * (gamma^2/((t - x_0)^2 + gamma^2)) F(t, x_0, gamma) = integral(f(t, x_0, gamma), t, -oo, x) show(F(t, x_0, gamma)) print "" plot(integral(f(t, 0, 1/5), t, -oo, x),-4, 4) print "Either plot is good." plot(integral(f(t, 0, 1/5), t, -oo, x))
γ(πγ2arctan(xx0γ)γ)2π\displaystyle \frac{\gamma {\left(\frac{\pi}{\gamma} - \frac{2 \, \arctan\left(-\frac{x - x_{0}}{\gamma}\right)}{\gamma}\right)}}{2 \, \pi}
Either plot is good.

Problem 4 -- a function with no elementary antiderivative:

Let f(x)=sin(x2)+exp(1/x)f(x) = \sin(x^2) + \exp(1/x)

  1. Draw a plot of ff on the interval [1/2,4][1/2, 4].
  2. Differentiate ff
  3. Integrate ff

10 Points Total

3 points per part, 1 point for completion

# 1 f(x) = sin(x^2) + exp(1/x) show(f) print "" plot(f, (1/2,4))
x  e1x+sin(x2)\displaystyle x \ {\mapsto}\ e^{\frac{1}{x}} + \sin\left(x^{2}\right)
# 2 f(x) = sin(x^2) + exp(1/x) show(diff(f, x))
x  2xcos(x2)e1xx2\displaystyle x \ {\mapsto}\ 2 \, x \cos\left(x^{2}\right) - \frac{e^{\frac{1}{x}}}{x^{2}}
# 3 f(x) = sin(x^2) + exp(1/x) show(integrate(f, x))
x  xe1x+116π((i+1)2erf((12i+12)2x)+(i1)2erf((12i12)2x)(i1)2erf(ix)+(i+1)2erf((1)14x))Ei(1x)\displaystyle x \ {\mapsto}\ x e^{\frac{1}{x}} + \frac{1}{16} \, \sqrt{\pi} {\left(\left(i + 1\right) \, \sqrt{2} \text{erf}\left(\left(\frac{1}{2} i + \frac{1}{2}\right) \, \sqrt{2} x\right) + \left(i - 1\right) \, \sqrt{2} \text{erf}\left(\left(\frac{1}{2} i - \frac{1}{2}\right) \, \sqrt{2} x\right) - \left(i - 1\right) \, \sqrt{2} \text{erf}\left(\sqrt{-i} x\right) + \left(i + 1\right) \, \sqrt{2} \text{erf}\left(\left(-1\right)^{\frac{1}{4}} x\right)\right)} - {\rm Ei}\left(\frac{1}{x}\right)

Problem 5: Limits

  1. Compute limx0sin(x)/x\lim_{x\to 0} \sin(x)/x
  2. Use Sage to verify that strange and amazing fact limx0(cosx)1/x2=1e\lim_{x\to 0} (\cos x)^{1/x^2} = \frac{1}{\sqrt{e}}.

10 Points Total

5 points per part

# Solutions show(limit(sin(x)/x, x=0)) show(limit(cos(x)^(1/x^2), x=0))
1\displaystyle 1
e(12)\displaystyle e^{\left(-\frac{1}{2}\right)}

Problem 6: Taylor Series

Let f(x)=sin(x2)f(x) = \sin(x^2)

  1. Find the 3rd degree taylor series, p3(x)p_3(x), of ff where x0=2πx_0 = 2\pi
  2. Plot the 10th degree taylor series p10(x)p_{10}(x) where x0=2πx_0 = 2\pi alongside ff
  • Plot on the interval x=[π,3π]x=[\pi, 3\pi]

10 Points Total

3 points for part 1

7 points for part 2

# 1 f(x) = sin(x^2) p_3(x) = taylor(f(x), x, 2*pi, 3) show(p_3)
x  43(2πx)3(8π3cos(4π2)+3πsin(4π2))(2πx)2(8π2sin(4π2)cos(4π2))4π(2πx)cos(4π2)+sin(4π2)\displaystyle x \ {\mapsto}\ \frac{4}{3} \, {\left(2 \, \pi - x\right)}^{3} {\left(8 \, \pi^{3} \cos\left(4 \, \pi^{2}\right) + 3 \, \pi \sin\left(4 \, \pi^{2}\right)\right)} - {\left(2 \, \pi - x\right)}^{2} {\left(8 \, \pi^{2} \sin\left(4 \, \pi^{2}\right) - \cos\left(4 \, \pi^{2}\right)\right)} - 4 \, \pi {\left(2 \, \pi - x\right)} \cos\left(4 \, \pi^{2}\right) + \sin\left(4 \, \pi^{2}\right)
# 2 f(x) = sin(x^2) p_10(x) = taylor(f(x), x, 2*pi, 10) P1 = plot(p_10(x), pi, 3*pi, ymax=2, ymin=-2) P2 = plot(f(x), pi, 3*pi, linestyle='--') show(P1 + P2)

Problem 7 - Gradient Vector Field:

  1. Compute the gradient of f(x,y)=3sin(x)2cos(2y)xyf(x,y) = 3\sin(x) - 2\cos(2y) - x - y.
  2. Plot the 2-dimensiona vector field defined by the gradient of ff in the rectangle 2x,y2-2 \leq x,y \leq 2.

10 Points Total

5 points for each part

f(x,y) = 3*sin(x) - 2*cos(2*y) - x- y show(f.gradient()) plot_vector_field(f.gradient(), (x,-2,2), (y,-2,2))
(x,y)  (3cos(x)1,4sin(2y)1)\displaystyle \left( x, y \right) \ {\mapsto} \ \left(3 \, \cos\left(x\right) - 1,\,4 \, \sin\left(2 \, y\right) - 1\right)

Problem 8 - Symbolic Sums:

  1. Compute n=1(1)nn\sum_{n=1}^{\infty} \frac{(-1)^n}{n}.
  2. Compute n=11n2\sum_{n=1}^{\infty} \frac{1}{n^2}.
  3. Compute n=11n3\sum_{n=1}^{\infty} \frac{1}{n^3} both symbolically (in terms of the Riemann Zeta function) and numerically.
  4. Compute n=11n4\sum_{n=1}^{\infty} \frac{1}{n^4}.
  5. Compute n=1ksin(n)\sum_{n=1}^k \sin(n).

10 Points Total

2 points per part

%var n show(sum((-1)^n/n, n, 1, oo))
log(2)\displaystyle -\log\left(2\right)
%var n show(sum(1/n^2, n, 1, oo))
16π2\displaystyle \frac{1}{6} \, \pi^{2}
%var n show(sum(1/n^3, n, 1, oo)) show(N(sum(1/n^3, n, 1, oo)))
ζ(3)\displaystyle \zeta(3)
1.20205690315959\displaystyle 1.20205690315959
%var n show(sum(1/n^4, n, 1, oo))
190π4\displaystyle \frac{1}{90} \, \pi^{4}
%var k show(sum(sin(n), n, 1, k))
cos(karctan(sin(1)cos(1))+arctan(sin(1)cos(1)))sin(1)(cos(1)1)sin(karctan(sin(1)cos(1))+arctan(sin(1)cos(1)))sin(1)2(cos(1)1)\displaystyle \frac{\cos\left(k \arctan\left(\frac{\sin\left(1\right)}{\cos\left(1\right)}\right) + \arctan\left(\frac{\sin\left(1\right)}{\cos\left(1\right)}\right)\right) \sin\left(1\right) - {\left(\cos\left(1\right) - 1\right)} \sin\left(k \arctan\left(\frac{\sin\left(1\right)}{\cos\left(1\right)}\right) + \arctan\left(\frac{\sin\left(1\right)}{\cos\left(1\right)}\right)\right) - \sin\left(1\right)}{2 \, {\left(\cos\left(1\right) - 1\right)}}

Problem 9 -- Unit Conversion:

Use Sage's units functionality (written by a UW undergrad -- David Ackerman!)

  1. Convert 68 degrees Fahrenheit to Celcius. Hint: use 68*units.temperature.fahrenheit to define fahrenheit.
  2. Convert 15 milliseconds to hours.
  3. Convert 2016 degrees kelvins to degrees Fahrenheit.
  4. Convert 9.8 meters per second squared to feet per second squared.

10 Points Total

2 points per part; 2 points for completion

# 1 a = 68*units.temperature.fahrenheit show(a.convert(units.temperature.celsius)) a.convert(units.temperature.celsius)
20celsius\displaystyle 20 \, \mathit{celsius}
20*celsius
# 4 a = 0.015*units.time.second show(a.convert(units.time.hour)) a.convert(units.time.hour)
(4.16666666666667×106)hour\displaystyle \left(4.16666666666667 \times 10^{-6}\right) \, \mathit{hour}
(4.16666666666667e-6)*hour
# 3 a = 2016*units.temperature.kelvin show(a.convert(units.temperature.fahrenheit)) a.convert(units.temperature.fahrenheit)
3169.13000000000fahrenheit\displaystyle 3169.13000000000 \, \mathit{fahrenheit}
3169.13000000000*fahrenheit
# 4 a = 9.8*units.length.meter/units.time.second^2 show(a.convert(units.length.feet/units.time.second^2)) a.convert(units.length.feet/units.time.second^2)
32.1522309711286(feetsecond2)\displaystyle 32.1522309711286 \, \left(\frac{\mathit{feet}}{\mathit{second}^{2}}\right)
32.1522309711286*(feet/second^2)

Problem 10 - 3d Plotting:

  1. Draw a 3d plot of a torus.
  2. Draw a single 3d plot the has the five regular polytopes in it: tetrahedron, cube, octahedron, dodecahedron, icosahedron. All five must be visible.
  3. Draw a 3d plot of the "Mexican hat function" (see, e.g., https://en.wikipedia.org/wiki/Mexican_hat_wavelet). [Hint: you have to make a choice of parameter σ\sigma so that it looks like Mexican hat.]

10 Points Total

Maximum 3 points per part. 1 point for completion

Based on:

  • Is it a torus?
  • Can you count the polytopes? -0.5 for each one you don't see.
  • Does it look like a hat? (it can be upside down)

u, v = var('u,v') f1 = (4+(3+cos(v))*sin(u), 4+(3+cos(v))*cos(u), 4+sin(v)) parametric_plot3d(f1, (u,0,2*pi), (v,0,2*pi), texture="red", mesh=2)
3D rendering not yet implemented
tetrahedron() + cube().translate((1,0,0)) + octahedron().translate((2,0,0)) + dodecahedron().translate((3,0,0)) + icosahedron().translate((4,0,0))
3D rendering not yet implemented
sigma = -1/2 f(x,y) = 1/(pi*sigma^4) * (1-((x^2+y^2)/(2*sigma^2)))*exp(-(x^2+y^2)/(2*sigma^2)) plot3d(f, (x,-2,2), (y,-2,2))
3D rendering not yet implemented