jake baker’s maths blog

APS Maths hangs in there

Javascript for A level maths

May 18th, 2011 by · 3 Comments · Uncategorized

Writing short bits of code to calculate partial series sums or to implement simple algorithms is a great extension to A level maths.  I had wanted to do this for some time, and hoped that my school would install Python or Sage or some other programming package. Then I realized that I could do the programming perfectly well using three readily available tools: any simple text editor, javascript, and any browser.  Javascript is a programming language which provides basic maths functions and constants (such as Math.PI and Math.sin()), and which is used everywhere in web pages.  Using fairly simple (and easily modified) html students can create a form which will accept inputted data and also display the result.

Here’s an example of javasript to calculate sin(x):

<script type='text/javascript'>
ans=Math.sin(x);
</script>

However, as it stands, this will not display any output, nor can the value of x be inputted by the user. The following html creates a form for input, and defines a ‘div’ in which output will be displayed.

<html>
<body>
<form name='trig'>
sin<input type='text' name='xforsin' value=''>
<input type='button' value='calculate' onclick='findsin()'>
</form>
<script type='text/javascript'>
function findsin(){
x=document.trig.xforsin.value;
ans=Math.sin(x);
document.getElementById('output').innerHTML='sin('+x+')='+ans;
}
</script>
<div id='output'></div>
</body>
</html>

Although this looks more complicated, the actual calculation is the same.  The rest is html to get the input and display the ouput.

The code as it stands above can be pasted into a text editor and saved as sin_calculator.html (or whatever filename is chosen). It’s important to make sure the file has no extra formatting and is saved with the extension ‘html’.  This file can then be opened by a browser and used to calculate sin(x)!

My students were quite excited to find themselves writing a working web page in just a few minutes, and some of them have gone on to create their own pages, for example to invert a 2 x 2 matrix.

Once students have tried a program like this, there are many things they could adapt the javascript to do: calculate a series sum, solve a quadratic using the formula, or automate finding a missing angle using the cosine rule, for example.

Excellent tutorials on html and javascript are provided by W3Schools here.

Mandelbrot

January 17th, 2011 by · No Comments · Further Maths, Year 10 Maths, Year 9 Maths

I’ve been working on a mandelbrot program.  I’ve been using javascript, so the work is done on the user’s computer rather than the server, and displaying the image using canvas.  I’m quite happy with the result, especially the selection and zoom feature.

Here’s an image I really like, from the baby-brot off near x=-1.75:

mandelbrot24large

There are lots of good mandelbrot programs out there. The best I know of is at www.h-schmidt.net, which uses java. If you want to try my program (which I think is quite good!), follow the ‘maths algorithms’ link in the sidebar or click here.

Tags: ··

Prime dates

January 17th, 2011 by · 2 Comments · Further Maths, Year 10 Maths, Year 9 Maths

It’s 2011!  And 2011 is a prime number.  Over a decade ago we had 1997, 1999 and 2003, all prime numbers, and so close together.  But that’s not to happen again until 2081.  So make the most of 2011, and plan for a great party in 2027 and 2029 when we have two prime years as close as possible again.  If you want to find ‘twin primes’ (like 2027 and 2029), or prime triplets, quadruplets or quintuplets, try my algorithm page www.jakebakermaths.org.uk.  1481, you will see, was a very special year!

Calculating pi

May 20th, 2008 by · 8 Comments · Further Maths, Stuff

I have a student in Y10 who can recite pi to 200 places, after listening to the pi song rather a lot of times … (see http://pi.ytmnd.com/).  This led to reading more about how to calculate pi, and I found out about the Brent-Salamin algorithm, very clearly explained on Wikipedia.  I tried it out on Excel, and also showed it to my Y13 students who really enjoyed it.

 Here it is, so you don’t have to go to Wikipedia …

brent-salamin.JPG 

With my Y13 class we worked out pi to 6 decimal places in around 10 minutes, which they were impressed with.

I still want to know how calculators do things like sin and arcsin, or find square roots, so if anybody knows of a good link about this, please add a comment!

The “most spherical” Platonic solid … ?

April 19th, 2008 by · 1 Comment · Further Maths, Year 10 Maths, Year 9 Maths

I spent quite some time over the Easter holidays finding expressions for the volume of a dodecahedron and icosahedron (with edge lengths 1 unit).  I found that there is a known and perhaps surprising result, that a dodecahedron fills more of a sphere which it just touches (a circumscribing sphere) than an icosahedron.

 Here are the results:

dodecahedron-volume-table.GIF

The interesting parts of the calculations were finding the angles between the faces of the polyhedra, and using various trigonometric identities to express the results as surds, leading to the really quite simple expressions for the volumes and radii.

One key result is that cos72 = (-1+sqrt(5))/4.  From this fact you can find the trig functions of lots of other angles.

Next I’ll find some images of a dodecahedron and icosahedron, though of course there are beautiful rotating ones on http://mathworld.wolfram.com/topics/PlatonicSolids.html.

GeoGebra software

March 31st, 2008 by · 4 Comments · Year 10 Maths, Year 9 Maths

GeoGebra is a very useful piece of free software for maths students. It allows you to draw geometric shapes on axes, and also to plot a huge range of functions. There are tools going well beyond the A level maths, but it’s easy enough for students at KS3 to use effectively. You can copy and paste diagrams you’ve made into other documents.

To get GeoGebra, go to http://www.geogebra.org/cms/.

Here’s a diagram I did for rotation:

rotation1.png