Difference between revisions of "CompSciWeek13"

From Predictive Chemistry
Jump to: navigation, search
(Numerical Integration + Binary Output Format)
(Numerical Integration + Binary Output Format)
Line 9: Line 9:
 
** inspecting binary formats with od
 
** inspecting binary formats with od
   
  +
=== GNU ODE Integrator ===
  +
  +
'''vanderpol.ode'''
  +
<code lang="python">
  +
mu = %MU
  +
  +
u = 1.0
  +
y = 0.0
  +
  +
u' = y
  +
y' = mu*(1-u*u)*y - u
  +
  +
print t, u, y, y! every 10 from 50
  +
  +
step 0, 100
  +
</code>
  +
  +
You can do the substitution with sed and run all dynamics with:
  +
  +
for((i=0;i<10;i++)); do
  +
sed -e "s|%MU|$i|" vanderpol.ode >vanderpol-$i.ode
  +
ode -f vanderpol-$i.ode >out-$i.dat </dev/null
  +
done
  +
  +
=== Plotting with Gnuplot ===
  +
  +
<code lang="gnuplot">
  +
set term postscript enh color lw 3 "Times-Roman" 28
  +
set out 'van.eps'
  +
  +
set xlabel "u"
  +
set ylabel "y"
  +
plot 'out-0.dat' u 2:3 w l title "0", \
  +
'out-1.dat' u 2:3 w l title "1", \
  +
'out-4.dat' u 2:3 w l title "{/Symbol m} = 4"
  +
</code>
  +
  +
Run with:
  +
  +
gnuplot plot_van.gplot
  +
  +
=== Python Integrator ===
  +
  +
  +
=== Working with binary ===
 
Example: [http://man7.org/linux/man-pages/man5/elf.5.html ELF] header
 
Example: [http://man7.org/linux/man-pages/man5/elf.5.html ELF] header
   

Revision as of 16:15, 17 November 2014

Numerical Integration + Binary Output Format

  • Van der Pol Oscillator: <math>\ddot u - \mu (1-u^2) \dot u + u = 0</math>
    • Implementations in OpenOffice Spreadsheet, GNU ODE, and Python
    • Perturbed initial conditions, Lyapunov exponents, and large deviation principles
  • Working well with others: text
  • Working with machines: binary
    • This is preferable when you have lots and lots of data
    • The relevant numpy methods are x.tofile("file") and x = fromfile("file") -- but save("file", x) and x = load("file") are preferred
    • inspecting binary formats with od

GNU ODE Integrator

vanderpol.ode mu = %MU

u = 1.0 y = 0.0

u' = y y' = mu*(1-u*u)*y - u

print t, u, y, y! every 10 from 50

step 0, 100

You can do the substitution with sed and run all dynamics with:

 for((i=0;i<10;i++)); do
   sed -e "s|%MU|$i|" vanderpol.ode >vanderpol-$i.ode
   ode -f vanderpol-$i.ode >out-$i.dat </dev/null
 done

Plotting with Gnuplot

set term postscript enh color lw 3 "Times-Roman" 28 set out 'van.eps'

set xlabel "u" set ylabel "y" plot 'out-0.dat' u 2:3 w l title "0", \

    'out-1.dat' u 2:3 w l title "1", \
    'out-4.dat' u 2:3 w l title "{/Symbol m} = 4"

Run with:

gnuplot plot_van.gplot

Python Integrator

Working with binary

Example: ELF header

od -t x1 -t c -N 8 /bin/bash

Binary comes in lots of units


8 bits = 1 byte
4 bits = 1 nibble
1 byte = 1 ascii character
2 bytes = 1 short
4 bytes = 1 32-bit int = 1 float
8 bytes = 1 64-bit int = 1 64-bit address = 1 double = 1 float complex
16 bytes = 1 long double = 1 double complex

Byte ordering on most modern 64-bit processors is little-endian (Intel, AMD)

in base 10, this would mean the 4-digit representation of the number 123 is

3 = 0011
2 = 0010
1 = 0001
0 = 0000

The binary together would read:

0011 0010 0001 0000

Since we have to use 4 digits, but the little end (least significant byte) goes first.

Basis Functions

  • Constructing B-splines - tensor method
  • Representing the differentiation operator
  • Solving PDEs using the implicit method