# MyOpenMath/Solutions/Big-O

An excellent introduction to this subject can be found at this document from web.mit.edu:
In this introduction to Big O notation, we solve two problems: one simple and the other so tricky I got a bit lost. The advantage of Big-O notation is that you can quickly "see" an answer without doing elaborate perturbation theory. Instead you just learn a few low order approximations for small $\epsilon$. A few examples are $\sin(\epsilon )\approx \epsilon$, $\cos \epsilon \approx 1-{\tfrac {1}{2}}\epsilon ^{2}$. All we need for this discussion is the first order approximation for $(1+\epsilon )^{p}$.

## Ruler misalignment

Have you ever pondered the fact that you can measure your height without carefully verifying that the ruler is perfectly vertical? In the language of Big O notation, if the actual height is $h$, the error is second order in the distance, $x$, between the actual and proper locations of the bottom of the ruler (see figure). To understand how this all works, begin with the Pythagorean theorem and express the erroneously measured height as:
$y={\sqrt {h^{2}+x^{2}}}=h\;\left(1+{\frac {x^{2}}{h^{2}}}\right)^{1/2}$
Advanced mathematics with numbers that have dimensions is best done by creating dimensionless variables, and this is especially true when analyzing approximations. A handy approximation is that whenever $\epsilon <<1$, we can write:
$(1+\epsilon )^{p}=1+p\epsilon +{\mathcal {O}}\epsilon ^{2}+...$.
Here the "big-O" informs us that the next term is proportion to $\epsilon ^{2}$. The ${\mathcal {O}}$-symbol allows us to avoid consideration of this term, while at the same time, preserve the location of these higher order terms, in case the calculation needs to be improved. We define, $\Delta y=y-h$, to be the error that arises from ruler misalignment. We presume that this error will be small ... but small compared with what? This problem has two large terms, $(h,y)$, and two small ones $(x,\Delta y)$. The big-O notation will help us sort things out. From the two equations displayed above:
${\frac {y}{h}}=1+{\frac {\Delta y}{h}}=1+{\frac {1}{2}}\left({\frac {x}{y}}\right)^{2}+{\mathcal {O}}\left({\frac {x}{y}}\right)^{4}$

#### Example

$x=0.1y$, then $\Delta y/h=.005$, which implies that:
A horizontal displacement of one end of ruler's length by ten percent will increase the measured height by approximately half of one percent.
This calculation is only an estimate that lacks a proper proof because higher order terms have been neglected. On the other hand, it is likely to be correct, since the next term in the expansion is of order $(x/y)^{4}\approx 10^{-4}=0.01\%$.

#### Defining the small parameter

This section might seem unnecessary, but the next calculation is so weird that it might help to discuss it here: Whether something is "first" or "second" order depends on you choose to define things. Here we have chosen,
$\epsilon ={\frac {x^{2}}{y^{2}}}$,
and we are working to "first order" in $\epsilon$, even though it is "second" order in $x/y$.

## Two slit diffraction with narrow slits
### When the screen is far from the slits

Problem: Two narrow slits are separated by 0.8 mm. The 15-th fringe appears 89 mm from the center of the diffraction pattern, and the screen is 9 m from the slits. What is the wavelength?
The standard textbook solution to this problem uses the formula, $n\lambda =d\sin \theta$, where :
$15\lambda ={\frac {0.8{\text{ mm}}\times 89{\text{ mm}}}{{\sqrt {9000^{2}+89^{2}}}{\text{ mm}}}}$$\Rightarrow \lambda \approx 527.4{\text{ nm}}$.
This solution is only valid when the distance to the screen, $L$ is much greater than the distance between the slits, $d$. In the next section we will derive an exact equation, and then use big-O notation to recover the standard formula in the limit that $d/L$ is small.
* To learn about two slit diffraction visit:
       OpenStax College Physics Chapter 27-3
       wikibooks:Waves/Double_slit_Diffraction
* To see a hand written solution on MyOpenMath visit:
       https://myopenmaths3.s3.amazonaws.com/ufiles/2556987/interference_question_ID_420941.pdf

### When the screen is not far from the slits

The wavelength and dimensions of the device in the previous section were chosen so that the simple formula would yield the correct answer. But how we solve the problem when the spacing between the slits is close to the distance to the screen. The geometry is shown in the figure to the right. It helps to define,
$R={\sqrt {L^{2}+y^{2}}},$ so that:
$r_{1}={\sqrt {L^{2}+(y-d/2)^{2}}}={\sqrt {R^{2}-yd+d^{2}/4}}$
$r_{2}={\sqrt {L^{2}+(y+d/2)^{2}}}={\sqrt {R^{2}+yd+d^{2}/4}}$
Note from the figure that $y/R=\sin \theta$, and that the two paths are effectively parallel when $d<<R$. The exact formula for the path difference is:
$\Delta r=r_{2}-r_{1}={\sqrt {T^{2}+yd}}-{\sqrt {T^{2}+yd}},$
where,
$T={\sqrt {L^{2}+y^{2}+{\frac {d^{2}}{4}}}}={\sqrt {R^{2}+{\frac {d^{2}}{4}}}}$
From the formulas stated without proof in the previous section, we are looking to show that:
$\Delta r\approx {\frac {yd}{R}}=d\sin \theta$.
We also seek insight into the nature of higher order correction terms in order to estimate when this simple formula is likely to be valid. The standard approach would be to perform a Taylor series expansion of the function $f(d)=\Delta r$, using $d$ as the variable. But in order to highlight big-O notation, we employ the aforementioned expansion:
$(1+\epsilon )^{1/2}=1+{\frac {\epsilon }{2}}+{\mathcal {O}}\epsilon ^{2}$.
Wright this expression with $\epsilon$ replaced by $-\epsilon$, and subtract the two:
$(1+\epsilon )^{1/2}-(1-\epsilon )^{1/2}=$$\left[1+{\frac {\epsilon }{2}}+{\mathcal {O}}\epsilon ^{2}\right]$$-\left[1-{\frac {\epsilon }{2}}+{\mathcal {O}}\epsilon ^{2}\right]$
When subtracting in the big-O notation, it is essential to realize that in general,
${\mathcal {O}}\epsilon ^{2}-{\mathcal {O}}\epsilon ^{2}={\mathcal {O}}\epsilon ^{2}\neq {\mathcal {O}}\epsilon ^{2}$
This is because ${\mathcal {O}}\epsilon ^{2}$ stands for $C\epsilon ^{2}$, where $C$ is some unknown constant. The difference between unknown constants is not usually zero. However in this case the exact cancellation of all even terms leaves us with an expression containing only terms that are odd in $\epsilon$:
$(1+\epsilon )^{1/2}-(1-\epsilon )^{1/2}=\epsilon +{\mathcal {O}}\epsilon ^{3}+...$
The absence of a second order term suggests that the first order term is likely to be sufficient for reasonably small values of $\epsilon$. The physics of this problem informs us that, $\Delta r=n\lambda ,$ so that we seek and expression for,
$\Delta r={\sqrt {T^{2}+yd}}-{\sqrt {T^{2}+yd}}=T\cdot \left[\,{\sqrt {1+\epsilon }}+{\sqrt {1-\epsilon }}\;\right]$,
We see here that our small parameter is,
$\epsilon ={\frac {yd}{T^{2}}}$
$\Delta r=\epsilon \cdot T+{\mathcal {O}}\epsilon ^{3}\cdot T={\frac {yd}{T}}+T\cdot {\mathcal {O}}\epsilon ^{3}$
One final task remains: Since since $y/R=\sin \theta ,$ we need to replace $yd/T$ = $yd/R$ (...plus small terms.) It is left as an exercise for the reader to show that:
${\frac {1}{T}}={\frac {1}{R}}\left\{1-{\mathcal {O}}\left({\frac {d^{2}}{4R^{2}}}\right)\right\}$
In other words, $T$ and $R$ are very close to each other, differing only at second order in our small parameter. Unless $\theta {\text{ is very close to }}\pi /2,$ the three lengths $T,R,{\text{and }}L$ are all of the same order and are not small:
${\mathcal {O}}T={\mathcal {O}}R={\mathcal {O}}L={\mathcal {O}}\epsilon ^{0}$
We also note that $yd/T={\mathcal {O}}\epsilon$, so that up to but not including third order, the difference in path length is:
$\Delta r={\frac {yd}{R}}\left[1+{\mathcal {O}}\epsilon ^{2}\right]\approx yd\sin \theta +...$,
which agrees with the formula found in most physics books.

#### Example

While not exact, the familiar formula for fringes when the screen is far away, the approximate formula, $n\lambda =d\sin \theta$, works surprisingly well for the screen close to the slits. Here, $[d,y,L]=[321,274,404]].$ The fringe number was $n=1$ (first maximum.)
Yet, the "small parameter" is not very small:
$yd/R^{2}\approx 0.37$.
The approximate formula for the first fringe is depicted in the figure as $\lambda _{1}$, which equals the length of the line segment, ${\overline {CD}}$.
The actual wavelength is $\lambda ={\overline {CE}}$. The point $E$ was by creating the (dotted) arc of length $r_{1}$, which intersect with line ${\overline {CP}}$, which has length $r_{2}$. The approximation,
$n\lambda _{1}=d\sin \theta$ .
yields,
$\lambda _{1}=180.18...=\lambda \times 1.037...$,
where,
$\lambda =173.66...$,
is the exact wavelength, calculated from:
$n\lambda ={\sqrt {{\sqrt {L^{2}+y^{2}+{\frac {d^{2}}{4}}}}+yd}}-{\sqrt {{\sqrt {R^{2}L^{2}+y^{2}+{\frac {d^{2}}{4}}}}+yd}},$

### Another approach

The big-O approach led us initially to a rather awkward small parameter,
$\epsilon ={\frac {yx}{T^{2}}}={\frac {yx}{R^{2}+x^{2}/4}}\approx {\frac {yx}{R^{2}}}+{\mathcal {O}}{\frac {x^{3}y}{R^{4}}}$
In other words, the convenient small parameter differs from the useful small parameter by a small parameter. Weird, huh?
We could also solve this problem with a Taylor series. In anticipation of doing differential calculus, we replace $d$ by $x$ as the variable to represent the distance between the slits. Now define the path length difference $\Delta r$ by the function $F$, where:
$F(x)={\sqrt {{\sqrt {R^{2}+{\frac {x^{2}}{4}}}}+yx}}-{\sqrt {{\sqrt {R^{2}+{\frac {x^{2}}{4}}}}-yx}}$
This looks like a lot of trouble, but symbolic software is available that can make this almost effortless. This expression also shows us why the big-O approach got into trouble. There are really two small dimensionless parameters lurking in this problem, and we can distinguish between them with subscripts:
$\epsilon _{R}={\frac {x^{2}}{4R^{2}}}{\text{, and }}\epsilon _{y}={\frac {yx}{R^{2}}}$,
so that
${\frac {\Delta r}{R}}={\sqrt {{\sqrt {1+\epsilon _{R}}}+\epsilon _{y}}}-{\sqrt {{\sqrt {1+\epsilon _{R}}}-\epsilon _{y}}}$
In other words we need to understand the function,
$f(x,y)={\sqrt {{\sqrt {1+x}}+y}}-{\sqrt {{\sqrt {1+x}}-y}}$,
when $x$ and $y$ are small. What I would do here is a two-dimensional expansion:
$f(x,y)=f_{0}+\left.{\frac {\partial f}{\partial x}}\right|_{0}x+\left.{\frac {\partial f}{\partial y}}\right|_{0}y+{\frac {1}{2}}\left.{\frac {\partial ^{2}f}{\partial x^{2}}}\right|_{0}x^{2}+{\frac {1}{2}}\left.{\frac {\partial ^{2}f}{\partial y^{2}}}\right|_{0}y^{2}+\left.{\frac {\partial ^{2}f}{\partial x\partial y}}\right|_{0}xy+...$