Math Equations

Thursday, April 3, 2014

The discrete heat problem - Part 0: Introduction

Newton's law of cooling states that "the rate of heat loss is proportional to the difference in temperatures between the body and its surroundings". Two years ago I began playing around with Newton's idea (although at the time I did not know it was attributed to him). The problems that have arisen since are the most rewarding ones that I have come across in my lifetime, and now, I'd like to share them with you.

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:

  1. Create a differential equation
  2. Solve the characteristic equation
  3. Create an associated linear equation (almost done!)
  4. Solve the linear equation (not done yet!)

Monday, March 31, 2014

Evaluating polynomials faster

I was just trying to find the roots of \(f(x) = 4 + 10x + 6x^2 + x^3\) by trying some values of x, when I came up with a better way of evaluating polynomials. Up till then I had been evaluating polynomials by summing the values of monomials. The better way is to rewrite the polynomial above as \(4 + x(10 + x(6 + x(1)))\), evaluate the innermost parenthesis first and work one's way out.

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.

To compute f(-2), we start with the last coefficient, 1, and alternatingly multiply by x and add the coefficient to the left. Our partial results are: 1, -2, 4, -8, 2, -4, 0. Indeed, x = -2 is a root of the polynomial.

Inverting a pair of numbers

Suppose you have two numbers \(a \pm b\) both not equal to zero. Then
\[
(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

It's been almost a week since this game was released, so I bet you've heard all about it already. In this guide I'll show you what I did to install it in Steam on Ubuntu using Wine.
  1. 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
  2. Install Steam.
    • Download the installer.
    • Run it by right-clicking the file and choosing "Wine Windows Program Loader"
    • Follow the wizard.
  3. 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


This guide assumes that you have Android Studio, git, a terminal and rsync installed.
  1. Create and open the project in which AndEngine will be used.
  2. Create a module for AndEngine.
    File → Project Structure → Modules → + → Android Library → [Module name: AndEngine, Package name: org.andengine, Create activity: no] → Finish
  3. 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
  4. 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
  5. 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
  6. 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'.
You should now be able to use the core AndEngine package.

Optional: adding an extension

Adding an extension is much the same procedure, so I'll only list the additional things you need to do.
  • 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

When I tried to use the physics extension, everything compiled fine, but when I ran my app, it crashed, logging: java.lang.UnsatisfiedLinkError: Couldn't load andenginephysicsbox2dextension from loader dalvik.system.PathClassLoader[...]: findLibrary returned null

That is, the .so files are not in the apk. Workaround:
  1. Manually copy <extension-module>/libs/* to a new folder <main-module>/lib
  2. Compress lib/ to lib.zip
  3. Rename lib.zip to lib.jar
  4. Add compile files('lib.jar') as a dependency in <main-module>/build.gradle
However, it must be noted that one has to update lib.jar manually in the future!

Happy coding!



Monday, February 24, 2014

A partial fraction decomposition

$$ \prod\limits_{i=0}^{n}{1 \over x + i} = {1 \over n!}\sum\limits_{i=0}^{n}{(-1)^i {n \choose i} \over x + i} $$

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

I discovered something great today. It is possible to listen to notes of a chord selectively. If you play the chord C major {C, E, G} (all three tones at once), it is possible to listen to the chord as if a melody was played. For example you may hear the tone C followed by E followed by G followed by E again even though the keys are actually hit all at once.

Played:
Observed:

How is this possible? Can I do this? you ask. My answer is I don't know, but I suspect it has to do with resonance in the ears. When I do it, it feels as though some muscle deep in my ear is contracting or relaxing depending on the tone (contracting if the tone is higher). Try it and let me know your results!

What does this mean? How can it be investigated further? What applications are there? My hopes are that I will get good at doing it so that I can "tune into" (resonate at) any frequency that I want. I would then for any chord be able to plot a graph with observed intensity on the y-axis as a function of the frequency that I am looking for on the x-axis. Obviously, the ability can also come in handy when analysing music: is that a C6 or a Cmaj7? Last of all, it may be possible to develop a theory which connects the shape of the aforementioned graph to the feeling of the music. Instead of saying That's a C13+11! we might say That's Mount Everest!

Discovering this makes today a big day in my life. I'm going to be sentimental and write down the exact minute it happened. 2014-02-05 17.40 CET.