Fun with Maths and Python - Introduction |
2011-07-16 00:00 |
This is going to be a series of articles which are all about having fun with maths and Python. I'm going to show you a bit of maths and then how to apply it with a python program, then work out how to improve it.
I decided to write these after looking in my doodles folder on my computer and finding 100s of programs to calculate this bit of maths, or explore that bit of maths, and I thought it would be interesting for me to share them. Hopefully you'll find it interesting too!
I'm going to use python 3 for all python code. This enables me to future proof these articles and encourage everyone who hasn't tried Python 3 to have a go. The programs will run with minor modifications on python 2 - just watch out for division which has changed from python 2 to 3. In fact if you run any of these programs under python 2 then put from __future__ import division at the top of them.
Python is a really excellent language for investigations into maths. It is easy to read and has excellent long number support with infinite precision integers and the decimal module. I'm going to attempt to demonstrate what I want to demonstrate not using any third party modules, but I may occasionally use the gmpy module.
I'm going to pitch the level of maths below calculus, no more than the maths that everyone should have learnt at school. If I want to use some bit of maths outside that range I'll explain it first. This does means that sometimes I won't be able to show a proof for things, but I'll add a link to an online proof if I can find one.
You are going to see maths written both in traditional style:

And in computer style which every programmer knows anyway. This involves a few more brackets, but it is much easier to translate to computer code. For example:
(-b +/- sqrt(b**2 - 4*a*c)) / (2*a)
In Python computer maths we write:
- * to mean multiply
- / to mean divide
- ** to mean to the power
- // to mean divide but give the result as an integer
- % to mean the same as the modulo or mod operator, ie do the division and take the remainder.
I'm going to make free with unicode fonts so you'll see:
- π - pi
- x² - x squared
- √x - square root of x
- ± - plus or minus
If these aren't appearing properly, then you'll need to try a different browser, or install some more fonts.
As for the programming level, anyone who knows a little bit of python should be able to work out what is happening - I won't be doing anything too fancy!
I'll tag all the articles with pymath so you can find them or subscribe to the rss.
Happy Calculating!
Nick Craig-Wood
Technology changes in 2010 |
2010-12-22 14:56 |
Technology that has come and gone from my life in 2010, and new stuff I've learnt. More than I expected!
These notes are really for me to look back at over the years, but you might find them interesting.
Old
Things gone from my life. Gone but not forgotten :-
- Mutt - finally replaced with Thunderbird. Mutt is a terminal based email client, just in case you haven't heard of it. It works really well for power users, is really configurable, but in these days of HTML emails and attachments it was no longer keeping up. I loved him - he was a faithful mutt, but he had to go. (Actually he is still there at the command line ready to go if needed - but keep it under your hat!)
- Courier V34 modem - years overdue, I finally disconnected it and consigned it to the pit of oblivion. It used to receive faxes, but I don't think anyone has sent one for several years. It also used to run a BBS and an Internet node, which was useful at times, but now GPRS/3G/Wifi is everywhere I want to go it is no longer needed.
- ISDN - 128k of digital goodness just wasn't good enough any more and became too expensive. Great in its hey-day with 2 channels, 10 numbers and a whopping 64k digitial Internet connection. Obsoleted by ADSL and VOIP.
- Nokia E90 & Symbian - sorry... we've had good times, but I've found someone else
- KDE - you worked really well until version 4 where the bugs and the slowness really kicked in.
- Usenet - This was my first hint of online communities on the Internet in 1994. Unfortunately the cool kids have moved on, and so, reluctantly, have I!
New
New technology :-
- Thunderbird - for people with complicated email lives the plugin system makes life bearable! Here are my top plugins
- Nostalgy - adds keyboard shortcuts to save, copy, goto folders
- Quickfolders - Put your favourite folders along the top
- Copy Sent to Current - copy sent mail to the current folder not the Sent folder - makes a new and better way of doing email
- Display Mail User Agent - snoop on what other people use for their mail client
- Enigmail - Use PGP to sign/encrypt your emails seamlessly
- External Editor - edit emails in your favourite editor (eg emacs)
- Identity Chooser - If you use multiple identities you need this!
- Mail Redirect - proper bounce of email (not forward)
- IMAP - makes it easy to migrate your email setup. You can still use it with procmail so some things haven't changed ;-) I can use it with my Android phone and the excellent K9Mail.
- Blogofile - which makes this (fully static) website. It replaces a pile of crufty hand built python scripts which did the same thing, just not nearly as well!
- Ubuntu on the desktop - I finally gave in and replaced Debian testing with Ubuntu on my main laptop so I can spend less time fixing stuff and more time doing real work! Debian still rules on the server though.
- VOIP - I've signed up with a 100% Voip provider and migrated my 10 telephone numbers to them. It went reasonably smoothly! I took the ISDN card out of my Asterisk PBX. We've been doing this at work for ages - it seemed like time to migrate at home too.
- Android - is Google's new phone operating system. It runs on Linux and is mostly open source which are big positives in my view. I've been enjoying my Android phone greatly and have written a number of applications - Oxo3d is one.
- Gnome - well not new actually, I last gave Gnome up in about 2005 when I got irritated at no longer being able to edit my menus. Unfortunately KDE 4 isn't shaping up for me, so it is hello again!
Books
Tech books I've read this year. No python books this year - I think I've read them all now!
- Java in a Nutshell (again) programming to write Android programs. I learnt original Java ages ago, but is is quite a different experience with generic types. Still not my favourite language - reminds me too much of C++, but bearable.
- Programming In Scala - just for fun - maybe I'll use it with Android one day. Scala is one of the new breed of languages which runs on the Java VM. Scala is a (mostly) functional language created by one of the creators of Java itself.
- Version Control with Git - distributed revision control system. Very clever idea with lots and lots of command lines to explore. If it scales to the Linux kernel then surely it is good enough for my projects?
- BGP: Building Reliable Networks with the Border Gateway Protocol - how the Internet really works!
- Unlocking Android: A Developer's Guide - how to make Android applications
- Running IPv6 - yes it is coming - IPv4 addresses are running out very soon.
These are affiliate links, so if you click then buy I'll earn a few pence towards my next tech book!
Oxo3d v0.93 released |
2010-11-21 18:43 |
Oxo3d v0.93 released.
Major changes are
- Fix keys / trackball not working sometimes
- Fix back button
- Update for new Market and new SDK
- Make work properly on High/Low res devices
Oxo3d v0.92 released |
2010-04-28 08:31 |
Oxo3d v0.92 released.
Major changes are
- Make the D-Pad rotate the view and the D-Pad center / search button flip view
- Make the trackball work again
- Fix 3D view bug
- Fix 3D view disappearing after showing the help