340 B Programs of Chapter 3: Velocity and Acceleration Analysis
omega = n
*
pi/30; % rad/s
% sym constructs symbolic numbers and variables
t = sym(’t’,’real’);
% phi(t) the angle of the diver link
% with the horizontal axis
% phi(t) is a function of time, t
% position of joint B
xB=AB
*
cos(sym(’phi(t)’));
yB=AB
*
sin(sym(’phi(t)’));
% position vector of B in terms of phi(t) - symbolic
rB = [xB yB 0];
% subs(S,OLD,NEW) replaces
% OLD with NEW in the symbolic expression S
xBn = subs(xB,’phi(t)’,pi/6); % xB for phi(t)=pi/6
yBn = subs(yB,’phi(t)’,pi/6); % yB for phi(t)=pi/6
rBn = subs(rB,’phi(t)’,pi/6); % rB for phi(t)=pi/6
fprintf(’rB = [ %g, %g, %g ] (m)\n’, rBn)
% velocity of B1=B2
% diff(S,t) differentiates S with respect to t
% vB1=vB2 in terms of phi(t) and diff(phi(t),t)
vB = diff(rB,t);
% calculates numerical value of vB for
% phi(t)=pi/6 and phi’(t)=omega
% creates a list slist for the symbolical variables
% phi’’(t), phi’(t), phi(t)
slist = ...
{diff(’phi(t)’,t,2), diff(’phi(t)’,t), ’phi(t)’};
% creates a list nlist
% with the numerical values for slist
nlist = {0, omega, pi/6};
% diff(’phi(t)’,t,2) -> 0
% diff(’phi(t)’,t) -> omega
% ’phi(t)’ -> pi/6
% replaces slist with nlist in vB
vBn = subs(vB,slist,nlist);
% double(S) converts the symbolic object S
% to a numeric object
% converts the symbolic object vBn
% to a numeric object
VB = double(vBn);