Math Equations
Monday, October 27, 2014
Elegant matrix inversion
To verify the result, note first that \(\mathbf{E}_n^2=n\mathbf{E}_n\). This identity can be seen as the workhorse of the method. Check that \(\mathbf{A}\mathbf{A}^{-1}=\mathbf{I}\).
\[\begin{align}\mathbf{A}_n^\phantom{-1}\hspace{-4pt}\mathbf{A}_n^{-1} &= (\mathbf{E}_n - \mathbf{I}_n)\left(\frac1{n-1}\mathbf{E}_n-\mathbf{I}_n\right) \\&= \frac n{n-1}\mathbf{E}_n-\mathbf{E}_n-\frac1{n-1}\mathbf{E}_n+\mathbf{I}_n = \mathbf{I}_n\end{align}\]
I'll have to think about this some more sometime. Can other simple matrices be inverted and expressed using matrix operations? What are some useful workhorses? Why has no one told me about this before?
Tuesday, August 12, 2014
Saturday, August 2, 2014
An open question
Saturday, July 26, 2014
The area of a triangle a, b, c
\[\small\begin{array}{l}
A = \sqrt{A^2}\\
\quad A^2 = \left(\frac{bh}{2}\right)^2 = \frac{b^2h^2}{4}\\
\quad\quad h^2 = \begin{cases} c^2-(c\cos{A})^2 \\ a^2-(b-c\cos{A})^2 \end{cases}\\
\quad\quad c\cos{A} = \frac{c^2+b^2-a^2}{2b}\\
\quad\quad h^2 = c^2 - \left(\frac{c^2+b^2-a^2}{2b}\right)^2 = \Pi\left(c \pm \frac{c^2+b^2-a^2}{2b}\right) = \Pi\frac{2bc \pm (c^2+b^2-a^2)}{2b}\\
\quad \begin{aligned}A^2 &= \cfrac{(2bc + (c^2+b^2-a^2))(2bc - (c^2+b^2-a^2))}{16} \\&= \cfrac{((b+c)^2-a^2)(a^2 - (b-c)^2)}{16} \\&= \cfrac{(b+c+a)(b+c-a)(a-b+c)(a+b-c)}{2\cdot2\cdot2\cdot2} \\&= \cfrac{a+b+c}{2}\cdot\cfrac{a+b+c-2a}{2}\cdot\cfrac{a+b+c-2b}{2}\cdot\cfrac{a+b+c-2c}{2} \\&= s(s-a)(s-b)(s-c)\end{aligned}\\
A = \sqrt{s(s-a)(s-b)(s-c)}
\end{array}\]
Sunday, June 22, 2014
A rational sinusoidal function
Monday, June 16, 2014
Ugliest sequence ever
Wednesday, June 4, 2014
Basic interpolation
Let the given points be \(\begin{array}{c}n\\(x_i, y_i)\\i=1\end{array}\) and let \(p_k\) denote the \(k\)th polynomial that we find. \(p_n\) is our final answer. \(p_k = \begin{cases}y_1 & \text{ if } k = 1\\ p_{k-1} + (y_k - p_{k-1}\bigg|_{x=x_k}) \prod_{i=1}^{k-1} \frac{x - x_i}{x_k - x_i} & \text{ if } 1 < k \leq n\end{cases}\).
Sunday, May 18, 2014
A fun fact about divisibility
Tuesday, April 22, 2014
A parametric curve
Are the points of the fractal the points of a parametric curve? At first I was convinced that they are not because the curve must be continuous. However, because all points are connected (by tangency) that's not a problem. Then came the constraint that the particle, which we imagine moving along the curve, must not come to rest, and after a lot of thinking I came up with the motion shown in the figure. The speed is inevitably infinite from time to time because the length of the curve is, and we just have to accept that, but it shouldn't ever be zero because it gets greater as the circles get smaller (by a factor of \(\frac{8}{1 + \sqrt2}\) which you'll be able to verify once I've shown you my definition of the curve).
It should be noted that the curve that I'm going to present does not have a velocity at the points of internal tangency (e.g. \(t = 0\)). Because the direction exists even at those points, I'm sure it is possible to remedy this by using a substitution \(u = g(t)\) where \(g\) is some increasing function that is piecewise differentiable.
OK, let's start. We'll be using complex numbers rather than vectors as values of \(\bar{r}\) because complex numbers are great for doing rotations. Furthermore we choose \(t \in I = [0, 1)\). Define the first iteration of the fractal parametric curve to be the unit circle \(\bar{r}_0(t) = \exp{(2\pi i \cdot t)}\). Then suppose we know how to draw the nth iteration and define the next iteration to be four copies of the current one scaled down to fit inside a new unit circle (which is also part of the new iteration):
\[
\bar{r}_{n+1}(t) =
\begin{cases}
\frac{\bar{r}_n(8t) + \sqrt2}{1 + \sqrt2} \enspace\mathrm{if}\, 0 \leq t < \frac{1}{8} \\
\exp{(2\pi i \cdot 2(t - \frac{1}{8}))} \enspace\mathrm{if}\!\,\, \frac{1}{8} \leq t < \frac{1}{4} \\
i \bar{r}_{n+1}(t-\frac{1}{4}) \enspace\mathrm{if}\!\,\, \frac{1}{4} \leq t < 1
\end{cases}
\]
(The \(1 + \sqrt2\) comes from the ratio between two successive radii and can be found trigonometrically.)
By induction, we know what all iterations look like. To get \(\bar{r}(t)\), we take the limit \(\bar{r}_n(t)\) as \(n \to \infty\). The limit exists because I've set it up so that in most cases \(\bar{r}_n(t) = \bar{r}_{n+1}(t)\) ultimately. In the cases where that's not true, the value will be enclosed by \(n+1\) circles with exponentially decreasing radii, the greatest of which is the unit circle. Because every circle but the unit circle is inside of the previous one, the circles will converge around a single point which will be the limit.
That's it basically. Some interesting points are those which lie on infinitely small circles. For these points the direction of the curve might not exist. One such point is \(t = \frac{4}{7}, \bar{r}(t) = 1 - \sqrt2\). Can you catch 'em all?
Edit: another interesting thing is that \(\bar{r}_n(\frac{4}{7})\) seems to lie on a line for all \(n\). Are there other \(t\) with this property?
The center of gravity of a triangle
Wednesday, April 16, 2014
Sum of nested square roots
\[
\sqrt{\sqrt2+1} + \sqrt{\sqrt2-1} = \sqrt{2\sqrt2+2}
\]
It is interesting because it's of the somewhat rare form square root plus square root equals something simpler. Related to this is my post Rational sum of irrationals, where I come to the conclusion that the sum of two irrational square roots of fractions cannot be rational (that would make it simpler!), and also possibly my post on the fibonacci sequence, in which the sum of two exponentially growing irrational numbers equals an integer.
Sunday, April 6, 2014
The other part of the fibonacci sequence
\[
F_n = \frac{r_1^n - r_2^n}{\sqrt5}\\
\qquad r_1 = \frac{1+\sqrt5}{2}\\
\qquad r_2 = \frac{1-\sqrt5}{2}
\]
This closely resembles the way that we use complex conjugates to extract imaginary parts from complex numbers \(z\):
\[
z = a + bi\\
z^* = a - bi\\
\operatorname{Im}(z) = \frac{z - z^*}{2i}
\]
Did you notice how in the fibonacci sequence we divide by the special number \(\sqrt5\) and here we are dividing by the special number \(i\)? This means that, in some sense, \(F_n\) is the 'imaginary' part of \(r_1^n\). The 'real' part, then, should be \(E_n = r_1^n + r_2^n\) (possibly divided by \(2\)) by analogy with \(\operatorname{Re}(z) = \frac{z + z^*}{2}\).
Is there a recursive interpretation of \(E_n\)? Apparently, it's the same as for the fibonacci sequence:
n | 0 1 2 3 4 5 6 7 8 9
E_n| 2 1 3 4 7 11 18 29 47 76
Friday, April 4, 2014
On my mathematical notation
\(\begin{array}{c}b\\f(n)\\n=a\end{array}\) means the comma separated list \(f(a), f(a+1), f(a+2), \ldots, f(b)\). It mimics the common way to specify ranges in summation. It is ideal for use in tuples, sets and function argument lists.
I also like to vary the indentation, kind of like you do when programming. The basic rule is that you increase indentation by one step to indicate that the block on that level belongs to the line above it. I use it frequently to isolate the value of variables from the expression that they belong to:
\[
F = ma\\
\quad m = 4 \,\mathrm{kg}\\
\quad a = 10 \,\mathrm{m}/\mathrm{s}^2\\
F = 40 \,\mathrm{N}
\]
Thursday, April 3, 2014
Rational sum of irrationals
Of course there are irrationals whose sum is rational. An example would be 2-√2 and √2.
If we limit ourselves to sums like √a + √b = q, where a, b, and q are nonnegative fractions but √a and √b are irrational, what are the solutions?
Assume that there exists a solution. Multiply by (√a - √b)/q (q ≠ 0 because otherwise √a = √b = 0 which is rational). We get (a - b)/q = √a - √b, a rational expression which we may call r. Knowing that both q and r are rational, we deduce that (q + r)/2 = √a is rational, but that's a contradiction, so there cannot be any solutions.
We've just investigated rational sums of irrational numbers. The other day, I heard about algebraic sums of transcendental numbers. Supposedly, it is not known whether e + π is algebraic or not. Maybe that's something to delve further into?
The discrete heat problem - Part 2: Solving the characteristic equation
It seems that, in general, the solutions to the characteristic equation are \[r_i = -4\cos^2\frac{\pi i}{2 n} (1 \leq i < n)\] but I don't have a proof for this yet. I found the solutions by chance: by noticing that the solutions for low n involved the same square roots as cos did.
As I don't have a proof yet, I'll give you an example instead. Let \(n = 4\). Then the characteristic equation is
\[
\begin{eqnarray}
0 &=& \sum_{j = 0}^{3} \binom{j+4}{2j+1} r^j\\
&=& \binom{4}{1} + \binom{5}{3} r + \binom{6}{5} r^2 + \binom{7}{7} r^3\\
&=& 4 + 10r + 6r^2 + r^3\\
&=& (2+r)(2 + 4r + r^2)\\
&=& (2+r)(2+\sqrt{2}+r)(2-\sqrt{2}+r)
\end{eqnarray}
\]
whence we may read off the solutions \(r = -2, -2-\sqrt{2}, -2+\sqrt{2}\). This is just what the formula predicts:
\[
\begin{eqnarray}
r_1 &=& -4\cos^2\frac{\pi}{8} &=& -4\frac{1}{2}(1+\frac{1}{\sqrt{2}}) &=& -2-\sqrt{2} \\
r_2 &=& -4\cos^2\frac{\pi}{4} &=& -4\frac{1}{2} &=& -2\\
r_3 &=& -4\cos^2\frac{3\pi}{8} &=& -4\frac{1}{2}(1-\frac{1}{\sqrt{2}}) &=& -2+\sqrt{2}
\end{eqnarray}
\]
In conclusion, the formula is reasonable and will do without a proof for the moment.
The discrete heat problem - Part 1: Creating a differential equation
Stating the problem algebraically
We'll drop the \((t)\)'s for a while. Read \(E^{(j)}_i\) as \(E^{(j)}_i(t)\).
\[
\begin{eqnarray}
E'_0 & = & E_1 - E_0 = - E_0 + E_1\\
E'_i & = & (E_{i - 1} - E_i) + (E_{i + 1} - E_i) = E_{i - 1} - 2E_i + E_{i + 1} (1 \leq i < n - 1)\\
E'_{n-1} & = & E_{n - 2} - E_{n-1}
\end{eqnarray}
\]
Rearranging terms, we get
\begin{eqnarray}
E_1 & = & E_0 + E'_0\\
E_{i} & = & E'_{i - 1} - E_{i - 2} + 2E_{i - 1} (2 \leq i < n)
\end{eqnarray}
\]
Combining the equations into one massive differential equation
Looking at the latest set of expressions, we see that \(E_1\) depends only on \(E_0\) and its derivative. \(E_2\) depends on \(E_0\) and \(E_1\) plus derivatives, but if we substitute our expression for \(E_1\), we get \(E_2\) as a linear combination of only \(E_0\) plus derivatives. Continuing in a similar fashion, we conclude that every \(E_i\) can be written as a linear combination of only \(E_0\) plus derivatives. Thus for every \(i\), there must exist a sequence \(a_i\) independent of \(t\), such that \( E_i = \sum_{j = 0} a_{i, j}E_0^{(j)} \).We'll now deal with finding \(a_i (1 \leq i < n)\). This section, I tell you, is beautiful. Aside from the conceptual inversion of our system of equations, we will find the coefficients in Pascal's triangle.
Let's look at our progress so far. We know \(a_0 = (1,)\) and \(a_1 = (1, 1)\) (corresponding to \(E_0 = E_0\) and \(E_1 = E_0 + E'_0\), respectively). For any \(i \geq 2\), we can find \(a_i\) if we know \(a_{i - 1}\) and \(a_{i - 2}\). It is possible to find a recurrence relation for \(a_i\):
\[
a_{i, j} = a_{i - 1, j - 1} - a_{i - 2, j} + 2a_{i - 1, j}
\]
This recurrence relation is similar to that of Pascal's triangle (\( p_{i,j} = p_{i-1,j} + p_{i-1,j-1} \)). As it turns out, if we construct a triangle of \(a_{i,j}\) similarly to how Pascal's triangle is constructed from \(p_{i,j}\), our new triangle is half of Pascal's (see the figure below, where the orange segments form our new triangle when moved together). We find that \( a_{i, j} = \binom{i+j}{2j} \).
Because energy is conserved, \( \sum_{i = 0}^{n-1} E_i(t) = \sum_{i = 0}^{n-1} E_i(0) \). Call this constant quantity E. Using the expressions obtained above for \(E_i\), we'll get a non-homogenous linear differential equation.
\begin{eqnarray}
E &=& \sum_{i = 0}^{n-1} E_i(t)\\
&=& \sum_{i = 0}^{n-1} \sum_{j = 0}^{n-1} a_{i, j}E_0^{(j)}\\
&=& \sum_{j = 0}^{n-1} (E_0^{(j)} \sum_{i = 0}^{n-1} a_{i, j})
\end{eqnarray}
\]
The rightmost sum may be evaluated by looking at its final term in Pascal's triangle and going down one to the right. Our final result is:
\[
E = \sum_{j = 0}^{n-1} \binom{j+n}{2j+1} E_0^{(j)}
\]
The discrete heat problem - Part 0: Introduction
I'll start with the one which I call the discrete heat problem: Consider the points \((i, 0) (i \in \mathbb{Z}; 0 \leq i < n; 2 \leq n)\). Each has an amount of heat, which we'll denote \(E_i(t)\) as a function of time. Suppose we are given \(E_i(0) (0 \leq i < n)\). Can we find explicit expressions for \(E_i(t)\)?
The problem can be solved one part at a time, each part being interesting on its own, so I have decided to split the problem into several posts. Here's an outline of my solution:
- Create a differential equation
- Solve the characteristic equation
- Create an associated linear equation (almost done!)
- Solve the linear equation (not done yet!)
Monday, March 31, 2014
Evaluating polynomials faster
Let the degree of the polynomial be n. The complexity of finding the value of an mth degree monomial is \(\log(m+1)\). By summing the complexities from m = 0 to n we get \(\log 1+\log 2+\log 3+...+\log n+\log (n + 1)\), which is about the same as \(\log(n^n) = n\log n\). The new method on the other hand is linear in n because we only need to multiply and add once more every time n increases by one.
Inverting a pair of numbers
\[
(a \pm b)(a \mp b) = a^2 - b^2\\
\frac{1}{a \pm b} = \frac{a \mp b}{a^2 - b^2} = \frac{a}{a^2 - b^2} \pm \frac{-b}{a^2 - b^2}
\]
Sunday, March 9, 2014
How to install South Park: The Stick of Truth
- Install a new version of Wine. Open up a terminal and run the following:
- sudo add-apt-repository ppa:ubuntu-wine/ppa
- sudo apt-get update
- sudo apt-get install wine1.7
- Install Steam.
- Download the installer.
- Run it by right-clicking the file and choosing "Wine Windows Program Loader"
- Follow the wizard.
- Install the game.
- Purchase it through Steam.
- Let Steam download it.
Fixing some problems
- I got a (non-fatal) error saying something about the gnome-keyring. I fixed it by following the accepted answer at askubuntu.
- The textures wouldn't load. For example, the main menu background didn't show South Park: The Stick of Truth, but rather a couple of pink squares floating around. Also, my character was red. I fixed this by installing newer graphics drivers for my Intel graphics card.
- Follow the instructions at the Steam Support site
- Update your system (sudo apt-get update && sudo apt-get dist-upgrade)
- Reboot your computer.
Friday, February 28, 2014
How to setup AndEngine in Android Studio
- Create and open the project in which AndEngine will be used.
- Create a module for AndEngine.
File → Project Structure → Modules → + → Android Library → [Module name: AndEngine, Package name: org.andengine, Create activity: no] → Finish
- Tell the compiler to search the AndEngine module by adding a dependency.
File → Project Structure → Modules → <the module that will use AndEngine> → Dependencies → + → Module dependency → :AndEngine
- Download AndEngine by running the following in a terminal:
$ cd <project folder> $ git clone -b <GLES2 or GLES2-AnchorCenter> https://github.com/nicolasgramlich/AndEngine.git AndEngine.github $ rsync -a AndEngine.github/* AndEngine # This merges AndEngine.github and AndEngine $ rm -rf AndEngine.github
- Make a minor change to the file tree of AndEngine to make it work with Android Studio.
$ cd <project folder>/AndEngine/src/main $ rm -r java/org $ mv org java
- Ensure that Android Studio notices the changes you did. Do this by right clicking on the AndEngine module in the Project tool window and choosing Synchronize 'AndEngine'.
Optional: adding an extension
- Before 2: To find the package name of the extension, browse the extension repo on github and look in AndroidManifest.xml.
- After 3: Make the extension dependent on AndEngine.
- At 5: This step may vary slightly. You may not need to do anything.
Fixing java.lang.UnsatisfiedLinkError
- Manually copy <extension-module>/libs/* to a new folder <main-module>/lib
- Compress lib/ to lib.zip
- Rename lib.zip to lib.jar
- Add compile files('lib.jar') as a dependency in <main-module>/build.gradle
Monday, February 24, 2014
A partial fraction decomposition
For example when \(n = 2\),
$$ {1 \over x(x + 1)(x + 2)} = {1 \over 2}({1 \over x} - {2 \over x + 1} + {1 \over x + 2}) $$
I have no proof yet.
Wednesday, February 5, 2014
A Musical Epiphany
Played: