Run commands with OCTAVE v6.1.0.
This file mirrors the implementation of the corresponding python file.
Let's now consider flows which are not just constrained to a line. Flows in higher dimensions have a larger space to move about in the parameter space and can lead to interesting dynamics. First, we will look at some kinds of flows by drawing their vector plot. On top of the vector plot, we can also plot the trajectory. The trajectory is essentially how the phase space parameters change in time. It is different from the time series as time does not appear explicitly.
omega = 1; p = 0.2;
x = linspace(-3, 3, 20); v = linspace(-3, 3, 20);
[X, V] = meshgrid(x, v);
U = V; W = -omega^2*X - p*V;
quiver(X, V, U, W);
daspect ([1 1 1]);
hold on;
x1 = linspace(-3, 3, 100); v1 = linspace(-3, 3, 100);
[X1, V1] = meshgrid(x1, v1);
U1 = V1; W1 = -omega^2*X1 - p*V1;
seedpoints = [[0, 1.5], [2.5, 0]];
streamline(X1, V1, U1, W1, [0, 1.5], [2.5, 0]);
hold off;
'perl' is not recognized as an internal or external command, operable program or batch file. error: 'streamline' undefined near line 1 column 1
We can also make the plots interactive by wrapping them inside a function. The plot below draws a set of "linear flows".
clear;
clc; close all;
h.ax = axes ("position", [0.05 0.4 0.5 0.5]); #reduce plot windows size to accomodate sliders
function update_plot (obj, init = false)
## gcbo holds the handle of the control
h = guidata (obj);
replot = false;
recalc = false;
switch (gcbo) # If we make any change then we replot
case {h.print_pushbutton}
fn = uiputfile ("*.png");
print (fn);
case {h.slider1}
recalc = true;
end
if (recalc || init)
a = -2 + 3.5*get (h.slider1, "value");
set (h.label1, "string", sprintf ("a: %.1f", a));
x = linspace(-3, 3, 20); y = linspace(-3, 3, 20);
[X, Y] = meshgrid(x, y);
U = a*X; V = -Y;
quiver(X, Y, U, V);
x1 = linspace(-3, 3, 500); y1 = linspace(-3, 3, 500);
[X1, Y1] = meshgrid(x1, y1);
F = log(abs(X1)) + a*log(abs(Y1));
hold on;
contour(X1, Y1, F, 11);
hold off;
guidata (obj, h);
else
set (h.plot, "ydata", y);
end
end
# specify the GUI plot properties like sliders and label formatting
## print figure
h.print_pushbutton = uicontrol ("style", "pushbutton",
"units", "normalized",
"string", "print plot\n(pushbutton)",
"callback", @update_plot,
"position", [0.6 0.45 0.35 0.09]);
## guess
h.label1 = uicontrol ("style", "text",
"units", "normalized",
"string", "Guess:",
"horizontalalignment", "left",
"position", [0.05 0.25 0.35 0.08]);
h.slider1 = uicontrol ("style", "slider",
"units", "normalized",
"string", "slider",
"callback", @update_plot,
"value", 0.1,
"position", [0.05 0.20 0.35 0.06]);
set (gcf, "color", get(0, "defaultuicontrolbackgroundcolor"))
guidata (gcf, h)
update_plot (gcf, true);
x = linspace(-3, 3, 20); y = linspace(-3, 3, 20);
[X, Y] = meshgrid(x, y);
U = X + Y;
V = 4*X - 2*Y;
quiver(X, Y, U, V);
hold on;
#daspect ([1 1 1]);
x1 = linspace(-3, 3, 100); y1 = linspace(-3, 3, 100);
[X1, Y1] = meshgrid(x1, y1);
U1 = X1 + Y1;
V1 = 4*X1 - 2*Y1;
seedpoints = [x1 x1;zeros(size(y1))+3 zeros(size(y1))-3];
streamline(X1, Y1, U1, V1,seedpoints(1,:),seedpoints(2,:));
ylim([-3, 3]);
plot(x1, x1, '--k');
plot(x1, -4*x1, '-k');
hold off;
'perl' is not recognized as an internal or external command, operable program or batch file. error: 'streamline' undefined near line 1 column 1