Starting from:

$29.99

Phys 512 Problem Set 1

Phys 512 Problem Set 1
Problem 1: We saw in class how Taylor series/roundoff errors fight against
each other when deciding how big a step size to use when calculating numerical
derivatives. If we allow ourselves to evaluate our function f at four points (x±δ
and x ± 2δ),
a) what should our estimate of the first derivative at x be? Rather than doing
a complicated fit, I suggest thinking about how to combine the derivative from
x ± δ with the derivative from x ± 2δ to cancel the next term in the Taylor
series.
b) Now that you have your operator for the derivative, what should δ be in
terms of the machine precision and various properties of the function? Show for
f(x) = exp(x) and f(x) = exp(0.01x) that your estimate of the optimal δ is at
least roughly correct.
Problem 2: Write a numerical differentiator with prototype
def ndiff(fun,x,full=False):
where fun is a function and x is a value. If full is set to False, ndiff should return
the numerical derivative at x. If full is True, it should return the derivative, dx,
and an estimate of the error on the derivative. I suggest you use the centered
derivative
f
0 '
f(x + dx) − f(x − dx)
2dx
Your routine should estimate the optimal dx then use that in calculating the
derivative. If you’re feeling ambitious, write your code so that x can be an array,
not just a single number. If you do that, you may actually wish to save your
code as you might use it in the future.
Problem 3: Lakeshore 670 diodes (successors to the venerable Lakeshore
470) are temperature-sensitive diodes used for a range of cryogenic temperature
measurements. They are fed with a constant 10 µA current, and the voltage is
read out. Lakeshore provides a chart that converts voltage to temperature, available at https://www.lakeshore.com/products/categories/specification/temperatureproducts/cryogenic-temperature-sensors/dt-670-silicon-diodes, or you can look
at the text file I’ve helpfully copied and pasted (lakeshore.txt). Write a routine
that will take an arbitrary voltage and interpolate to return a temperature. You
should also make some sort of quantitative (but possibly rough) estimate of the
error in your interpolation as well (this is a common situation where you have
been presented with data and have to figure out some idea of how to get error
estimates).
Your prototype should be:
def lakeshore(V,data):
1
where data is the output of:
dat=np.loadtxt(’lakeshore.txt’)
The columns of lakeshore.txt are 1) the temperature, 2) the voltage across
the diode at that temperature (which is what your experiment will actually
measure), and 3) dV/dT. You do not need to use the third column, but you
may if you wish.
Your code should support V being either a number or array, and it should
return the interpolated temperature, and your estimated uncertainty on the
temperature.
Problem 4: Take cos(x) between −π/2 and π/2. Compare the accuracy of
polynomial, cubic spline, and rational function interpolation given some modest
number of points, but for fairness each method should use the same points. Now
try using a Lorentzian 1/(1 + x
2
) between -1 and 1.
What should the error be for the Lorentzian from the rational function fit?
Does what you got agree with your expectations when the order is higher (say
n=4, m=5)? What happens if you switch from np.linalg.inv to np.linalg.pinv
(which tries to deal with singular matrices)? Can you understand what has
happened by looking at p and q? As a hint, think about why we had to fix the
constant term in the denominator, and how that might generalize.
2

More products