This Matlab code illustrates the solution of steady state analysis for the DISCRETE-TIME dynamical system described in the docking problem.
clear all, close all, clc
Parameters are
c = 5; % time to make a control adjustment w = 10; % delay time before the next observation k = 0.1; % ratio between acceleration and velocity (control law)
The discrete-time dynamical system is given by delta_x1=f1; delta_x2=f2 where f1= -k*w*x1-k*c*x2; f2= x1-x2;
The following code displays the direction field f1,f2
M=10; % number of samples points x1min=-15; x1max=15; % domain specification x2min=-15; x2max=15; [X1,X2]=meshgrid(x1min:(x1max-x1min)/M:x1max,x2min:(x2max-x2min)/M:x2max); dX1=-k*w*X1-k*c*X2; % x1-component dX2= X1-X2; % x2-component quiver(X1,X2,dX1,dX2); % matlab routine axis([x1min x1max x2min x2max]); title('Direction field (the vectors are rescaled!)'); hold on xlabel('Current Speed'); ylabel('Previous Speed');
One important and convenient feature of Matlab is the possibility of defining customized functions (procedures) that can be called several times within the main code). This example is a good candidate for defining such a function. Here is how to do this.
Create separately a function file (say dockfun.m) that takes as input a 2-dim vector x and outputs a 2-dim vector rhs. This is the precise format:
* function rhs = dockfun(x,c,w,k); rhs = [-k*w*x(1)-k*c*x(2); * x(1)-x(2)];
NOTE Make sure that the name of the file (dockfun.m) coincides with the name of the function inside the file.
Initial starting point (chosen pretty arbitrary) and number of iterations
x=[8;10]; N = 12; fprintf('n Current speed Prev. speed\n\n') fprintf('%2.0f %5.2f %5.2f\n', 0, x(1), x(2))
n Current speed Prev. speed 0 8.00 10.00
Iteration Step:
for n=1:N xnew = x + dockfun(x,c,w,k); plot([x(1),xnew(1)], [x(2),xnew(2)],'--ro',... 'MarkerFaceColor','k','MarkerSize',2) x = xnew; fprintf('%2.0f %5.2f %5.2f\n', n, x(1), x(2)) end
1 -5.00 8.00 2 -4.00 -5.00 3 2.50 -4.00 4 2.00 2.50 5 -1.25 2.00 6 -1.00 -1.25 7 0.63 -1.00 8 0.50 0.63 9 -0.31 0.50 10 -0.25 -0.31 11 0.16 -0.25 12 0.13 0.16