Thursday, January 30, 2014

Tuesday, January 28, 2014

Calculus review: integration II

3) Trig substitutions
Often an integrand can be much simplified by a trigonmetric identity, such as $$\sin ^2 +\cos^2=1,$$ or $$1+\tan^2=\sec^2.$$  For instance, consider the integral

$$\int_a^b \frac{dx}{\sqrt{1-x^2}}.$$

We know that $$1-\sin^2=\cos^2,$$ so what if we let $$x=\sin \theta?$$

We then have the squareroot as cos, and $$dx=\cos \theta d\theta,$$ so our integral is now

$$\int_{\arccos a}^{\arccos b}\frac{\cos\theta d\theta}{\cos\theta}.$$

Simplifying, we get
$$\int_{\arccos a}^{\arccos b}d\theta=\theta \bigg |_{\arccos a}^{\arccos b}.$$

Done.

Let's try another one.  What if we want to do

$$\int _a^b \frac{dx}{1+x^2}?$$

Let's try letting $$x=\tan\theta,$$ which means $$dx=\sec^2\theta d\theta.$$  We then have

$$\int _{\arctan a}^{\arctan b} \frac{\sec^2\theta d\theta }{\sec^2 \theta}.$$  Simplifying, we get

$$\int _{\arctan a}^{\arctan b}d\theta=\theta\bigg| _{\arctan a}^{\arctan b}.$$

Done.  Notice that, as with integrating by substitution, you have to remember to calculate dx and also change the limits of integration.

4) Partial fractions
Suppose we want to integrate what is called a rational function: a ratio of two polynomials.  For instance,
$$\int \frac{x^3+2x^2-x}{x^2-1}dx.$$

We might first think of making a substitution either with $$u=x^2-1$$ or perhaps a trig substitution, but we end up being better served if we notice that the integrand can be written as

$$\frac{x^2}{x-1}+\frac{x}{x+1}.$$  We can then integrate the first term of this sum using the substitution $$u=x-1,\;du=dx:$$
$$\int\frac{x^2}{x-1}dx=\int \frac{(u+1)^2}{u}du=\int \frac{u^2+2u+1}{u}du.$$

Dividing all of the terms by u gives us
$$\int \big[u+2+\frac{1}{u}\big]du,$$

which can easily be integrated.  The second term of the sum can be integrated with the substitution $$u=x+1,\;du=dx.$$

What we have done here is decomposed one fraction into a sum of fractions: basically, reversed what you do when you add fractions and find the least common denominator.  This technique is called partial fractions.  Usually you can just reconstruct the form you need with a bit of guess and check, by writing the numerators of the terms in the decomposition as a+bx and c+dx, for instance, and solving for a, b, c, and d by adding the terms and demanding equality of the coefficients of each power of x with the original fraction.




Calculus review: integrals

An integral is very similar to a sum.  If a curve is described by a function, the integral of that function between two x values gives you the area under it on a graph.  There are many approximation schemes for integrals that just compute them as sums, such as Midpoint Rule, Trapezoid Rule, or Simpson's Rule.  Integration is also the inverse operation of differentiation: taking the derivative and then the integral of a function gets you back the original function.

Here, we are going to assume some familiarity with integration and remind the rusty among you of how to do a bit more . . .

The most basic functions can be integrated just by remembering the derivative formulae and inverting.  For instance,
since $$\frac{d x^n}{dx}=nx^{n-1},$$ if we want to integrate $$x^m,$$ we can let $$m=n-1$$ and see that  $$\frac{1}{n}\frac{d x^n}{dx}=x^{n-1}$$ and replace n-1 with m to see that
$$\int x^m=\frac{1}{m+1}x^{m+1}.$$  We can then check by differentiating: we get $$x^m,$$ so all's well that ends well!

$$e^x,\;\sin x,\;\rm{and}\;\cos x$$ can all be handled using this principle too.

For more complicated functions, there are five major techniques, which we'll look at in increasing order of complexity.
1) Integration by substitution
2) Integration by parts
3) Trig substitution
4) Partial fractions
5) Gaussian integrals
6) Completing the square in Gaussian integrals

1) Integration by substitution
Given a composition of functions, it is often convenient to define a new variable for the inner function.  For instance, let's compute
$$\int_a^b \big[ 1+x\big]^2dx$$
by defining $$u=1+x,$$ $$du=dx.$$
We then have
$$\int_{1+a}^{1+b} u^2 du=\frac{u^3}{3}\bigg|_{1+a}^{1+b}$$
Notice a few things:
a) we have replaced the limits of integration: if x runs from a to b, u=1+x runs from 1+a to 1+b.
b) we have replaced dx with dx=du: in general, we need to differentiate u and solve algrebraically for dx in terms of du, and then replace dx with its value in terms of du.

Let's do a harder example:
$$\int_a^b \big[1+2x \big]^{1/2}dx.$$
Let $$u=1+2x,\;du=2dx$$ so that
$$dx=\frac{du}{2}.$$
We then find
$$\int_{1+2a}^{1+2b} \frac{u^{1/2}}{2}du=\frac{u^{3/2}}{2}\bigg|_{1+2a}^{1+2b}.$$

To do these without making a mistake, it's good to go step by step.  First, write out clearly what u equals and then du = . . . dx, and solve carefully for dx.  Then make these replacements in the integral.  After that, make sure to change the bounds of integration to have the right range for the new variable!

2) Integration by parts
Often an integrand is of the form of a product of two functions, one of which is has a simple integral.  How do we handle these cases?  Write the integral as
$$\int u dv$$ where dv is the function that has a simple integral.  We then have the formula
$$\int_a^b u dv=uv\bigg|_a^b-\int_a^b v du.$$  Try differentiating this formula to prove it is the correct integral of u dv:
$$\frac{d}{dx}\big[uv\big|_a^b-\int_a^b v du\big]=u \frac{dv}{dx}+v\frac{du}{dx}-v\frac{du}{dx}.$$

Let's try an example.  Conveniently, this example will turn out to give us a useful formula for the integral of natural log.

$$\int \ln x dx=\int 1 \cdot \ln x dx.$$

We don't know how to integrate $$\ln x,$$ so we better not have it be our dv.  But we do know how to integrate $$1dx:$$ that's just x!  So we set
$$u=\ln x,\;dv=1dx.$$

We then have
$$\int \ln x dx=x \ln x - \int \frac{x}{x}dx=x\ln x -x.$$

This is great because we now have a general technique for integrating any power of x against natural log.  Let's try x:

$$\int x \ln x dx=\int \ln x dx=\frac{x^2}{2} \ln x - \int \frac{x^2}{2x}dx=\frac{x^2}{2}\ln x -\frac{x^2}{4}.$$

Try deriving the formula for $$\int x^n \ln x dx$$ yourself!

Another integral commonly evaluated using integration by parts is $$\int x^n e^x dx,$$ where n is a positive whole number.  Here things get a little trickier.  We want to eventually lower the integrand to involve only $$e^x$$ and no powers of x, so we need to do something that lowers the power of x each time we do it.  This suggests letting $$u=x^n,$$ because $$du=nx^{n-1}.$$  We then have

$$\int x^n e^x=x^n e^x-\int nx^{n-1}e^xdx.$$  We can then integrate the integral by parts again to reduce the power of x by one more, and keep doing so until we get the integrand to be $$e^x,$$ which we know how to integrate.


Calculus review: derivatives

In the excellent novel The Poisonwood Bible, the self-taught main character says that "Calculus is the mathematics of change."  Heraclitus, an ancient Greek philosopher, wrote that "Change is the only constant," (and has been unwittingly quoted by many motivational speakers since), and so calculus is ubiquitous in mathematical descriptions of nature.  Calculus intrinsically is neither easy nor hard: it's just a language---becoming fluent requires practice.  The focus of this course will be to do things in the least mathematical way possible, so don't get too stressed about calculus, but it is a good thing to have in one's toolkit moving forwards.

Derivatives
A derivative just describes how much one quantity changes as you vary another quantity that it depends on.  Graphically, if you have a curve, the derivative at a point gives the slope of the line touching the curve (tangent) at that point.  Here we'll just describe how to compute most of the cases you'll ever need.

Formula
$$\frac{d}{dx}x^n=nx^{n-1}$$
Proof
Use definition of derivative as the limit of a difference:
$$\frac{d}{dx}x^n=\lim_{\Delta x\to 0}\frac{(x+\Delta x)^n-x^n}{\Delta x}.$$
Since we are taking the limit as $$\Delta x\to 0,$$ we can treat it as very small compared to $$x,$$ and rewrite the above as
$$\lim_{\Delta x\to 0}\frac{x^n(1+\Delta x/x)^n-x^n}{\Delta x}\approx \lim_{\Delta x\to 0}\frac{n x^n\Delta x/x}{\Delta x}$$
$$=nx^{n-1}.$$

The approximate equality comes from using the "most useful approximation ever" we showed in the Basic Math Review:
$$\big[1+\epsilon\big]^n\approx 1+n\epsilon.$$

Formula
$$\frac{d}{dx}e^x=e^x$$
Proof
Write
$$e^x=\sum_{n=0}^{\infty}\frac{x^n}{n!}$$ and differentiate each term using the previous formula to find
$$\frac{d}{dx}e^x=\sum_{n=1}^{\infty}\frac{x^{n-1}}{(n-1)!}+0$$
where the 0 comes from the $$n=0$$ term in the original series, which has derivative zero.
Then re-index the sum to again start at 0, by transforming $$n-1\;\rm{to}\;n.$$  The result then follows.

Note: the formula for e as a sum above is super-useful! 
It immediately gives you the approximation for e at small x by just dropping terms that are quadratic or above in x:
$$e^x\approx 1+x$$
as well as an approximation for $$\ln\big[1+x\big]$$
by taking the natural log of both sides of $$e^x\approx 1+x$$
to get
$$x\approx \ln\big[1+x\big]$$ for small x.

Incidentally, the series for e can also be used, by comparison with the series expansions for sine and cosine, to prove Euler's formula! (substitute in $$x=i\theta$$ and just algebra it out!)

Chain Rule
A very useful way to do derivatives of compositions of functions.  What is a composition of functions?  Well, $$\big[1+x\big]^2$$ is one example!  Inside the brackets, you take x to 1+x.  That's one function:
$$f(x)=1+x.$$  Then outside the brackets, you take that function, f, to its square: $$g(f)=f^2.$$
So we can write the initial expression as g of f.  What if we want to do the derivative of something of that form?  It is
$$\frac{d}{dx}\big[g\circ f\big]=\frac{dg}{df}\frac{df}{dx}$$
An easy way to remember this is to imagine the df's canceling out, much like how one would write out unit conversions, e.g. meters to feet as $$1\; \rm{m} \times \frac{3\;\rm{ft}}{\rm{m}}=3\;\rm{ft}.$$  We won't prove this formula here---maybe you can think of a proof!

Formula
$$\frac{d\ln x}{dx}=\frac{1}{x}$$
Proof
Write x as
$$x=e^{\ln x},$$ which is true by the definition of ln.  Then differentiate both sides, using Chain Rule for the righthand side:
$$1=e^{\ln x}\frac{d\ln x}{dx}.$$
Then simplify using that $$e^{\ln x}=x,$$ and divide both sides by x:
$$\frac{1}{x}=\frac{d\ln x}{dx}.$$

Formula
$$\frac{d\sin x}{dx}=\cos x,\;\frac{d\cos x}{dx}=-\sin x.$$
Proof
Use Euler's formula to write sin and cos as complex exponentials.
Then
$$\frac{d\sin x}{dx}=\frac{d}{dx}\bigg(\frac{1}{2i}\big[e^{ix}-e^{-ix}\big]\bigg)=\frac{1}{2i}\big[ie^{ix}+ie^{-ix}\big].$$
The second equality above is using Chain Rule to differentiate $$e^{ix}.$$
Simplifying the righthand side, we have
$$\frac{1}{2}\big[e^{ix}+e^{-ix}\big]=\cos x.$$
It's nearly the same to compute the derivative of cos: try it for yourself!


Basic math review

Here we aim to go over some math things that will be useful in the course.  This is by no means exhaustive, and some of the things below may not come up.  But we hope this will be a useful place to turn as a first quick resource if you're feeling a little rusty . . .

Fraction division
To divide one fraction by another, remember: Kentucky Chicken Fried (Keep Change Flip):

$$\frac{a}{b}\div \frac{c}{d}=\frac{a}{b}\times\frac{d}{c}$$

Geometry
Area of a triangle =  $$\frac {1}{2}\rm{base}\times\rm{height}$$
Area of a circle = $$\pi r^2$$
Circumference = $$2\pi r$$
Volume of a sphere = $$\frac{4}{3}\pi r^3$$

Differential volume in spherical coordinates $$dV=r^2 dr \sin \theta d\theta d\phi$$
If the function you are integrating against this differential volume is angle-independent, you can use
$$dV=4\pi r^2 dr$$

Finally, notice that if you integrate the above over r from 0 to R, you get
$$\int dV = 4\pi \int_)^R r^2 dr=\frac {4\pi}{3}R^3$$
---the volume of a sphere!  And if you ever forget what dV is, just take the expression for the volume of a sphere and differentiate to get dV for a spherically symmetric problem.

Trigonometry
Just comes from the Greek for "triangle measuring": so any time a triangle shows up in a problem, you probably want to think trig.

Mnemonic for sine, cosine, tangent: SOHCAHTOA, or "Some Old Horse Caught A Horse Taking Oats Away"---meaning,

Sine = Opposite/Hypotenuse
Cosine = Adjacent/Hypotenuse
Tangent = Opposite/Adjacent

and recall that 1/Sine = Cosecant (abbreviated Csc)
and . . .           1/Cosine = Secant (abbreviated Sec)
Finally, . . .     1/Tangent = Cotangent (abbreviated Cot)

More advanced trigonometry
Euler's formula: $$e^{i\theta}=\cos\theta+i\sin\theta$$ with $$i=\sqrt{-1}$$

This formula can be used to write
$$\sin \theta =\frac{1}{2i}\big[e^{i\theta}-e^{-i\theta}\big]$$
and
$$\cos \theta =\frac{1}{2}\big[e^{i\theta}+e^{-i\theta}\big]$$

Notice that if you flip the sign of the angle, sine changes sign (punny?), while cosine does not---that is no surprise, because we know that sine is an odd function and cosine is an even one.

Euler's formula is great because you can also use it to quickly derive the double-angle formulae for sine and cosine:

$$(\sin \theta)^2=\frac{1}{2i}\big[e^{i\theta}-e^{-i\theta}\big]^2$$
$$=-\frac{1}{4}\big[e^{i2\theta}+e^{-i2\theta}-2\big]$$
$$=\frac{1}{2}\big[1-\cos2\theta \big]$$

Working through similar math for cosine:
$$(\cos \theta)^2=\frac{1}{2}\big[e^{i\theta}+e^{-i\theta}\big]^2$$
$$=\frac{1}{4}\big[e^{i2\theta}+e^{-i2\theta}+2\big]$$
$$=\frac{1}{2}\big[\cos2\theta+1\big]$$

Now notice that adding these results together gives
$$\sin^2\theta+\cos^2\theta=1$$
---hopefully a familiar identity!  It's really just the Pythagorean theorem applied to a triangle with hypotenuse 1, because by the definitions of sine and cosine, the legs of the triangle will be sine and cosine if the hypotenuse is 1.

Finally, note that you can even use Euler's formula to get formulae relating higher powers of sine and cosine to higher multiples of the angle, e.g. $$\sin^3\theta$$ in terms of $$\sin 3\theta,$$ for instance.  You would just use the Binomial Theorem to expand the binomial (two terms added together)
$$\big[e^{i\theta}\pm e^{-i\theta}\big]^n$$ out, and then simplify, just like we did for $$n=2$$ above.

Most useful approximation ever
90% of astrophysics problems involving two terms taken to a power can be handled using what's below.
Suppose you have something of the form
$$\big[1+\epsilon\big]^n,$$
where $$\epsilon\ll 1.$$
Using the Binomial Theorem to expand this out, you'd get
$$1+n\epsilon +\rm{tems\;in\;higher\;powers\;of\;\epsilon}.$$
Because $$\epsilon\ll 1,$$
all these higher powers can just be neglected, since taking anything less than 1 to a power makes it smaller, the higher the power the smaller.
So we have
$$\big[1+\epsilon\big]^n\approx 1+n\epsilon.$$
Note that in astrophysical problems you often may have to factor out something to get a 1 in the first term, and can then apply this expansion. For this reason it's always good to consider the relative scales of any two quantities that have the same dimensions.





Monday, January 27, 2014

Week 1 assignments


Hi, everyone!  Just a note on week 1 assignments: the lab activity we did today should be written up as one of the blog posts for this week.  It is labeled "worksheet," but it's really a lab, so you should write up the whole thing, not just 1 or 2 parts of it!

Great work in class today and see you Thursday!  We'll also be putting up some information on how to use MathJax to get Latex (a way to typeset equations and math symbols) in blogger, so check back soon!

Welcome!

Welcome!  This blog will be an additional source for Harvard's astronomy 16 class, taught by Professor John Johnson with assistance from Luke, Marion, and Zack.  We'll be doing posts on a variety of topics here, from sample problem write-ups to useful supplemental material.  Check out our first post, a review of basic math that may be helpful as you get into the course.  And check back regularly!  We welcome feedback and post ideas at harvardastro16@gmail.com, and you can also reach us individually at the emails given on the syllabus!

with best wishes for the course,
Professor Johnson, Marion, Luke, and Zack