Octave
Getting Started Arithmetic is as usual: – What would (a-V)(V-1)V be for a=0.1 and V=-56? – Multiplication is *, division is /
Variables Variables are as usual and assignment is as usual:
Arrays Arrays are the basic data type – Semi-colons separate rows – Commas separate individual numbers in a row
Addressing array elements
Array exercises Array operations are what they should be – Define any array and the identity, and multiply them – Divide the identity by an array, assigning to a variable (this should be the array inverse) – Multiply the array and its inverse
Array operations But there are also element-wise operations – + is always element-wise –.* is element-wise multiplication
Useful built-in arrays Try these: i=1:1:10 i=1:2:10 ones(10) zeros(1,10) eye(10) eye(5,10)
Adding to vectors
Plotting Uses gnuplot The command “plot(x, y)” lets you plot values of a vector x against values of a vector y
Plotting exercises Plot x against sin(x) for x=pi/16, 2*pi/16, …, 2*pi Plot cos(x) against sin(x) for the same values
Functions function = ( ) … endfunction
Fitzhugh-Nagumo ∂V/∂t = (a-V)(V-1)V – v ∂v/∂t = ϵ(βV-γv-δ)
Before more functions… editing addpath( ) – = “/Users/User/octave” Edit and save functions in a separate window – Pick your favorite text editor (don’t use Word) Octave will search its path for functions you use
Exercises Write functions to compute: ∂V/∂t = (a-V)(V-1)V – v ∂v/∂t = ϵ(βV-γv-δ)
Parameter values a=0.1 b=0.5 g=1 d=0 e=0.01
Numerical integration f(t+Δt) = f(t) + dt*∂f/∂t Given V(0) =0 and v(0) = 0, let’s plot (t, V(t)) and (t,v(t)) –
Loops
A simple version of expression is a vector; var takes on each value in the vector in turn.
Numerical Integration V(t+Δt) = V(t) + Δt(∂V/∂t) = V(t) + Δt((a-V)(V-1)V – v) v(t+Δt) = v(t) + Δt(∂v/∂t) = v(t) + Δt(ϵ(βV-γv-δ)) V = V + dt*(V*(a-V)*(V-1.0)-v) v = v + dt*(eps*(beta*V-gamma*v-delta))
Exercise Write a function to compute vectors of values for V and v, from time 0 to time 200. Plot them against time t. Plot them against each other. Provide a stimulus at some point plot the result