Math – Elektromagnetisme http://elektromagnetisme.no The home of FYS1120 Mon, 20 Oct 2014 11:23:54 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.3 28429679 Some peculiar Trigonometric Identities http://elektromagnetisme.no/2010/09/22/some-peculiar-trigonometric-identities/ http://elektromagnetisme.no/2010/09/22/some-peculiar-trigonometric-identities/#comments Wed, 22 Sep 2010 16:16:41 +0000 http://mindseye.no/?p=124 Continue reading ]]> Have you ever wondered what  \sin( \arccos(x) ) is expressed just in x? Probably not, but it might actually sometimes be useful to know. The expression might for example turn up when you’ve done a trigonometric substitution in an integral. So I decided how to go about to show the trigonometric identities

 \cos( \arcsin(x) ) = \sin(\arccos (x)) = \sqrt{1-x^2} ,

\cos(\arctan(x)) = \frac{1}{\sqrt{1+x^2}},

\sin(\arctan(x)) = \frac{x}{\sqrt{1+x^2}} .

The idea is the use the well known identity \sin ^2 x + \cos ^2 x = 1 and try to get a relation between the basic trig functions and the arcus functions trough that. It goes like this

 x = \sin( \arcsin (x)) = \sqrt{1-\cos ^2 (\arcsin (x))}

using the well known identity. We see that we already have the wanted relation, so that the rest is algebra. By squaring both sides we get

x^2 = 1 - \cos^2 (\arcsin (x)) \Leftrightarrow \cos( \arcsin (x)) = \sqrt{1-x^2}.

And there we have the first one. Similarly to obtain the next one we go

x = \cos (\arccos (x)) = \sqrt{1- \sin ^2 (\arccos (x) )},

\Leftrightarrow x^2 = 1-\sin^2 (\arccos (x)) \Leftrightarrow \sin( \arccos (x) ) = \sqrt{1-x^2}

Obtaining the symmetric identity between sine and cosine. For tangent we go

x = \tan(\arctan(x)) = \frac{\sin(\arctan (x))}{\cos(\arctan(x))} = \frac{\sqrt{1-\cos ^2 (\arctan (x))}}{\cos (\arctan(x))} = \frac{\sin(\arctan(x))}{\sqrt{1 - \sin ^2 (\arctan(x))}}

where we separately use expression 3 and 4 in the equal-chain above to obtain

x^2 = \frac{1 - \cos ^2 (\arctan (x) )}{\cos ^2 (\arctan (x))} = \frac{1}{\cos ^2 (\arctan (x))} - 1 \Leftrightarrow \cos (\arctan (x)) = \frac{1}{\sqrt{1 + x^2}}

and then for nr.4

 x^2 = \frac{ \sin ^2 (\arctan (x))}{1 - \sin^2 (\arctan (x))} \Leftrightarrow x^2 = (x^2 + 1)\sin^2 (\arctan (x)) \Leftrightarrow \sin ( \arctan(x)) = \frac{x}{\sqrt{1 + x^2}}.

And that was that. Later i will do  \arccos(\sin(x)) etc.. but that requires complex numbers.

]]>
http://elektromagnetisme.no/2010/09/22/some-peculiar-trigonometric-identities/feed/ 2 124
Using Python in the first MAT1120 oblig http://elektromagnetisme.no/2010/09/13/using-python-in-the-first-mat1120-oblig/ http://elektromagnetisme.no/2010/09/13/using-python-in-the-first-mat1120-oblig/#respond Mon, 13 Sep 2010 13:00:04 +0000 http://mindseye.no/?p=84 Continue reading ]]> 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:

n=28;
B=zeros(n);

B(1,1)=0.3;
B(1,2)=0.3;
B(1,3)=0.2;

This is quite similar to Python code, but the parentheses should be square brackets and the zeros function requires NumPy. Thus, we need a way to replace these. Using regular expressions was the most probable useful way to do this. Thanks to the Gedit Regex Plugin I managed to do this without even opening a terminal. The needed Regex code was as follows:

Search for: B\((.*?)\)
Replace with: B[\1]

This will match any line with a “B” and replace the round brackets with square ones.  Notice that we don’t need any more fancy regex in this example as there are no other B’s with round brackets getting caught by our search.

The last challenge is to match the dimensions of the array. Matlab stores all n \times n matrices with indexes running from 1 \to n, while Python uses indexes from 0 \to n - 1.

First of all, we need to make the dimensions of the array n+1 to make sure the indexes used to insert the variables are not out of bounds, and in the end we need to delete the first row and column.

Luckily, this is easy to achieve by adding +1 to the zeros function:

B=zeros((n+1,n+1));

And by using the delete function from NumPy:

B=delete(B,1,1) # removes the first and row and column
B=delete(B,1,0)

You may download the finished Python version of the file here.

Note that when you are continuing to do these exercises you should convert B to a matrix whenever you need to do matrix multiplication. You might also use the B.dot(B) function, but there is no such equivalent for exponentials (powers). Check out this page for more info about differences between matrices and arrays in NumPy.

]]>
http://elektromagnetisme.no/2010/09/13/using-python-in-the-first-mat1120-oblig/feed/ 0 84
Sweet first proof http://elektromagnetisme.no/2010/09/09/sweet-first-proof/ http://elektromagnetisme.no/2010/09/09/sweet-first-proof/#respond Thu, 09 Sep 2010 20:28:12 +0000 http://mindseye.no/?p=33 Continue reading ]]>

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.

]]>
http://elektromagnetisme.no/2010/09/09/sweet-first-proof/feed/ 0 33
WordPress in LaTeX glory http://elektromagnetisme.no/2010/09/09/wordpress-in-latex-glory/ http://elektromagnetisme.no/2010/09/09/wordpress-in-latex-glory/#respond Thu, 09 Sep 2010 13:36:06 +0000 http://mindseye.no/?p=21 Continue reading ]]> 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!

]]>
http://elektromagnetisme.no/2010/09/09/wordpress-in-latex-glory/feed/ 0 21
LaTeX It! http://elektromagnetisme.no/2010/09/09/latex-it/ http://elektromagnetisme.no/2010/09/09/latex-it/#comments Thu, 09 Sep 2010 10:43:01 +0000 http://mindseye.no/?p=14 Continue reading ]]> 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.

There are a few pros and cons to both approaches. If you are using the Equations plugin, your images won’t be integrated in your e-mail as files, but will simply be linked to. You will see the images, of course, but if the server should crash or no longer be operative, your LaTeX formulas will become invisible.

This will probably not happen in the nearest future, but if you want to see your formulas forever, it might be a good idea to use LaTeX It! instead.

The problem with LaTeX It! is that it requires your computer to have the right set of packages installed. In Ubuntu this is no problem – you just install the packages texlive-latex-base, texlive-binaries and imagemagick using either Synaptic or by issuing the following command in a Terminal:

sudo apt-get install texlive-latex-base texlive-binaries imagemagick

In Windows you need to install LaTeX and ImageMagick by using the automatic installers, and you will also need GhostScript. On a Mac, however, I’ve not yet got the installation to work. You could try to see if everything is installable from MacPorts, but I have been unlucky with the converting, and would suggest you use the Equations plugin if everything else fails.

]]>
http://elektromagnetisme.no/2010/09/09/latex-it/feed/ 1 14