# channelflow.org

### Site Tools

gibson:teaching:fall-2012:math445:quiverdiary

# Quiver plot diary

Matlab/octave commands for plotting the vector field and solutions of a simple differential equation.

```octave:43> % draw graph of vector field in t,y plane for dy/dt = 0.2 y t
octave:44> t = linspace(-5, 5, 30);
octave:45> y = linspace(-5, 5, 30);
octave:46> [T,Y] = meshgrid(t,y);
octave:47>
octave:47> % dy = 0.2 y t dt
octave:47> % draw arrows with y,t lengths dt and dy at each spot on grid
octave:47> dt = 0.1*ones(size(T)); % make dt = 0.1 at each point on grid
octave:49> dy = 0.2*Y.*T.*dt;
octave:50> size(T)
ans =    30   30
octave:51> size(Y)
ans =    30   30
octave:52> size(dt)
ans =    30   30
octave:53> size(dy)
ans =   30   30

octave:54> % Y,T, dy, dt are all 30 x 30 matrices on grid in y, plane
octave:54> quiver(T,Y,dt,dy)
octave:59> xlabel('t')
octave:60> ylabel('y')
octave:61> title('dy/dt = 0.2 y t')
octave:62> axis([-5 5 -5 5])
octave:63> axis square

octave:64> % matlab command to solve ord. diff eqn is ode45
octave:65> % given an ODE (function), ode45 will produce discrete curve
octave:65> % y(t), i.e. a vector of t values and a  vector of y values
octave:65> % which can be graphed with plot(t,y)
octave:65>
octave:74> quiver(T,Y,dt,dy)
octave:75> axis([-5 5 -5 5])
octave:76> axis equal
octave:77> hold on
octave:78> [tsoln,ysoln] = ode45(@f0, t, -4);
octave:79> plot(tsoln, ysoln, 'r-')
octave:82> [tsoln,ysoln] = ode45(@f0, t, 2);
octave:83> plot(tsoln, ysoln, 'k-')```