Showing posts with label MAST10008. Show all posts
Showing posts with label MAST10008. Show all posts

Monday, 20 April 2015

Maths on Steroids (Accelerated Mathematics 1, 2015): 3

If-statements, for-loops, while-loops, what are they good for? Absolutely...everything in programming?

For most of you, last week would have been the first time that you've seen an if-statement in Matlab. And you were given a slightly involved task: you were asked to write up a function that takes in a matrix \(A\) and does the following:
  1. checks if \(A\) is square;
  2. checks if the columns of \(A\) each add up to \(1\);
  3. checks if the entries of \(A\) are all non-negative;
  4. puts out a message if any of the checks fail;
  5. outputs the row-reduced form of \(I-A\) if \(A\) satisfies the checks.
To begin with, let's have a think about how to write if-statements for each of the checks in Matlab.

1. If \(A\) is square.

Here's a simple if-statement to check for square-ness:

[m,n]=size(A);
if m~=n
    'Not square enough?'
end

So, what does it do? We first compute the size of the matrix A, this is a vector whose first entry is the number of rows that \(A\) has and whose second entry is the number of columns. Thus, writing "[m,n]=size(A)" is to assign "[m,n]" to be this vector; i.e.: m=the number of rows of \(A\) and n=the number of columns of \(A\). Then, if m isn't equal to n, this little if-statement outputs the message "Not square enough?", but if m is equal to, then nothing happens.

One question that you should be asking at this point is: what's the deal with the semi-colon ";" at the end of the first line. Why do we bother having it at all? Well, semi-colons at the end of a command lets you run that command without displaying the results. For our purposes, we wanted to assign numbers to m and n, but we didn't really want to see them. Hence the semi-colon. On the other hand, we definitely wanted to be able to read the message "Not square enough?", so we didn't put a semi-colon after that.

2. If the columns of \(A\) add up to \(1\).

This first idea might be to write something like the following:

[m,n]=size(A);
if sum(A)~=ones(1,n) (THIS IS WRONG!)
    'columns need to sum to one!'
end

And where this goes wrong (my mistake - I actually thought that this worked during the Tuesday lab), is that the if-statement then just checks if the first entries of "sum(A)" and "ones(1,n)" are equal. So, it only checks if the first column of \(A\) adds to \(1\).

Here's the "intended" if-statement:

[m,n]=size(A);
T=sum(A);
t=0;
for k=1:n
    if T(k)~=1
        t=t+1;
    end
end
if t>0
    'columns need to sum to 1!'
end

We start by creating a vector \(T\) corresponding to the column-sum of \(A\). Now, we'd like to check if each entry of \(T\) is equal to \(1\), and the above code deals with this by creating a variable \(t\) that increases by \(1\) for every entry \(T(k)\) of \(T\) that isn't equal to \(1\). So, after going through the entries of \(T\) using the for-loop in the third line, either \(t=0\) in which case \(T\) is a row of \(1\)s, or \(t>0\), in which case \(T\) isn't a vector of \(1\)s and hence the columns of \(A\) don't each sum to \(1\). Note that again, nothing happens if the columns of \(A\) each sum to \(1\).

Aaaaaaand, now that you've understood how that worked, let me tell you about alternative ways of doing step 2. To begin with, let's understand how truth values work. You saw in this tute that writing "m==n" lets you check if m is equal to n. But have you tried typing this into Matlab and seeing what you get? Try "3==3" and "3==2" (without the quotation marks). You should have gotten "ans=\(1\)" and "ans=\(0\)" respectively: that's right! Matlab thinks of \(1\) as "true" and \(0\) as "false". Soooo, what happens if I type in something like "[3 2]==[3 3]"? Well...TRY IT! You should get in return a vector "[1 0]", signifying that this is true for the first value, and false for the second value. Sooo....how can we use this to our advantage? Here's a first idea:

[m,n]=size(A);
if sum(sum(A)==ones(1,n))~=n
    'columns need to sum to one!'
end

So, what's going on here? The command "sum(A)==ones(1,n)" checks the column-sum vector of \(A\) against a row of \(1\)s and outputs a vector filled with \(1\)s and \(0\)s signifying whether the corresponding entries of these two row vectors match up. IF every column sums to \(1\), then we should expect "sum(A)==ones(1,n)" to produce a length n vector of \(1\)s - signifying "true" in every entry. If not, then some of the outputs will be \(0\). Now, the sum function not only adds up the columns of a matrix \(A\), it also adds up all the entries of a row vector (if you didn't know this, you could have still taken a transposition of a row vector and then applied the sum function). So, the above code basically checks if "sum(A)==ones(1,n)" is n and displays a message if it's not.

And here's another variant:

[m,n]=size(A);
if sum(abs(sum(A)-ones(1,n)))>0
    'columns need to sum to one!'
end

The absolute value function "abs", when combined with "sum" adds up the difference between sum(\(A\)) and a row of \(1\)s. So, if there is no difference, then this should be \(0\) and if there is a difference, then it'll be strictly above \(0\).

See if you can come up with something-else?

3. If every entry of \(A\) is positive.

To begin with, let's start with something that doesn't work:

[m,n]=sum(A);
if A~=abs(A) (THIS IS WRONG!)
    'slightly too negative =('
end

Again, the problem here is that "A~=abs(A)" only checks to see if the first two entries of these two matrices are equal, and neglects the rest. =/

The "intended" solution is something like the following:

[m,n]=size(A);
u=0;
for j=1:m
    for k=1:n
        if A(j,k)<0
            u=u+1;
        end
    end
end
if u~=0
    'slightly too negative =('
end

Like before, the \(u\) here is a marker for how many entries are negative. The two nested for-loops lets us go through all of the entries of \(A\) and checks if they're (strictly) negative.

And, here's an alternative method - see if you can figure out what's going on:

[m,n]=size(A);
if sum(sum(A==abs(A)))<m*n
    'slightly too negative =('
end

And another variant:

[m,n]=sum(A);
if sum(sum(A-abs(A)))>0
    'slightly too negative =('
end

4. Putting all of this together in just a single for-loop, and in the form of a function, we have:

Method 1:

function B=xx_solve(A)
[m,n]=size(A);
T=sum(A);
t=0;
for k=1:n
    if T(k)~=1
        t=t+1;
    end
end
u=0;
for j=1:m
    for k=1:n
        if A(j,k)<0
            u=u+1;
        end
    end
end
if m~=n
    'Not square enough?'
elseif t>0
    'columns need to sum to 1!'
elseif u>0
    'slightly too negative =('
else
    B=rref(eye(n)-A);
end

This is the most rudimentary, and in some sense, most "universal" version. The ideas that you use here apply to most programming languages.

One thing that you might ask is why there is a semi-colon after "B=rref(eye(n)-A)", as this would withhold the displaying of the matrix \(B\) - the desired output? Well, that has to do with the first line: the fact that it's written "B=xx_solve(A)" means that inputting \(A\) into the function xx_solve will output "B" (provided that everything goes right).

Method 2:

function B=xx_solve(A)
[m,n]=size(A);
if m~=n
    'Not square enough?'
elseif sum(sum(A)==ones(1,n))<n
    'columns need to sum to 1!'
elseif sum(sum(A==abs(A)))<m*n
    'slightly too negative =('
else
    B=rref(eye(n)-A);
end

This should be pretty self-explanatory, right?

Method 3:

function B=xx_solve(A)
[m,n]=size(A);
if m~=n
    'Not square enough?'
elseif sum(abs(sum(A)-ones(1,n)))>0
    'columns need to sum to 1!'
elseif sum(sum(A-abs(A)))>0
    'slightly too negative =('
else
    B=rref(eye(n)-A);
end

And here's a fnal method...it's the intended method in Matlab, but requires knowing a specialised command called "isequal" that basically tests if two matrices are completely equal.

Method 4:

function B=xx_solve(A)
[m,n]=size(A);
if m~=n
    'Not square enough?'
elseif isequal(sum(A),ones(1,n))
    'columns need to sum to 1!'
elseif isequal(A,abs(A))
    'slightly too negative =('
else
    B=rref(eye(n)-A);
end

This is the most efficient method, but it's also pretty Matlab-specific? And to be fair...it's a little bit on the boring side...so...um, totes go with the other methods guys!?!? Totes.


Thursday, 16 April 2015

Maths on Steroids (Accelerated Mathematics 1, 2015): 2

The week before Easter, a friend of mine showed me the following question before my Tuesday morning tute, I solved it and decided that it'd be a good question to give to you guys. =P

Actually, we could do this question using Descartes' circle theorem, but that's probably a bit overkill. Instead, let's tackle it with basic primary school geometry, and a bit of induction and telescoping! Consider the following figure:

Problem: order the radii of all the little yellow circles up from the bottom of the center as a sequence \(\{r_n\}\) and show that \begin{align}r_n=\frac{1}{2n(n+1)}.\end{align} When doing proofs for general results like this, it can often really really help to work out a few baby cases. So, let's start by showing that \(r_1=\frac{1}{4}\).

As you can see from the diagram below, we've got a (vertical) trapezium with two right angles opposite each other and with the parallel sides of lengths \(1\) and \(r_1\). Thus, by chopping off a rectangle at the bottom of this trapezium, we're left with a right-angled triangle with sides of lengths \(1-r_1,1\) and \(1+r_1\).
And so, Pythagoras' theorem tells us that \begin{align} (1-r_1)^2+1^2&=(1+r_1)^2 \\ \Rightarrow 1&=4r_1.\end{align} Oookay, that was fair straight forward. Let's try this again for \(r_2\):
So, we see that by repeat this trapezium trick to calculate \(r_2\) we get: \begin{align} (1-2r_1-r_2)^2+1^2&=(1+r_2)^2\\ \Rightarrow 1&=(1+r_2)^2-(1-2r_1-r_2)^2\\ &=4(r_1+r_2)(1-r_1).\end{align} Substituting in \(r_1=\frac{1}{4}\), we show that \(r_2=\frac{1}{12}\). Now, if we keep going with this trapezium trick (*), we see that to compute \(r_{n+1}\), we get: \begin{align} (1-2(r_1+\ldots+r_n)-r_{n+1})^2+1^2&=(1+r_{n+1})^2\\ \Rightarrow 1&=(1+r_{n+1})^2-(1-2(r_1+\ldots+r_n)-r_{n+1})^2\\ &=4(r_1+\ldots+r_{n+1})(1-r_1-\ldots-r_{n}).\end{align} Thus, \begin{align} r_{n+1}=\frac{1}{4-4(r_1+\ldots+r_n)}-(r_1+\ldots+r_n).\end{align} So, we've now got this recursive expression for \(r_{n+1}\) and recursion should really make us think: induction.

We're going to use a slightly stronger form (**) of mathematical induction than what you're used to seeing. Don't worry - the logic is the same. =) Okay, here goes...

Let's start off with a proposition: let the proposition \(p(n)\) be the statement that \(r_n=\frac{1}{2n(n+1)}\), and we're going to prove these statements for every \(n\in\mathbb{N}\).

Base case: \(n=1\)... well, we've actually already proven this above. We showed that \(r_1=\frac{1}{4}=\frac{1}{2\times1\times 2}\).

(Strong) induction step: now, we're going to do something a little different to showing that "\(p(k)\Rightarrow p(k+1)\)". We're actually going to show that \begin{align}p(1),p(2),\ldots, p(k)\text{ all being true }\Rightarrow p(k+1)\text{ is true.}\end{align} Take a moment to think about that logic, and I hope that you see that it's the same type of logic as you usually use in induction, except that it feels stronger because you're assuming more things for the induction step.

Okay....breathe out.

So, let's assume that \(p(1),\ldots,p(k)\) are all true. Now, we showed before that \begin{align} r_{k+1}=\frac{1}{4-4(r_1+\ldots+r_k)}-(r_1+\ldots+r_k).\end{align} And now, invoking all of our assumptions, we can try to work out what \(r_1+\ldots+r_k\) is equal to, and hence what \(r_{k+1}\) is equal to: \begin{align} r_1+\ldots+r_k&=\frac{1}{2}\left(\frac{1}{1\times 2}+\frac{1}{2\times 3}+\ldots+\frac{1}{k\times (k+1)}\right)\\ &=\frac{1}{2}\left(\frac{1}{1}-\frac{1}{2}+\frac{1}{2}-\frac{1}{3}+\frac{1}{3}-\frac{1}{4}+\ldots-\frac{1}{k}+\frac{1}{k}-\frac{1}{k+1}\right)\\ &=\frac{k}{2(k+1)}.\end{align} W000t! Telescoping! And substituting this in, we get that: \begin{align}r_{k+1}&=\frac{1}{4-\frac{2k}{k+1}}-\frac{k}{2(k+1)}\\ &=\frac{k+1}{2(k+2)}-\frac{k}{2(k+1)}\\&=\frac{(k+1)^2-k(k+2)}{2(k+1)(k+2)}=\frac{1}{2(k+1)(k+2)},\end{align} which is precisely what we want. I.E.: the proposition \(p(k+1)\) is true!

Therefore, by the principle of (strong) mathematical induction, the propositions \(p(n)\) are true for all \(n\in\mathbb{N}\).

=)

*: Bah, I didn't feel like drawing the diagram.
**: strictly speaking, it's not stronger - it's the same strength! It's just that it seems stronger.

Monday, 23 March 2015

Maths on Steroids (Accelerated Mathematics 1, 2015): 1

Alright, alright, alright, alright as promise: I'mma give a more detailed explanation of how to do question 24 from your tutorials using...symmetry. =D (*)

But because we launch into that, some of you might find this blog entry from a previous year useful. Those who are in my tutes will have seen the very first thing in this blog post, but those who're only in my lab might find it interesting. I also go through a line-by-line analysis of the code at the end of last week's lab - if you totes understood everything, then great! If not, this might be a useful reference (plus, I point out a few things along the way - who knows, maybe you missed something?).

Okay, on to symmetry?

Now, we want to prove that \begin{align}\left| \begin{array}{ccc} 1 & 1 & 1 \\a & b & c \\ a^3 & b^3 & c^3\end{array}\right|=(a-b)(b-c)(c-a)(a+b+c).\end{align} And the first thing that I want to do is to make the following observations:

  1. The determinant is going to be a degree 4 polynomial in \(a,b,c\). This is because each (monomial) term in the determinant is a product of matrix entries taken from different rows and different columns (have a gooooood think about how cofactor expansion works).
  2. If any two of the three variables are equivalent, e.g.: \(a=b\), then the matrix has repeated columns and hence will have determinant equal to \(0\) (**). This tells us that \((a-b),(a-c)\) and \((b-c)\) must all be factors of the determinant.
  3. Switch any two of the variables in the matrix has the same effect as switching the two corresponding rows! This means that the determinant changes sign every time you switch two variables
Aaaaand, that should be enough to get us started.

Now, we know that the determinant is some polynomial \(d(a,b,c)\). And observation 2 tells us that \begin{align} d(a,b,c)=(a-b)(b-c)(c-a)\times p(a,b,c),\end{align} where \(p(a,b,c)\) is another polynomial in \(a,b,c\). Add on the fact that observation 1 tells us that every single term in \(d(a,b,c)\) has to be degree 4, this tells us that the polynomial \(p(a,b,c,)\) actually has to be linear: \begin{align} p(a,b,c)=\alpha a+\beta b+\gamma c\text{, for some }\alpha,\beta,\gamma\in\mathbb{R}.\end{align}

Okay, so it's lookin' preeeetty good...we're getting a good handle-hold on what \(d(a,b,c)\) looks like.

Thanks to observation 3, we know that \(d(a,b,c)=-d(b,a,c)\) and so: \begin{align} (a-b)(b-c)(c-a)p(a,b,c)&=-(b-a)(a-c)(c-b)p(b,a,c)\\&=(a-b)(b-c)(c-a)p(a,b,c)\\ \Rightarrow p(a,b,c)&=p(b,a,c)\\ \Rightarrow \alpha a +\beta b+\gamma c &= \alpha b+\beta a+\gamma c.\end{align} Since \(a\) and \(b\) are independent variables, this means that \(\alpha=\beta\). By the same logic applied to \(a\) and \(c\), we get that: \begin{align} \alpha=\beta=\gamma.\end{align} Soooo, we've just shown that the determinant may be written as \begin{align} d(a,b,c)=\alpha (a-b)(b-c)(c-a)(a+b+c),\end{align} and all we need to do now, is to show that \(\alpha=1\). One way to do this is to substitute nice numbers into \(a,b,c\) and to work it out. In fact, if we just set \(a=0\) we see that \begin{align}d(0,b,c)=\left| \begin{array}{ccc} 1 & 1 & 1 \\ 0 & b & c \\ 0 & b^3 & c^3\end{array}\right|=\left|\begin{array}{cc}b & c\\ b^3 & c^3\end{array}\right|=bc(c-b)(b+c).\end{align} Since we know that \begin{align}d(0,b,c)=\alpha bc(c-b)(b+c),\end{align} this gives us the desired conclusion that \(\alpha=1\).

AND WE'RE DONE! Now, this technique can also be used to do the other determinant in this question. It's a little bit trickier though...and you'll need to show, using symmetry arguments, that at some point you can get the determinant \(d(x,y,z)\) into the following form: \begin{align} d(x,y,z)=(x-y)(y-z)(z-x)[\alpha (x^2+y^2+z^2)+\beta (xy+yz+zx)],\end{align} and then show that \(\alpha=0\) and \(\beta=1\). This is a healthy exercise and you should all totes give it a try!


*: Note to self: smileys look vaguely wrong in a serif font... =/
**: if you didn't know this, combine the fact that determinants aren't changed by transposition and the method of computing determinants using row reduction

Sunday, 16 June 2013

Maths on Steroids: final?

Sorry guys: I tried, but I just couldn't think of a non-trite-sounding first sentence to this post, so I wrote a con-trite-sounding one instead. Okay, maybe I'm not that contrite...in fact, I'm pretty happy with how that sentence turned out. =P

There is perhaps, in the West, a slight cultural inclination towards the belief that teachers are somehow less. After all, it's often said that those who can, do. And those who can't, teach.

I can't be bothered refuting this claim, someone-else has already done it for me. But it does strike me as odd that even in a major segment of the teaching profession: tertiary education, this view is espoused. I took us about two hundred years after the adoption of the printing press in the West for scientific journals to happen (compare with erotic novels, which pretty much happened overnight).

There is no denying that this gadget has been instrumental (*) in the spreading of scientific ideas among academics. But one of the side-effects of the scientific journal has been a shift in the focus of academia. Traditionally, a professor's primary role is to profess that they know nothing about their field of expertise and then hammer you with all the details of how poorly they understand their material over the next few months. But some where along the line, academia started to focus less on teaching and more on the number of and quality of one's publications.

While I agree that there's probably a strong correlation between the two, I feel that it's tragic that some how research is touted as the primary objective of academia, and the noble act of teaching is...disdained.

...hmm...

I dunno, that was a bit of a random start to things. And...and I guess that I have been thinking a bit about teaching. Both of my parents were teachers in China, and they have a very pragmatic approach to teaching: make sure that the kids get good marks on their exams. On the other hand, I can't really name anyone at uni who would explicitly claim that this is the right way to do this; there is a hope that we can steer students far from the perils of an "exam-oriented" approach to study. And I feel... I feel like this is a reflection of an overly simplistic and naive view of human motivation. But...yea, I should go to sleep soon. I'mma fly off to China in a few hours and this is probably just some sort of procrastination.

Orritey! It's tiiime fooooor...

General Exam tips:
  1. Get full marks.
  2. Aim to get 120/100. When you fail to achieve your goals, you'll still have full marks.
  3. Keep your hands warm. My personal preference is to bring a trashcan full of charcoal - this way, you can roast chestnuts while you get full marks! Failing that, I guess you could go buy one of those Japanese hand-warmer packs from Daiso?
  4. Do the questions in order. I know that one of the standard pieces of advice that we're supposed to tell peeps is that you DON'T NEED TO do the questions in order. But, it's much harder for BOTH you and your exam marker to miss one of the questions this way. I think that the only reason that we're supposed to tell you that you don't need to do stuff in order is because sometimes people get stuck on one question and waste waaaaay too much time on it. So...
  5. Don't waste waaaay too much time on one question. 
  6. Do not leave an exam 2 hours early because you finished it and you and your friends "agreed" beforehand that you were all going to finish waay early and go out and party and stuff and then they end up not leaving 2 hours early and you get sunburnt/frostbite standing outside the exam hall and you realise much later that you forgot to do one of the questions because it was hella annoying and you were gonna leave it till the end sad face.
  7. Write in English where necessary.
And hints to the questions that I gave you guys in the last post:
  1. Duh. It's all Greek to me.
  2. Just do some computations with monomials.
  3. *Cough* the eigenvectors should be all the monomials...just make sure that you do some sample computations and define the right generalisation of \(T\).
  4. I think that it's probably important to have two variables? Maybe???
  5. The trick is to group things into sequences of two (non-overlapping) days.
  6. *Cough* ...just...*cough*.
  7. Diagonalise it!

Orrite. Own those exams guys! Own them like you paid fees to attend uni. =P

*: you can't really deny it because gadgets are pretty much instruments, right?

Thursday, 30 May 2013

Maths on Steroids: 10 + 11

"This cosmic dance of bursting decadence and withheld permissions twists all our arms collectively, but if sweetness can win, and it can, then I'll still be here tomorrow to high-five you yesterday, my friend. Peace."

-Royal Tart Toter (Adventure Time).

Hey guys...and so it came to pass that the semester drew to an end, but not so your edification. I hope that you all had a fun semester doing some maths. I know that I had fun tutoring you guys. And I guess that I just wanna point out and remind you that ultimately, you kinda learnt everything by yourselves. All I did was facilitate some discussion and thoughts every so often, and this is meant to be one of the take-home messages of university education: there won't always be teachers, and you guys can and will have to teach yourselves. Which is good, because it turns out that most of the time you're better at teaching yourselves than we (teachers) are.

Having said that, during this week's tute, I got a request for some harder eigen-stuff questions. I couldn't really find any hard ones of the net, so I just made some up. I'll only provide the answer for the first one (for now). If you wanna know if you got something right, ask one of your friends to try the problem independently and see if your answers match up? Oh, and I should warn you that I haven't ordered the questions in order of difficulty =P

  1. What do you call an eigen-sheep? (Ans: a lamb, duh).
  2. Consider the (infinite dimensional) vector space \(\mathcal{P}\) of real polynomials in \(x\). Show that the following function is a linear transformation, and find its eigenvalues and eigenvectors: \begin{align}T:\mathcal{P}&\rightarrow\mathcal{P}\\ p(x)&\mapsto x\cdot\frac{\mathrm{d}p}{\mathrm{d}x}.\end{align}
  3. Generalise the above setup/result/calculations to vector spaces of real polynomials in more than two variable.
  4. Once you've figured out the right generalisation in 3 to the linear transformation \(T\) defined in question 2, notice that it works on smooth functions in general. So then try to find non-polynomial eigenvectors in the vector space of smooth functions with eigenvalue \(2\).
  5. The weather in the Ice Kingdom in the land of Ooo sucks hard. If it snows today, then the probability that it will snow tomorrow is \(\frac{3}{4}\). And if it doesn't snow today, then the chance that it will snow tomorrow is \(\frac{1}{5}\). Given that there is no climate change in the Ice Kingdom, in the long term, for what proportion of the days in the Ice Kingdom will it snow?
  6. Most of the time we've dealt with matrices that can be diagonalised. Can you find a \(2\times 2\) matrice that can't be diagonalised? And how might you generalise to a \(k\times k\) matrix?
  7. Consider the following matrix of transformation on \(\mathbb{R}^3\): \begin{align}A=\left[\begin{array}{ccc}0 & -\frac{\sqrt{3}}{4} & -\frac{1}{4} \\ \frac{1}{\sqrt{3}} & \frac{1}{2} & -\frac{\sqrt{3}}{2} \\ \frac{1}{3} & -\frac{\sqrt{3}}{2} & \frac{3}{2} \end{array}\right],\end{align} and also consider the following set in \(\mathbb{R}^3\): \begin{align}S=\left\{\left[\begin{array}{c} u \\ \frac{v\sqrt{3}}{2}-\frac{1}{2} \\ \frac{v}{2}+\frac{\sqrt{3}}{2} \end{array}\right]: 0\leq u, v, \leq 1\right\}.\end{align} First show that \(S\) is a unit square, then figure out what \(A\cdot S\) and \(A^2\cdot S\) and so forth look like. In particular, calculate the area of \(A^n\cdot S\), hence find the total area of all the \(A^n\cdot S\)s as you vary \(n\) over all the non-negative integers and figure out what the union of all of these shapes geometrically looks like (*).
Methinks that's enough for now. Plus, if you can do those, you really should be set for any eigenvalue stuff you're likely to see in first year maths. =)

*: you might need to be slightly more subtle in your approach to eigenvectors and eigenvalues for this problem. It can be tricksy...

Wednesday, 22 May 2013

Maths on Steroids: 9

Hey guys! To begin with, distractions: MUMS AGM this week - free pizza + run for a position as a first year rep? Also, there's a MUMS Trivia night next week - I stress: no maths required, despite this being for a maths society.

Orrite, let's just get down to business - these are some answers (not solutions, just answers) to last week's (tute 9) lab sheets:

2 A Linear Transformation in \(\mathcal{P}_3\)
1)a)\begin{align}T(1)=&12\cdot1\\ T(x)=&10\cdot x\\ T(x^2)=&2\cdot 1+6\cdot x^2 \\ T(x^3)=&6\cdot x^2.\end{align}
1)b)\begin{align}\left[\begin{array}{c}12 \\ 0 \\ 0 \\ 0 \end{array}\right],\left[\begin{array}{c}0 \\ 10 \\ 0 \\ 0 \end{array}\right],\left[\begin{array}{c} 2 \\ 0 \\ 6 \\ 0 \end{array}\right],\left[\begin{array}{c}0 \\ 6 \\ 0 \\ 0 \end{array}\right]. \end{align}
1)c)\begin{align}\left[\begin{array}{cccc}12 & 0 & 2 & 0 \\ 0 & 10 & 0 & 0 \\ 0 & 0 & 6 & 0 \\ 0 & 0 & 0 & 0 \end{array}\right].\end{align}
2)
A basis for the kernel of \(T\) is given by: \(\{3x-5x^3\}\).

A basis for the image of \(T\) is given by: \(\{1,x,x^2\}\).

3)a)
Everything in the kernel.

3)b)
No, there is no solution to blah blah blah\(=x^3\).

Yes, anything of the form \(\frac{5}{6}+\alpha(3x-5x^3)\) will be a solution to blah blah blah\(=10\).

Note: it is crucial that the answer is given in polynomial form, since the column vectors are merely representatives of these polynomials and hence not appropriate answers to 1)a), 3)a) and 3)b).

3 Change of Basis
4)a)
I...personally think that this is a slightly silly question. I suppose that an answer might be something like: "Coordinate changes are linear transformations, and transition matrices are their corresponding matrix of transformations.".

4)b)\begin{align}P_{B\rightarrow S}=\left[\begin{array}{cccc}1 & 1 & 0 & 0 \\ 1 & -1 & 0 & 0 \\ 0 & 0 & 1 & 1 \\ 0 & 0 & 1 & -1 \end{array}\right],\,P_{S\rightarrow B}=\frac{1}{2}\left[\begin{array}{cccc}1 & 1 & 0 & 0 \\ 1 & -1 & 0 & 0 \\ 0 & 0 & 1 & 1 \\ 0 & 0 & 1 & -1 \end{array}\right].\end{align} 4)c)\begin{align}P_{C\rightarrow B}=\left[\begin{array}{cccc}\frac{1}{2} & 1 & \frac{1}{2} & 0 \\ \frac{1}{2} & 0 & \frac{-1}{2} & 0 \\ 0 & 0 & \frac{1}{2} & 1 \\ 0 & 0 & \frac{1}{2} & 0\end{array}\right].\end{align}
4)d)\begin{align}[3+x-10x^2+x^3]_S=\left[\begin{array}{c} 3 \\ 1 \\ -10 \\ 1 \end{array}\right],\,[3+x-10x^2+x^3]_B=\left[\begin{array}{c} 2 \\ 1 \\ \frac{-9}{2} \\ \frac{-11}{2} \end{array}\right].\end{align}

4 Linear Transformations and Eigenthings
5)a)\begin{align}A=\left[\begin{array}{cc}5 & -3 \\ 6 & -4 \end{array}\right].\end{align}
5)b)\begin{align}T(2,2)=(4,4),\, T(1,2)=(-1,-2).\end{align}
5)c)\begin{align}T(2,0)&=T((4,4)+(-2,-4))=T(2(2,2)-2(1,2)) \\ &=2T(2,2)-2T(1,2)=(8,8)+(2,4)=(10,12).\end{align}
5)d)
Ewww...so gross. There's no way I'mma answer this one at all. I mean, you might need to do three pictures just to show what's going on...bleh.

5)e)
The (*) eigenvectors of \(A\) are \(\{\left[\begin{array}{c}2 \\ 2\end{array}\right],\,\left[\begin{array}{c}1 \\ 2\end{array}\right]\}\) with respective eigenvalues \(\lambda=2,-1\).

5)f)\begin{align}P_{B\rightarrow S}=\left[\begin{array}{cc} 2 & 1 \\ 2 & 2 \end{array}\right] \Rightarrow P_{S\rightarrow B}=\frac{1}{2}\left[\begin{array}{cc} 2 & -1 \\ -2 & 2 \end{array}\right].\end{align}
5)g)\begin{align}[T]_B=P_{S\rightarrow B}[T]_S P_{B\rightarrow S}=\left[\begin{array}{cc} 2 & 0 \\ 0 & -1 \end{array}\right]. \end{align}
5)h)
I've noticed that my answer to (g) is a diagonal matrix whose diagonal values correspond to the eigenvalues I obtained in part (e) (**).

5)i) The basis \(B\) tells me that the linear transformation \(T\) acts on a vector in \(\mathbb{R}^2\) by doubling the \((2,2)\) "component" of this vector and flipping the \((1,2)\) "component" of this same vector. I use the term "component" somewhat loosely here - I just mean that any vector in \(\mathbb{R}^2\) may be written uniquely as a linear combination of \((2,2)\) and \((1,2)\), and not something to do with vector-resolutes.

Note: just as with the polynomials, it's important to put in row vectors instead of column vectors in 5)b) and 5)c) - but not 5)e) as it asks for eigenvectors to \(A\), not \(T\).

Additional note: these eigenstuff calculations are generally pretty start forward, although a lot of people will screw up part (g) just because they have the matrices in the wrong order. I personally avoid memorising what you have to put down, and just think through the matrix multiplications - making sure that I remember that when you apply a matrix to a column vector, you start from the RIGHT HAND SIDE!

*: This doesn't mean that the eigenvectors of \(A\) are unique, we're simply writing down representatives (up to linear combinations of eigenvectors with the same eigenvalue).
**: In particular, the position of these diagonal values line up with which eigenvector I've set as the columns of the matrix \(P_{B\rightarrow S}\) I formed in part (f).

Tuesday, 21 May 2013

Maths on Steroids: 8

W0000! The Puzzle Hunt is over! Now I can finally get some work done. =P

Well, maybe not straight-away...maybe after I watch the entire first season of Pendleton Ward's (*) Bravest Warriors.

Blogging (**) is strange: there's something disarmingly private (even diary-esque?) about writing up a post, especially given how open blogging is as a medium. Okay...okay...okay...fair enough: no-one's actually going to ever read it, but there's still something sort of...umm...faintly and intangibly Huxleyan about all this.

Or not.

Hmm...whatevs, - it's not like I know what I'm on about.

Err...let's just do some maths.

I mentioned at the end of tute 8 that I would write up a solution to a non-standard Gram-Schmidt orthonormalisation question in the yellow book. Something like question 29:

Let \(P_2\) be the vector space of polynomials of degree at most two with the inner product\begin{align}\langle p,q\rangle :=\int_{-1}^{1}p(x)q(x)\,\mathrm{d}x.\end{align}Obtain an orthonormal basis for \(P_2\) from the basis \(\{1,x,x^2\}\) using the Gram-Schmidt process.

To begin with, we just pick one of the three vectors and normalise it. Let's use the vector \(1\in P_2\). We know that the magnitude of this vector is:\begin{align}||1||^2=\langle1,1\rangle=\int_{-1}^{1}1\cdot1\,\mathrm{d}x=2.\end{align}Therefore, the first vector in our orthogonal basis is: \(\frac{1}{\sqrt{2}}\cdot1\in P_2\).

The second step is to take another basis vector, like \(x\in P_2\), and to first remove the \(1\)-component from this vector, before normalising the result to form a new vector. So, consider the vector\begin{align}x-\langle x,\frac{1}{\sqrt{2}}1\rangle\cdot\frac{1}{\sqrt{2}}\cdot1=x-(\frac{1}{2}\int_{-1}^1 x\,\mathrm{d}x)\cdot1=x-0\cdot1=x.\end{align}
At this point, we've got two orthogonal vectors: \(\frac{1}{\sqrt{2}}1\) and \(x\), and we just need to normalise this latter vector to obtain: \begin{align}\{\frac{1}{\sqrt{2}}1,\sqrt{\frac{3}{2}}x\}.\end{align}In this last step, we take the final basis vector \(x^2\in P_2\) and remove the \(1\) and \(x\)-components from this vector, before normalising the result to form a new vector. So, consider the vector\begin{align}&x^2-\langle x^2,\frac{1}{\sqrt{2}}1\rangle\cdot\frac{1}{\sqrt{2}}1-\langle x^2,\sqrt{\frac{3}{2}}x\rangle\cdot\sqrt{\frac{3}{2}}x\\=&x^2-(\frac{1}{2}\int_{-1}^1x^2\,\mathrm{d}x)\cdot1-(\frac{3}{2}\int_{-1}^1x^3\,\mathrm{d}x)\cdot x=x^2-\frac{1}{3}.\end{align}After normalisation, we obtain the Gram-Schmidt orthonormalised basis: \begin{align}\{\frac{1}{\sqrt{2}},\sqrt{\frac{3}{2}}x,\sqrt{\frac{45}{8}}(x^2-\frac{1}{3}).\}\end{align}
W000000.

Note that the answer to this problem is non-unique, because the basis that results from the Gram-Schmidt process depends a lot upon the order in that we feed the original basis into the orthonormalisation procedure. For example, shoving in the vectors in the order \(x^2,x,1\) results in the orthonormal basis: \(\{\sqrt{\frac{5}{2}}x^2,\sqrt{\frac{3}{2}}x,\sqrt{\frac{5}{8}}(1-3x^2)\}.\)

Well, that was that.

The other thing that I promised to do was to give answers to the tute 9 lab sheets. Psst: Turns out that that's going to have to wait because I left the lab sheets at uni again.  >____<

*: the creator of Adventure Time!
**: actually, when you think about it, this is pretty applicable to Twitter, Facebook, YouTube, heck - it's applicable to pretty much anything without a password on the internet.

Thursday, 2 May 2013

Maths on Steroids: Tute 7

I have no idea why inner products are so named. But I do know that there's something called an outer product...they're probably related.

In any case, inner products give us a notion of length and angle on a vector space. The former is given by taking the distance between two vectors \(\vec{u}\) and \(\vec{v}\) to be \(||\vec{u}-\vec{v}||:=\sqrt{\langle\vec{u}-\vec{v},\vec{u}-\vec{v}\rangle}\). And the latter is defined by taking \begin{align}\frac{\langle\vec{u},\vec{v}\rangle}{||\vec{u}||\cdot||\vec{v}||}\end{align} to be \(\cos\theta\), where \(\theta\) is the angle between \(\vec{u}\) and \(\vec{v}\). Of course, in order for this to make sense, we'd need \begin{align}|\langle\vec{u},\vec{v}\rangle|\leq ||\vec{u}||\cdot||\vec{v}||,\end{align}which is precisely the Cauchy-Schwarz inequality.

Usually it's not all that hard to prove that something is an inner product: the linearity and symmetry conditions are fairly straight-forward to check, and positivity is often a matter of doing completing the square in the right way. Having said that, consider the following inner product \(\langle\cdot,\cdot\rangle\) on the vector space \(C^0([0,1],\mathbb{R})\) of continuous real-valued functions on \([0,1]\): \begin{align}\langle f, g\rangle:=\int_0^{1} f(x)g(x)\; \mathrm{d}x.\end{align} In this case, the positivity condition is intuitively obvious, if a function \(f:[0,1]\rightarrow\mathbb{R}\) is not the constant zero function, its square is a non-negative function and should have positive integral over \([0,1]\). But to make this precise, we're going to do a wee bit of analysis. The maths here is, in some sense, fairly easy - it's all in the language. Then again, this language did take some very smart mathematicians ages to formulate, so it's probably not entirely trivial?

Time to think positive!

We just need to show the second part of positivity, the first part is pretty obvious. So, we need to show that if \(f\in C^0([0,1],\mathbb{R})\) is not the constant zero function, then\begin{align}\langle f,f\rangle=\int_0^1 f(x)^2\;\mathrm{d}x>0.\end{align} Now, we know that \(f\) is not everywhere zero, so for some (interior) point \(x_0\in [0,1]\), the function \(f\) spits out some number \(f(x_0)\neq 0\). By the \(\epsilon-\delta\) definition of continuity, for any positive number \(\epsilon\) there's a small neighbourhood \((x_0-\delta,x_0+\delta)\) around \(x_0\) so that \(f\) spits out numbers between \(f(x_0)-\epsilon\) and \(f(x_0)+\epsilon\) on this neighbourhood. So if we take \(\epsilon\) to be small enough, then on \((x_0-\delta,x_0+\delta)\), the magnitude of \(f\) will be greater than some constant \(c>0\). Therefore:\begin{align}\langle f,f\rangle=\int_0^1 f(x)^2\;\mathrm{d}x\geq\int_{x_0-\delta}^{x_0+\delta} f(x)^2\;\mathrm{d}x>\int_{x_0-\delta}^{x_0+\delta} c^2\;\mathrm{d}x=2\delta c^2>0.\end{align} And we're done.

So ugh...that was totes not on the course syllabus, although it used to be...sorta...a few years ago. But if you decide to do any maths next year you're pretty likely to bump into this \(\epsilon-\delta\) stuff again. So umm...here's something-else that's not quite on the syllabus: well, okay, it's more of a parting thought than anything-else. In playing around with these inner products, sometimes we encounter something that doesn't quite satisfy the second part of the positivity condition. For example: the following symmetric (bi)linear function on \(\mathbb{R}^3\) does not satisfy the positivity condition that says that \(||\vec{u}||=0\) if and only if \(\vec{u}=\vec{0}\),\begin{align}\langle(x_1,x_2,x_3),(y_1,y_2,y_3)\rangle:=&2(x_1+2x_2+x_3)(y_1+2y_2+y_3)\\+&e(x_2-x_3)(y_2-y_3)\\+&\pi(x_1+3x_3)(y_1+3y_3).\end{align}Well, there're two ways of fixing this problem so that we end up with a vector space with a legit inner product. The first is to restrict ourselves to a vector subspace on which our inner product does satisfy the final positivity condition. And there are many many such choices of a vector space in this particular case - such as:\begin{align}V:=\{(x,y,z)\in\mathbb{R}^3|-3x+y+z=0\}.\end{align}And the second method is to equate certain vectors in our vector space \(\mathbb{R}^3\), and thereby creating a new vector space called a quotient space \(\mathbb{R}^3/W\), where \begin{align}W:=\mathrm{Span}_{\mathbb{R}}([-3,1,1])=\{\text{vectors whose ``length" is zero}\}.\end{align} Note that althought you might find quotient spaces a tad intimidating the first time that you see them, quotienting just means that we think of two vectors \(\vec{u}\) and \(\vec{v}\) that differ by some element in \(W\) (that is: \(\vec{u}-\vec{v}\in W\)) as being the same vector. In fact, this is how we do modular arithmetic! E.g.: one way of defining \(\mathbb{Z}_2\) is to take all the integers and regard the ones that differ by even numbers as being the "same". So, \(1\) is the same as \(3\) is the same as \(5232320009\) (modulo \(2\)).

Now, this quotient space idea has the slight advantage that there's really just one way of doing it. Although we do need to show that for some some nearly-inner product space \((V,\langle\cdot,\cdot\rangle)\), the set \begin{align}W:=\{\text{vectors whose ``length" is zero}\}\end{align} is always a vector subspace. Soooo...Subspace Theorem time!
  • Axiom 0: \(W\) is non-empty because the vector \(\vec{0}\) is always length zero.
  • Axiom 2: Since \(\langle\alpha\vec{w},\alpha\vec{w}\rangle=\alpha^2\langle\vec{w},\vec{w}\rangle=0\), \(W\) is closed under scalar multiplication.
  • Axiom 1: This is slightly trickier, we need to show that for two vectors \(\vec{w}_1,\vec{w}_2\in W\), their sum \(\vec{w}_1+\vec{w}_2\) is in \(W\). Well, we know that \begin{align}\langle \vec{w}_1+\vec{w}_2,\vec{w}_1+\vec{w}_2\rangle=\langle\vec{w}_1,\vec{w}_1\rangle+2\langle\vec{w}_1,\vec{w}_2\rangle+\langle\vec{w}_2,\vec{w}_2\rangle=2\langle\vec{w}_1,\vec{w}_2\rangle,\end{align} so all we need to do is show that this last term is also zero - so, we just need some weaker version of the Cauchy-Schwarz inequality that applies to a nearly-inner product. Here's a proof: our result is obviously true if either \(\vec{w}_1\) or \(\vec{w}_2\) is the zero vector, so let's ignore that case. Then we know from the first part of positivity that:\begin{align}0\leq\langle\frac{\vec{w}_1}{||\vec{w}_1||}\pm\frac{\vec{w}_2}{||\vec{w}_2||},\frac{\vec{w}_1}{||\vec{w}_1||}\pm\frac{\vec{w}_2}{||\vec{w}_2||}\rangle=1\pm2\langle\frac{\vec{w}_1}{||\vec{w}_1||},\frac{\vec{w}_2}{||\vec{w}_2||}\rangle+1\\\Rightarrow||\vec{w}_1||\cdot||\vec{w}_2||\geq\pm\langle\vec{w}_1,\vec{w}_2\rangle\Rightarrow||\vec{w}_1||\cdot||\vec{w}_2||\geq|\langle\vec{w}_1,\vec{w}_2\rangle|.\end{align} So yea, \(|\langle\vec{w}_1,\vec{w}_2\rangle|\) is less than \(0=0\cdot0\), and we've shown that \(W\) is closed under vector addition.
You might think that this is all pretty useless, but oddly enough this sort of stuff keeps cropping up in maths, often for perfectly legitimate reasons. Like, that inner product that we defined on the space of continuous functions? Well, if you try to ditch the word continuous and replace it with something like square-integrable (and this is a perfectly pragmatic thing to do - sometimes you want to integrate functions which aren't continuous, like car acceleration...etc.), you'll suddenly find that our integral based inner product now fails the last positivity condition. So peeps actually use this quotient space technology to fix this problem and do some functional analysis and stuff...and stuff.

Okay okay okay, we're done. =)

Wednesday, 24 April 2013

Maths on Steroids: Tute 6

I have no idea why I thought that today was Yom Kippur - especially because I actually thought that it was Jewish New Year's Day: Rosh Hashanah. I suspect that a combination of illness, watching old Family Guy and South Park episodes and stealing a glance (over someone's shoulder on the train) on a Rabbi's chaplaincy report (*) must have caused my mind to mash all of these ingredients into some crazy-festive-kosher-holiday-cake-mix. And if that doesn't make sense, well good - it doesn't make any sense to me either. But let's all hope that the maths that I'm about to write does make sense.

Sooooo guys, remember this question from your assignment?

"Find an \(n_0\) such that for all \(n\geq n_0\), \(3^n>n^4\). Give a proof by induction."

Well, it's pretty painful for me to mark a proof by induction by induction in an induction in an induction (**), so I'm going to remind you guys that comparison trick that I showed you in the tutes...obviously, I'm only going to do the induction step, and I'll forgo the usual setting-up:

Assume that \(3^k>k^4\) is true, let's show that \(3^{k+1}>(k+1)^4.\)

Well, since \(k\geq 8\) - this follows from the base case holding for \(n_0=8\), we obtain the following sequence of inequalities:\begin{align}3^{k+1}> k^4+2k^4&\geq k^4+16k^3\\&=k^4+4k^3+12k^3\\&\geq k^4+4k^3+96k^2\\&>k^4+4k^3+6k^2+4k+1=(k+1)^4.\end{align} Note that I've tweaked it a tiny bit from what we did in class - just because \(k\geq 8\), doesn't mean that your inequalities always have to be of the form \(k^{m+1}\geq 8 k^{m}\). Speaking of tweaking stuff, Nick came up with a cute version of this comparison trick in his assignment. If you don't mind fractions, you can just straight off use that:\begin{align}k^4+4k^3+6k^2+4k+1\leq(1+\frac{4}{8}+\frac{6}{8^2}+\frac{4}{8^3}+\frac{1}{8^4})k^4=\frac{6561}{4096}k^4<3k^4<3^{k+1}.\end{align}

Oh, and one final comment before we go through the MATLAB graphing code from this week's tutorial: be aware of the flow of your logical arguments. I understand that sometimes your thinking as you progress through a proof is pragmatic, it's like: to get A, I need B; to get B, I need C...etc. But when it's written simply in the form: A, B, C, ... with no (backwards) implication arrows, I'm going to assume that you mean that A implies B and B implies C and so forth.

Orrite, MATLAB time! First things first, here's the code for the m-file that I used to generate the MATLAB plot during Tuesday's lab:

x=-3:0.1:3;
n=length(x);
y=[];
for k=1:n
    if x(k)<-2
        y(k)=0;
    elseif x(k)<0
        y(k)=x(k)^2;
    else
        y(k)=x(k)^3+2;
    end
end
plot(x,y,'*')

Ultimately, we want to produce a graph (of points) by the end of this exercise using MATLAB's "plot" function. Now, plot works by taking in two vectors of the same length \(x\) and \(y\) and using them respectively as the \(x\) and \(y\)-coordinates of the points that we wanna plot. And specifying '*' or 'x' or '+' or '-' in the third entry in plot(x,y,'*') tells MATLAB what type of points it should draw. If you just type plot(x,y), MATLAB will "join the dots" by default - try it out and see what happens!

Let's break it down, line by line:
  1. We create a vector \(x=[-3, -2.9, -2.8,\ldots, 2.9, 3]\). This will constitute the \(x\)-values of the points that we'll draw.
  2. Since we need to create a vector of \(y\)-values of the same length, I decided to create a variable \(n\) that keeps track of the length of \(x\).
  3. We create a vector called \(y\) that at the moment is empty. As in, it's a length zero vector. This step is, I think, unnecessary in MATLAB, but I dunno, I see it around every so often - maybe it's important in another programming language? If anyone knows, tell me. =P
  4. We start out for-loop. Note that \(1:n\) creates a vector of the form\[[1,2,3,\ldots,n-2,n-1,n],\]and for loop basically goes through this vector and runs everything inside of the for-loop (i.e.: lines 5~11) first for \(k=1\), then for \(k=2\), then for \(k=3\),...etc., until \(k=n\). 
  5. This is the beginning of our if-loop inside of our for-loop. And the first condition is to check if the \(k\)th value of the vector \(x\) is less than -2. So recall: \(x(k)\) means the \(k\)th value of \(x\).
  6. If the condition of \(x(k)<-2\) is satisfied, then we set the \(k\)th value of the vector \(y\) to be \(0\). Note that if \(y\) is shorter than length \(k\), this step implicitly extends the \(y\) vector to being length \(k\). Just to reiterate: the final outcome of this first portion of the if-loop is that if our \(x\) values are strictly less than \(-2\), our \(y\) is just \(0\). Which is precisely the first part of the hybrid function that we're meant to draw.
  7. This second condition of our if-loop checks if the \(k\)th entry of \(x\) is less than \(0\). Note that since the first condition of the if-loop has already taken care of \(x(k)<-2\), this condition is really checking for when \(-2\leq x(k)<0\).
  8. Given that the condition that \(-2\leq x(k)<0\) is fulfilled, we assign the \(k\)th entry of the \(y\) vector to be our \(x\) value squared. So, this is just saying that on the domain of \([-2,0)\), we're drawing the graph of \(f(x)=x^2\).
  9. This last condition of our if-loop takes in everything-else in our domain (which in this case is \([-3,3]\) - I just picked this domain out of thin air, in the actual MATLAB exam, it should be given). So in this case, we'll end up dealing with \(0\leq x(k)\leq 3\).
  10. Much like line 8, this is just saying that on the \([0,3]\) portion of our domain, the graph that we're drawing looks like \(f(x)=x^3+2\).
  11. Ends our if-loop.
  12. Ends our for-loop. Notice that you can always tell the start and ends of an if or a for loop using the natural indentations that MATLAB introduces.
  13. Uses the plot-function native to MATLAB to draw our points on a plane.
Psst: at each step here we put a semi-colon ; at the end of every line where MATLAB does a computation. This stops the program from outputting something on the screen - otherwise you'd get clunky computations appearing in the program console. Try to remove one of those semi-colons and running the program if you wanna see what I mean. Also, the most common mistake that students make with the sort of problem in the MATLAB exam is to write \(x\) instead of \(x(k)\) and \(y\) instead of \(y(k)\) inside the loops. Always remember that \(x\) and \(y\) are vectors! Another common mistake is to get the conditions for the if-loop wrong, I mean: sometimes you need strict inequalities, sometimes you need non-strict ones.

So, I hope that all made sense, because I'm about to show you some other ways of drawing this graph. Now, recall from the first week that we can concatenate two row-vectors \(w1\) and \(w2\) by writing \([w1,w2]\) in MATLAB. Well, we could have used this to "extend" our \(y\) vector from a length \(0\) vector to a length \(n\) vector. And here's how: instead of writing \(y(k)=0\), \(y(k)=x(k)^2\) and \(y(k)=x(k)^3+2\), we could have respectively written \(y=[y,0]\), \(y=[y,x(k)^2]\) and \(y=[y,x(k)^3+2]\). Make sure that you understand why that works. Remember: it's MATLAB, if you wanna know how something works, just type it into the console and see what happens!
And there's an even "better" way of drawing these vectors without using if and for loops, which is very natural to MATLAB. It does have the slight disadvantage in that for the program that we wrote, we can increase the resolution of our graph by changing the parameter \(r\) in \(x=-3:r:3\) to be something smaller/finer. And the method that I'm about the describe is a tiny bit messier in this regard. But yea...the idea is that we can just produce the vector \(y\) "directly":

x1=-3:0.1:-2.1;
y1=0*x1;
x2=-2:0.1:-0.1;
y2=x2.^2;
x3=0:0.1:3;
y3=x3.^3+2;
x=[x1,x2,x3];
y=[y1,y2,y3];
plot(x,y,'+')

In fact, we could probably shorten all of that into just three lines, but I don't have MATLAB with me right now and I can't check if what I wanted to write down makes any sense. You guys should totes try to condense it to three lines though!

*: conclusion: Rabbis are the win! Respect ++. =P
**: having read that sentence, you now know how it feels.

Wednesday, 17 April 2013

Maths on Steroids: Tute 5

Arghghh...so cold.

I have basically zero cold tolerance. I wonder if it has something to do with my consistently running off to South East Asia during the last few Aussie winters. Maaan, those were good trips: got more than fifty mosquito bites on just one arm on the first night (in a malarial region, the guy I shared a room with and the two kids next door had malaria), spent hours cleaning toilets in a house of guys, nearly rode a motorbike off a cliff...etc, and yet still some of my happiest and most relaxing holidays (*) ever! =D

So yea, sometimes things aren't quite what you expect them to be - and today, I'mma write down one example of something that you mightn't have expected to be a vector space.

A vector space is essentially a whole bunch of vectors so that you may perform vector addition and scalar multiplication to your heart's content. So why are these two things important? Well, they're the basis of row-reduction, right? If you can add and subtract vectors and scalar multiply vectors then you can do row-reduction, which in turn means that you can solve linear equations...etc, and you basically get all of linear algebra.

We formalise this intuition with a semi-clunky definition that says that a vector space is a set \(V\) with a notion of addition \(\oplus\) and scalar multiplication \(\otimes\) that satisfy eight axioms. Most of the time, the addition and scalar multiplication is pretty obvious, but if I choose my vector space to be based on the set \(V:=\mathbb{R}^{+}=(0,\infty)\), then the usual addition and scalar multiplication will not suffice to make \(V:=\mathbb{R}^+\) a vector space.

But what if we took \begin{align}u\oplus v:=u\times v=uv\text{ and }\alpha\otimes v:=v^\alpha?\end{align} Turns out this will make \((V,\oplus,\otimes)\) a real vector space.

Let's check this for all eight axioms. We're going to assume through-out and \(u,v,w\) are arbitrary vectors in \(V\), and \(\alpha,\beta\) are arbitary real scalars in \(\mathbb{R}\).
  1. Associativity of \(\oplus\): \begin{align}u\oplus(v\oplus w)=u\oplus (vw)=u(vw)=uvw=(uv)w=(uv)\oplus w=(u\oplus v)\oplus w.\end{align}
  2. Commutativity of \(\oplus\): \begin{align}u\oplus v=uv=vu=v\oplus u.\end{align}
  3. Additive identity element: this is actually slightly tricky. The identity (or zero) element in this vector space isn't the number \(0\) - which isn't even an element in \(V=\mathbb{R}^+\). It is in fact the number \(1\in V\)! And here's the proof that \(1\) is the zero-element (**):\begin{align}1\oplus v=1\times v=v.\end{align}
  4. (Additive) Inverse element: this is also slightly tricky, but I guess if you're figured out the last point, this should make sense. Now, since \(v\in\mathbb{R}^+\), its reciprocal \(v^{-1}\) is also in \(V=\mathbb{R}^+\) and is indeed the inverse element of \(v\):\begin{align}v\oplus v^{-1}=v\times v^{-1}=1.\end{align}
  5. Distributivity I:\begin{align}\alpha\otimes(u\oplus v)=\alpha\otimes (uv)=(uv)^{\alpha}=u^{\alpha}v^{\alpha}=(\alpha\otimes u)(\alpha\otimes v)=\alpha\otimes u\oplus\alpha\otimes v.\end{align}
  6. Distributivity II:\begin{align}(\alpha+\beta)\otimes v=v^{\alpha+\beta}=v^{\alpha}v^{\beta}=(\alpha\otimes v)(\beta\otimes v)=\alpha\otimes v\oplus\beta\otimes v.\end{align}
  7. Compatibility of scalar multiplication:\begin{align}\alpha\otimes(\beta\otimes v)=\alpha\otimes(v^{\beta})=(v^\beta)^{\alpha}=v^{\alpha\beta}=(\alpha\beta)\otimes v.\end{align}
  8. Scalar identity element: in this case, the scalar identity element is \(1\in\mathbb{R}\) - note that we're distinguishing this from \(1\in V=\mathbb{R}^+\), which is totally a vector. =)\begin{align}1\otimes v=v^{1}=v.\end{align}
Oh good! We've checked all eight axioms and see that \((V,\oplus, \otimes)\) is indeed a vector space.

Now, if you really think about it, what's REALLY going on is that I've simply disguised the usual one-dimensional real vector space \((\mathbb{R},+,\times)\) as \((V,\oplus, \otimes)\) by exponentiating and then re-interpreting what addition and multiplication means once we've exponentiated (***). So here's an exercise:

Make \((0,1)\) into a vector space!

*: surprisingly more relaxing than spending a lot of time onsen-ing in Japan?
**: yes, it sounds stupid, but the truth often sounds stupid. =)
***:it doesn't matter which exponent you choose, so long as it's positive and not \(1\).

Saturday, 13 April 2013

Maths on Steroids: Tute 4

I didn't think that I was going to write up this post. But there's something compelling about the following question from the yellow Accelerated Mathematics exercise (*) book. It is, after all, one of my favourite questions from the book (as in, it was around when I did one of the old incarnations of this subject).

To be honest, I never managed to solve it. I thought about it for a day or two but just couldn't really make any headway. And I'm not sure who eventually showed me how to do it - probably Nick Sheridan or Zhihong Chen, or both. But here it is, in all its unadulterated vexatiousness:

Problem sheet 3, question 19 (official rating: Very hard easy):

Prove that, for any 1993 integers, there is a subset whose sum is divisible by 1993.

Okay, well, you can see that this version of the question is a bit outdated. Like, twenty years outdated. So let's solve it, but with 1993 changed to 2013. =P

Now, you might think this changing of numbers is just some general frivolousness on my part, but there's something to it: I've just hinted that this property isn't specific to the number 1993 - which is prime, but also applies to 2013 - which certainly isn't. So, whatever strategy that we try had better not need prime-factor-based arguments (**).

Now, let's call these integers \(a_1, a_2, a_3,\ldots, a_{2013}\) and consider the following related integers:\begin{align}b_1&=a_1,\\ b_2&=a_1+a_2,\\b_3&=a_1+a_2+a_3,\\&\vdots\\b_{2013}&=a_1+a_2+a_3+\ldots+a_{2013}.\end{align}

Now, if any of these \(b_i\)s is a multiple of \(2013\), then we're done - because each \(b_i\) is the sum of some subset of the \(a_j\)s.

On the other hand, if none of the \(b_i\)s are a multiple of \(2013\), then their remainders when divided by \(2013\) are going to be integers between \(1\) and \(2012\). So, we've got 2013 \(b_i\)s, and their remainders could be one of 2012 different numbers; by the pigeonhole principle (try squeezing 2013 pigeons into 2012 holes), two of these numbers \(b_n\) and \(b_{n+m}\) must have the same remainder. But this means that \begin{align}b_{n+m}-b_n=a_{n+1}+a_{n+2}+\ldots+a_{n+m}\end{align} is a multiple of \(2013\). And we're done!

Okay, I admit that looked pretty easy, and in some sense...it was pretty easy. But to someone who hasn't done very much recreational or puzzly maths (or just maths), there's a stunning idea there - that in reorganising things you can sometimes observe the patterns more easily. Orrite orrite, it sounds even more trivial and trite and obvious when I put it like that, but I think that you get the point. So much of mathematics is based on organising things neatly. E.G.: matrices arise from wanting to organise linear equations neatly, and anyone who's done and understood a course in linear algebra can tell you how amazing matrices are.

So ugh...yea...totes do the "Very hard" questions in the exercise book guys...guuuuuys? =P

*: I don't know why, but it'd taken me years to learn how to spell "exercise". I guess I always used to chuck an extra "c" after the "x". Shrug

**: If you think about it, it's kinda weird that the difficulty of the question is somehow hugely affected by what number you give. And that in this case, giving a "nicer" number - a prime, actually makes the problem way harder. Just coz you get distracted by it.

Wednesday, 27 March 2013

Maths on Steroids: Tute 3

Guys from my tute! I lied to y'all on Tuesday (well, sorta lied)!

But first, a very short story.

There was a period, during the summer holidays, that my friends and I used to play 20 Questions (I did not know that it was made into a TV show) after lunch every day. And being the sound logicians that we are, we ask all the regular questions like:
  • "Are you real?"
  •  "Are you male?" and 
  • "Do most of the letters constituting your name lie in the first half of the alphabet, where "most" is taken to mean "at least half""?
And I remember this one time that someone asked "Are you alive?", and this simple little question was met by a mask of furrow-browed incertitude and a very very hesitant "Yes, I think I'm alive".

We soon figured out that either he'd given us a really philosophical response, or - as was the case - we were dealing with Alexander Grothendieck.

And that's the end of my story. (Note: Grothendieck has since passed away. =/ )

Enter: vector resolutes vs. projections (a la our tutorial).

So, one of you asked me why we've renamed "vector resolutes" as "vector projections" and I made an offhanded remark about mathematicians loving the term "projection" partially due to Grothendieck. Well, that was at least half-false. =P  I don't really know why we like "projection" - although it is certainly a more conceptually meaningful word (*) than "resolute" - I was sorta hinting at the mathematical construction called "projectivisation" (usually just Proj) that's used like, a hella lot in algebraic geometry. And somewhere in the deep dark recesses of my mind, there's a small footnote that says that Grothendieck has a lot to do with projectivisations.

Anyhoo, let's talk about proving the following vector identity:\begin{align}\vec{a}\times(\vec{b}\times\vec{c})=(\vec{a}\cdot\vec{c})\vec{b}-(\vec{a}\cdot\vec{b})\vec{c}.\end{align}Now, you all got pretty close to bashing this out this identity as per the hint that was given in the yellow book, and I think that's probably the safest proof of this identity that I've seen. To my understanding, most of you will probably just expand out the left hand side, expand out the right hand side and go - O look, they're the same.

That's fine, but you should have a think about how to get straight from the left all the way to the right via factorisation near the end. Hint: you'll need to add and subtract the term \(a_ib_ic_i\) for each coordinate.

I'm going to explain an alternate way of proving this result, which - although algebraic - is slightly more geometric in feel. To begin with, let's talk about the standard unit vectors in \(\mathbb{R}^3\):\begin{align}\vec{e}_1=[1,0,0],\;\vec{e}_2=[0,1,0]\text{ and }\vec{e}_3=[0,0,1].\end{align}Now, these vectors are mutually perpendicular (ortho) + they're unit vectors (normal), and in maths, we call them (together) orthonormal vectors. And you guys can easily show that\begin{align}\vec{e}_1\times\vec{e}_2&=-\vec{e}_2\times\vec{e}_1=\vec{e}_3\\\vec{e}_2\times\vec{e}_3&=-\vec{e}_3\times\vec{e}_2=\vec{e}_1\\\vec{e}_3\times\vec{e}_1&=-\vec{e}_1\times\vec{e}_3=\vec{e}_2.\end{align}
Thanks to these cross-product identities, it's really really easy to verify our vector identity above for these three vectors, right? In fact, by the right-hand rule, if we think about what's geometrically happening to three generic orthogonal vectors \(\vec{u},\vec{v},\vec{w}=\vec{u}\times\vec{v}\), then we should certainly expect the following identities:\begin{align}\vec{u}\times\vec{v}&=-\vec{v}\times\vec{u}=\vec{w}\\\vec{v}\times\vec{w}&=-\vec{w}\times\vec{v}=\vec{u}\\\vec{w}\times\vec{u}&=-\vec{u}\times\vec{w}=\vec{v},\end{align}and we'd have no problems checking our result. So, wouldn't it be great if somehow the vectors \(\vec{a},\vec{b},\vec{c}\) were sorta close to being orthonormal-ish?

So here's a way to make that almost happen. Observe (i.e.: stare really hard) that the truthiness of our identity isn't affected by us multiplying any of the three vectors by a non-zero constant. So, what I mean is that if we know that: \begin{align}\vec{a}\times(\frac{\vec{b}}{|\vec{b}|}\times\vec{c})=(\vec{a}\cdot\vec{c})\frac{\vec{b}}{|\vec{b}|}-(\vec{a}\cdot\frac{\vec{b}}{|\vec{b}|})\vec{c}\end{align}
is true/false, then our desired identity must be true/false - this is of course assuming that \(\vec{b}\neq\vec{0}\), but then the identity is really easy to prove if that were the case. Therefore, we may assume without loss of generality (wlog) that \(\vec{b}\) is a unit vector.

Now, this scaling business means that we can make any of the vectors a unit vector (unless if it's the \(\vec{0}\) vector, but then the identity is really easy if any of them is the zero vector). But that's not quite good enough - I mean, orthogonality is sort of the more important bit. If only we could somehow replace \(\vec{c}\) with \[\vec{c}'=\vec{c}-(\vec{b}\cdot\vec{c})\vec{b},\]
which we know is orthogonal to \(\vec{b}\). Well, we can certainly do this on the left-hand side, because\[\vec{b}\times\vec{c}'=\vec{b}\times\vec{c}-(\vec{b}\cdot\vec{c})\vec{b}\times\vec{b}=\vec{b}\times\vec{c}.\]
And we can do so on the right hand side because\begin{align}&(\vec{a}\cdot(\vec{c}-(\vec{b}\cdot\vec{c})\vec{b}))\vec{b}-(\vec{a}\cdot\vec{b})(\vec{c}-(\vec{b}\cdot\vec{c})\vec{b})\\=&(\vec{a}\cdot\vec{c})\vec{b}-(\vec{b}\cdot\vec{c})(\vec{a}\cdot\vec{b})\vec{b}-(\vec{a}\cdot\vec{b})\vec{c}+(\vec{a}\cdot\vec{b})(\vec{b}\cdot\vec{c})\vec{b}\\=&(\vec{a}\cdot\vec{c})\vec{b}-(\vec{a}\cdot\vec{b})\vec{c}.\end{align}So, we may assume wlog that \(\vec{c}\) is orthogonal to \(\vec{b}\). In fact, we can also assume that \(\vec{c}\) is normal by normalising \(\vec{c}'\), and again I should say something like if \(\vec{c}'\) is the zero vector, then everything is easy.

So, we've got orthonormal vectors \(\vec{b},\;\vec{c}\) and \(\vec{d}:=\vec{b}\times\vec{c}\), and if I re-position my \(x,y,z\)-axes in \(\mathbb{R}^3\) to line up with these three vectors, I can see that any vector in \(\mathbb{R}^3\) may be written in a unique way as a sum of these three vectors. In fact, you'll learn after the Easter break that this is what we call a basis for \(\mathbb{R}^3\). In particular, our vector \(\vec{a}\) may be written in the form:\[\vec{a}=\alpha_b\vec{b}+\alpha_c\vec{c}+\alpha_d\vec{d}.\]
Now, let's calculate the two sides of our desired identity and prove it!

On the left-hand side, we have:\begin{align}&\vec{a}\times(\vec{b}\times\vec{c})\\
&=(\alpha_b\vec{b}+\alpha_c\vec{c}+\alpha_d\vec{d})\times\vec{d}\\
&=-\alpha_b\vec{c}+\alpha_c\vec{b}.\end{align}Note that this makes use of that stuff we were saying about cross-products of orthonormal vectors at the start of this proof. And on the right-hand side, we have:\begin{align}(\vec{a}\cdot\vec{c})\vec{b}-(\vec{a}\cdot\vec{b})\vec{c}=\alpha_c\vec{b}-\alpha_b\vec{c},\end{align}
where we've made use of the orthogonality of the vectors \(\vec{b},\vec{c}\) and \(\vec{d}\).

Orrite, to be honest, that did seem kinda long as a proof, but I think that it's nicer than bashing it out directly because you get this additional understanding to do with scaling these vectors and making them orthogonal and jazz. But I have to warn you: I did make use of the right-hand rule and we had a physical-intuition based argument for why the cross products of any orthonormal vectors \(\vec{u},\vec{v},\vec{w}\) should be as I described. And for that reason alone, if this question crops up in an assignment or (God-forbid?) the exam, just bash it out. It's actually not so painful the second time you do it - I think that my second time took about 2~3 minutes?

So...ugh...happy Easter guys!

(*): I'm thinking of movie projectors here, but I think that might actually be kinda backwards, because the peeps who first invented and made projectors might actually be semi-familiar with the word "projection".

Tuesday, 19 March 2013

Maths on Steroids (Accelerated Mathematics): Tutes 1 and 2

Orrite guys, some of you were asking me about the last tute question in the MATLAB prac sheet today, so I'll try to walk you through how to do the "simple programming" task there. But first, let me tell you a little story.

First week of my first year at uni, I learned a little something called row reduction. Naturally, the first thing that I did was to ignore the lecturer (sorry Paul (*)), and fiddle around with some matrices. And, here's what I did: \begin{align}&\left[\begin{array}{rrr|l} 1 & 0 & 0 & 2 \\ 0 & 1 & 0 & 2 \\ 0 & 0 & 1 & 2 \end{array}\right] \begin{array}{l} R_1\rightarrow R_1-R_2 \\ R_2\rightarrow R_2-R_3 \\ R_3\rightarrow R_3-R_1\end{array} \sim \left[\begin{array} {rrr|l} 1 & -1 & 0 & 0 \\ 0 & 1 & -1 & 0 \\ -1 & 0 & 1 & 0 \end{array} \right]. \end{align} So, that was pretty innocuous right? I mean, all I did was to be a fully-sick efficient guy and do a few row-reductions together; what could possibly go wrong?

And yet, something is very wrong.

I mean, I started off with this augmented matrix that had a unique solution of \(x=y=z=2\) and winded up with a system of equations that has \(\infty\) many solutions (you can check this by getting the row echelon form of this latter matrix)! Being a totally cocky first year, I was all like...oh man oh man oh man oh man, I broke maths.

Soooo, for any one in my tute who's reading this - see if you can figure out what I screwed up, and see if you can clearly articulate your idea/s to me before/during our next tute. =)

Onto this week's Lab sheet exercise 4!

You played around with the following rowswap function today in MATLAB:

function [B,E]=rowswap(A,x,y)
    % this function performs a row swap operation and creates the
    % associated elementary matrix.
    temp=A(x,:);
    A(x,:)=A(y,:);
    A(y,:)=temp;
    E=eye(size(A,1));
    temp=E(x,:);
    E(x,:)=E(y,:);
    E(y,:)=temp;
    B=A;

And exercise 4 requires you to tweak this function so that this becomes a column-swapping function instead. So let's first try to understand these lines.

1. The very first line:

"function [\(B,E\)]=rowswap(\(A,x,y\))" 

has always been the most inscrutable one to me. Now, I am not programmer and I can only tell you what this practically means. Basically, it tells Matlab that this m-file is going to be a function called rowswap. And that this rowswap function takes in 3 inputs: \(A, x, y\) and is capable of spitting out two things: \(B\) and \(E\). We saw from the lab that \(A\) is a matrix (in our case, a \(4\times 4\) matrix) and we tell the function which rows we want to swap by specifying \(x\) and \(y\).

2,3. The next two lines have a percentage sign out the front and are commented out. That is, MATLAB totes ignores these two lines.

4. In the fourth line, we create a new variable called temp (the name isn't important, I could have called it werewolfram but that'd take more letters to type) and we assign it to be \(A(x,:)\). So let's remind ourselves a little something that we learned last week.

Now, when we run this program, \(x\) is some number that we enter, like \(x=1\). Last week we saw that in MATLAB,
typing \(A(1,1)\) gives you the \((1,1)\)-th entry of the matrix \(A\),
typing \(A(1,2)\) gives you the \((1,2)\)-th entry of the matrix \(A\),
typing \(A(1,3)\) gives you the \((1,3)\)-th entry of the matrix \(A\), and so forth.

We also saw that the colon \(:\) has to do with producing vectors of integers. For example, typing \(1:9\) into MATLAB gives you the vector: \begin{align}[1\, 2\, 3\, 4\, 5\, 6\, 7\, 8\, 9],\end{align}
so it's perhaps not surprising that if you type in \(A(x,:)\), you should get you get the \(x=1\)th row of the matrix \(A\): \begin{align}[A(1,1)\, A(1,2)\, \ldots A(1,n)].\end{align} In short: the fourth line sets temp to be the \(x\)th row of \(A\).

5. If you followed the above point, it should be clear that the fifth line sets \(A(x,:)\) to be \(A(y,:)\), that is: we're replacing the \(x\)th row of \(A\) with the \(y\)th row of \(A\). So, this achieves half of our goal, which is to switch rows \(x\) and \(y\).

6. Now, obviously we can't just replace the \(y\)th row of \(A\) with the (current) \(x\)th row of \(A\), because we've just replaced the \(x\)th row of \(A\) in the last step. But thankfully we've got a backup of the original \(x\)th row of \(A\) stored as temp. And so the sixth line is just to replace the \(y\)th row of \(A\) with temp.

7-10. I'm not going to spell out the specific details of each step because you guys are all smart enough to figure this out. But the aim of these steps is to create a matrix called \(E\) that corresponds to the elementary matrix that does a row swap between rows \(x\) and \(y\) when you multiply a matrix on the left by \(E\). Oh, and if you're thrown off by what \(size(A,1)\) does, go to a lab, type in a (preferably non-square) matrix \(A\) and type \(size(A)\) and \(size(A,1)\) and \(size(A,2)\) and see what you get.

11. In this last step, we set \(B\) to be the row-swapped matrix \(A\) that we've produced in lines 4-6, and this is one of the two matrices that the rowswap function outputs (we mentioned this in line 1).

Now, you've been asked to turn this whole thing into a column-swapping function, well, before I tell you how to do it, you should really have a think about how you might do this. In fact, at the end of my second year, I decided to learn some topology, so I went to the library and found a nice looking book and started reading the definitions. Being the typical maths book, it's got a section of definitions, then some examples (actually, I might be wrong about this, it might have been one of those rare books that gives motivating examples before definitions) followed by some theorems. And I just recall reading the statement of every theorem and then proving/trying to prove the result myself before reading their proof.

And you learn so much from doing this. Because often you'll find that perhaps your proof is more intuitive, but their's is cleaner. In fact, if you find that their proof is really unintuitive and seemingly belaboured, then that's especially useful: it tells you that either you've understood some of the concepts wrongly, or that their proof actually generalises much more easily in a more general framework than the particular result that's given.

So...that was enough time for you to have figured out how to do it yourself, right?

The idea is to just go through every line, and switch the roles of the row-coordinates and column-coordinates. Specifically, replace \(A(x,:)\) with \(A(:,x)\), and similarly for the matrix \(E\). Also, take care with what's going on with the \(size(\cdot)\) function - it shouldn't make a difference for a square matrix, but it will for a non-square matrix.

We finish this section with a few small remarks:

1. Every line of the code ends with a semi-colon. Is this necessary? Maybe you can try to run a version of the code where this semi-colon is taken away. Does the code still work? And if it still works, then what's changed?

2. Also, having now understood this code, you should realise that it seems to be a bit inefficient. In the sense that you should be able to do the whole thing without actually writing lines 4-6, because in lines 7-10 you produce an elementary matrix whose role is to switch rows \(x\) and \(y\). In fact, the following code should suffice:

function [B,E]=rowswap(A,x,y)
    E=eye(size(A,1));
    temp=E(x,:);
    E(x,:)=E(y,:);
    E(y,:)=temp;
    B=E*A;

So, why isn't it written this way? Maybe it's easier for you guys to figure out what's going on in the code without having to deal with the \(size\) function straight up? Maybe the guy who wrote the sheet didn't think of this? Whatever the case, I think that the original code is possibly more...computer-friendly. And I mean this in the sense that the original algorithm requires computers to do fewer computation. But yea, whatevs...that's more of a random remark. =)

Allllso...some additional shameless advertising (that I'm doing outside of my duties as your tutor, much as writing up this stuff is outside of my duties as your tutor :P): I'm helping to start up a new Bible study thingy on Tuesday arvos (especially for peeps who can speak Chinese, I guess? Coz some of the students who are currently in it are a lot more comfortable with Mandarin), so if you're interested you can always contact me?

(*) you guys are thinking of the wrong Paul (**), I meant Paul Pearce,
(**) I hope that you guys are thinking of the wrong Ron Paul. =P