#!/usr/bin/env python
import os
def system( u, v, w, uinit, vinit, winit, time ):
ut = list(); ut.append( uinit )
vt = list(); vt.append( vinit )
wt = list(); wt.append( winit )
for i in range( time ):
ut.append( u.update( ut[-1], vt[-1], wt[-1] ) )
vt.append( v.update( vt[-1], ut[-1], wt[-1] ) )
wt.append( w.update( wt[-1], ut[-1], vt[-1] ) )
return ( ut, vt, wt )
class Component:
def __init__( self, a, b, g, h ):
self.alpha = a
self.beta = b
self.gamma = g
self.step = h
def update( self, x, y, z ):
self.body = self.alpha*x + self.beta*x*y + self.gamma*x*z
return x + self.step*self.body
step = 0.08
u = Component( -1.0, 0.025, 0.035, step )
v = Component( 1.5, -0.45, -0.024, step )
w = Component( 1.45, -0.75, 0.026, step )
( ut, vt, wt ) = system( u, v, w, 5.0, 50.0, 20.0, 4000 )
ubuff = open( "ut.txt", "w" )
vbuff = open( "vt.txt", "w" )
wbuff = open( "wt.txt", "w" )
for i in range( len( ut ) ):
ubuff.write( str( ut[i] ) )
ubuff.write('\n')
vbuff.write( str( vt[i] ) )
vbuff.write('\n')
wbuff.write( str( wt[i] ) )
wbuff.write('\n')
ubuff.close(); vbuff.close(); wbuff.close()
foo = list()
foo.append('#!/usr/bin/env octave\n')
foo.append('\n')
foo.append('load ut.txt ; load vt.txt ; load wt.txt ;\n')
foo.append('t = 0:4000 ; plot( t, ut, t, vt, t, wt ) ;\n')
foo.append('print -djpeg foo.jpeg;\n')
f = open( "foo.o", "w" )
f.writelines( foo )
f.close()
os.system( 'octave -qf foo.o' )
os.system( 'evince foo.jpeg &' )
os.system( 'rm ut.txt' )
os.system( 'rm vt.txt' )
os.system( 'rm wt.txt' )
os.system( 'rm foo.o' )
Showing posts with label octave. Show all posts
Showing posts with label octave. Show all posts
Monday, November 29, 2010
Thursday, October 7, 2010
Variance
Different programs implement variance in different ways. This can lead to confusing results when you move from one set of functions to another.
scipy.stats.cov() normalizes by (N-1), by default, bias=False. By setting bias=True, you will normalize by N.
However, scipy.var() normalizes by N.
In Octave, var( x, 0 ) biases by N-1, and var( x, 1 ) biases by N.
Matlab and R, I think, do things slightly differently.
scipy.stats.cov() normalizes by (N-1), by default, bias=False. By setting bias=True, you will normalize by N.
However, scipy.var() normalizes by N.
In Octave, var( x, 0 ) biases by N-1, and var( x, 1 ) biases by N.
Matlab and R, I think, do things slightly differently.
Friday, October 1, 2010
Subscribe to:
Posts (Atom)