Suppose now that the child is pulling or pushing some toy, by means of a rigid bar of length . We are interested in computing the orbit of the toy when the child is walking around.
Let be the position of the toy. From Figure 8.3 the following equations are obtained:
From Figure 8.3 we see that the modulus of the velocity of the toy is given by the modulus of the projection of the velocity of the child onto the bar.
function zs = f(t,z) % [X Xs Y Ys] = child(t); v = [Xs; Ys]; w = [X-z(1); Y-z(2)]; w = w/norm(w); zs = (v'*w)*w;The function f calls the function child which returns the position and velocity of the child for a given time t. As an example consider a child walking on the circle . The corresponding function child for this case is:
function [X, Xs, Y, Ys] = child(t); % X = 5*cos(t); Y = 5*sin(t); Xs = -5*sin(t); Ys = 5*cos(t);
MATLAB offers two M-files ode23 and ode45 to integrate differential equations. In the following main program we will call one of these functions and also define the initial conditions (Note that for the child is at the point and the toy at ):
% main1.m y0 = [10 0]'; [t y] = ode45('f',[0 100],y0); clf; hold on; axis([-6 10 -6 10]); axis('square'); plot(y(:,1),y(:,2));If we plot the two columns of we obtain the orbit of the toy. Furthermore we add the curve of the child in the same plot with the statements:
t = 0:0.05:6.3 [X, Xs, Y, Ys] = child(t); plot(X,Y,':') hold off;Note that the length of the bar does not appear explicitly in the programs; it is defined implicitly by the position of the toy, (initial condition), and the position of the child (function child) for .
Peter Arbenz 2008-09-24