Using Python in the first MAT1120 oblig

The first “oblig” (mandatory exercise) in the subject MAT1120 is now available. I am trying to do as much work as possible in Python instead of Matlab, but as always this creates some extra effort when the subject is oriented around the latter.

Already in the first exercise there is a minor challenge, since the data file is not stored as a simple array, but as Matlab code. This means we need to rewrite this file to Python code or run it in Matlab and export it as data instead. As I am currently using a computer without Matlab installed and being to lazy to connect to a server with Matlab via remote desktop, I decided to do the latter. (I might add that I also wanted to see if I could do this without Matlab at all).

First of all, I figured the data was stored in the following manner:

Continue reading

Sweet first proof

Carl Friedrich Gauss (1777 – 1855) by G. Biermann (1824-1908)

Earlier today, enjoying a warm cup of coffee with a friend of mine,we got into a discussion about some math and ended up contemplating on how to prove the sum formula for the n first natural numbers.

The proof is rumored to first have been done by Gauss when he was only a child.

Let S_n = 1 + 2 + 3 + . . . + (n-2) + (n-1) + n

just rewriting the terms backwards we get

S_n = n + (n-1) + (n-2) + \ldots + 3 + 2 +1

now adding these two expressions for the sum we obtain

2 S_n = (n+1) + (n+1) + (n+1) + \ldots+ (n+1) + (n+1) + (n+1)

and since we had n terms in the original sum we now have n \cdot (n+1)‘s, so

2 S_n = (n+1) + (n+1) + (n+1) + \ldots+ (n+1) + (n+1) + (n+1) = n(n+1)

so..

S_n = \frac{ n(n+1) }{2}

Neat. On a computer this would severely reduce the number of operations that would have to be done to compute such a sum. Imagine having to sum up the first million natural numbers and let’s suppose the computer requires one operation for adding, multiplying, dividing and so forth. Then implementing this formula would reduce the numbers of operations from 10^6 to 3.

WordPress in LaTeX glory

Speaking of LaTeX, if you, like us, want to write LaTeX math code in your blog, you should have a look at the LaTeX WP plugin.

The output will become something like this: (1 + (\frac{y}{a})^2)^{\frac{1}{2}} = 1 + \frac{1}{2}(\frac{y}{a})^2 + \ldots

Or maybe like this: f(x) = \sum_{n=0}^\infty \frac{f^{(n)}(0)}{n!}x^n = 1 + nx +  \frac{n(n-1)}{2}x^2 + \ldots

These are not as pretty as real \LaTeX output, but they sure are prettier than writing math the hard way:

f(x) = \sum_{n=0}^\infty \frac{f^{(n)}(0)}{n!}x^n = ...

I’m looking forward to be serving you with more math-stuff in the future!

LaTeX It!

This is going to my first post in this blog, and along with some other more technical posts, I will dual post it in my own blog over at dragly.org.

If you are using Thunderbird for e-mail and want to send mathematical formulas to your contacts, you should consider the LaTeX It! plugin or the Equations plugin. The former requires you to have LaTeX and ImageMagick installed, while Equations uses an external server to generate your images.

Continue reading