fish

2009 July 1
by David

The best shell ever created: http://fishshell.org/

Arduino 0016 on 64-bit Ubuntu 9.04

2009 June 24
by David

arduino-64-bit


This is strongly based off of the information provided at freeduino.de.


  1. Install all dependencies:
    sudo apt-get install sun-java6-jre gcc-avr avr-libc ia32-libs librxtx-java
  2. Download 32-bit version of Arduino 0016: [download]
  3. Extract it and navigate to the lib/ directory. Rename RXTXcomm.jar to RXTXcomm.jar-disabled and librxtxSerial.so to librxtxSerial.so-disabled.
  4. Go back to the main directory and open the arduino script in a text editor. Change the third line (starts with CLASSPATH=[...]) to:
    CLASSPATH=java/lib/rt.jar:lib:lib/build:lib/pde.jar:lib/core.jar:lib/antlr.jar:lib/oro.jar:lib/registry.jar:lib/mrj.jar:/usr/share/java/RXTXcomm.jar
  5. Also, change the 13th line (starts with LD_LIBRARY_PATH=[...]) to:
    LD_LIBRARY_PATH=/usr/lib:`pwd`/lib:${LD_LIBRARY_PATH}
  6. Done! Save the file and launch the IDE like normal.

Here’s a full printout of the modified arduino script for reference:

#!/bin/sh
 
CLASSPATH=java/lib/rt.jar:lib:lib/build:lib/pde.jar:lib/core.jar:lib/antlr.jar:lib/oro.jar:lib/registry.jar:lib/mrj.jar:/usr/share/java/RXTXcomm.jar
export CLASSPATH
 
# put the directory where this file lives in the front of the path, because
# that directory also contains jikes, which we will need at runtime.
#
PATH=`pwd`/tools:${PATH}
export PATH
 
# put the directory with the native RXTX libs in the library path
LD_LIBRARY_PATH=/usr/lib:`pwd`/lib:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
 
java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel processing.app.Base

JavaScript Image Animation

2009 June 24
by David

I made a small script to produce an animation with a series of images and JavaScript. I only tested it in Firefox 3, but I don’t see any reason why it wouldn’t work in other browsers.

Try it: http://doswa.com/projects/animate/
Download it: http://doswa.com/projects/animate/animate.zip

http://trac.sagemath.org/sage_trac/ticket/1483 inspired me to make this, since the sagenb.org server doesn’t have ImageMagick installed.

PHPNotify: Debug Notifications From PHP

2009 May 13
by David

This is a little program to help debug AJAX (or anything else) from PHP.

PHP Debug Notification

Read the README file to instructions on setting it up on Ubuntu. Note that you must first install python-notify through apt-get for this to work correctly.

Download PHPNotify

If the function name notify() conflicts with any of your functions, you can change it on lines 2 and 3 of prepend.php

Improved RK4 Implementation

2009 April 21
by David

Harmonic motion with drag

This is a Python implementation of the RK4 numerical integrator that works with differential functions of all orders. That is, any function in the form F(x, y, y’, y”, …, y^{(n)}).

If you’re new to numerical integration or even RK4 integration, please read my other post first. It’s easier to understand because it’s a less generalized function.

def rk4(s0, fn, t, dt):
	"""RK4 implementation.
	s0 = initial state as a list. ex.: [initial_position, initial_velocity]
	fn = function(state, t) to integrate
	t = current value of the independent variable
	dt = amount to increase the independent variable (step size)"""
	r = range(len(s0))
	s1 = s0 + [fn(s0, t)]
	s2 = [s0[i] + 0.5*s1[i+1]*dt for i in r]
	s2 += [fn(s2, t+0.5*dt)]
	s3 = [s0[i] + 0.5*s2[i+1]*dt for i in r]
	s3 += [fn(s3, t+0.5*dt)]
	s4 = [s0[i] + s3[i+1]*dt for i in r]
	s4 += [fn(s4, t+dt)]
	return [s0[i] + (s1[i+1] + 2*(s2[i+1]+s3[i+1]) + s4[i+1])*dt/6.0 for i in r]

On a side note, I recently found out about Sage (sagemath.org and sagenb.org). Its plotting capabilities and convenient mathematical notation are especially useful. Plus, it uses Python!

Chain

2009 January 24
by David

I made a little Processing sketch based on the same physics as JavaScript physics.

Screenshot of "Chain"

(View the full post to try it out.)

read more…

Flight404

2009 January 21
by David

Flight404, the personal site of Robert Hodgin of The Barbarian Group, has some interesting works created with Processing.

Flight404 main site (blog)
Flight404 Vimeo page - Has videos of many of his works
Some of his Processing experiments - These aren’t as fully developed as the ones on the other two links, but they include the source code

JavaScript physics

2009 January 16
by David

I made a very basic physics demo in JavaScript to practice using the MooTools library. It uses Verlet integration as outlined in Thomas Jakobsen’s paper.

To try out the demo, go to http://doswa.com/projects/physics_js/

Chain of particles attached by joints

Chain of particles attached by joints

Extending derivatives and integrals into fractions

2009 January 3
by David

In the previous post, I wrote about a way to generalize derivatives and integrals into one function. What happens if a number other than an integer is passed to that function?

Here is the generalization from the last post:

\frac{\partial^n}{\partial x^n} x^k = \frac{k!}{(k-n)!} x^{k-n}

Set k=2 and n=\frac{1}{2}:

\frac{\sqrt{\partial}}{\sqrt{\partial x}} x^2 = \frac{2!}{(2-\frac{1}{2})!} x^{2-\frac{1}{2}} = \frac{2!}{1.5!} x^{1.5}

Now there’s a problem. Since a! is only defined for integers 0 or greater, a different way of calculating factorials is needed. Luckily, there exists a Gamma function defined for all real and complex numbers such that:

\Gamma(n+1) = n!

Substitute the Gamma function into the other equation and simplify:

\frac{\sqrt{\partial}}{\sqrt{\partial x}} x^2 = \frac{2!}{1.5!} x^{1.5} = \frac{2}{\Gamma(1.5+1)} x^{1.5} = \frac{2}{\Gamma(2.5)} x^{1.5} = \frac{2}{(\frac{3 \sqrt{\pi}}{4})} x^{1.5}

 = \frac{2}{1} (\frac{4}{3 \sqrt{\pi}}) x^{1.5} = \frac{8}{3 \sqrt{\pi}} x^{1.5} = \frac{8 \sqrt{\pi}}{3 \pi} x^{1.5} \approx 1.505 x^{1.5}

So, the half derivative of x^2 is approximately equal to 1.505 x^{1.5}.

This can be used for ‘fractional integration’ as well, if a negative number is used for n.

Generalizing derivatives and integrals

2009 January 3
by David

Start with a simple expression, x^k, and take a few derivatives:

\frac{\partial}{\partial x} x^k = k x^{k-1}

\frac{\partial^2}{\partial x^2} x^k = (k-1) k x^{k-2}

\frac{\partial^3}{\partial x^3} x^k = (k-2) (k-1) k x^{k-3}

\frac{\partial^4}{\partial x^4} x^k = (k-3) (k-2) (k-1) k x^{k-4}

A pattern is emerging:

\frac{\partial^n}{\partial x^n} x^k = (k-n+1)...(k-1)k x^{k-n} = c x^{k-n}
, where c is the coefficient.


Now the hard part is finding the pattern in the coefficient. This needs to be taken out of the ‘…’ form. Focus on that:

c = (k-n+1)...(k-1)k

This is a series of numbers, each one larger than the next. This looks like a factorial, so divide k! by that:

\frac{k!}{c} = \frac{k!}{(k-n+1)...(k-1)k} = \frac{1(2)(3)...k}{(k-n+1)...(k-1)k}

Note how the top goes from 1 to k and the bottom goes from k-n+1 to k. That means that k-n+1 to k is a subset of 1 to k, so just divide that part out:

\frac{k!}{c} = \frac{1(2)(3)...k}{(k-n+1)...(k-1)k} = 1(2)(3)...(k-n) = (k-n)!

Now solve for c:

\frac{1}{c} = \frac{(k-n)!}{k!}
, so
c = \frac{k!}{(k-n)!}


Puts this back into the original equation to get:

\frac{\partial^n f(x)}{\partial x^n} = c x^{k-n} = \frac{k!}{(k-n)!} x^{k-n}

So, the nth derivative of x^k is equal to:

\frac{k!}{(k-n)!} x^{k-n}


Verify this with a couple of derivatives:

\frac{\partial}{\partial x} x^2 = \frac{k!}{(k-n)!} x^{k-n} = \frac{2!}{(2-1)!} x^{2-1} = \frac{2}{1} x^1 = 2x

\frac{\partial^2}{\partial x^2} 4 x^4 = 4 (\frac{k!}{(k-n)!}) x^{k-n} = 4 (\frac{4!}{(4-2)!}) x^{4-2} = 4 (\frac{24}{2}) x^2 = 4(12) x^2 = 48 x^2

And a couple of integrals:

\frac{\partial^{-1}}{\partial x^{-1}} x^2 = \frac{k!}{(k-n)!} x^{k-n} = \frac{2!}{(2+1)!} x^{2+1} = \frac{2}{6} x^3 = \frac{1}{3} x^3

\frac{\partial^{-7}}{\partial x^{-7}} 3 x^4 = 3 (\frac{k!}{(k-n)!}) x^{k-n} = 3 (\frac{4!}{(4+7)!}) x^{4+7} = 3 (\frac{24}{39916800}) x^{11} = \frac{1}{554400} x^{11}