Professional Documents
Culture Documents
Dynamics
JERRY GINSBERG
Georgia Institute of Technology
Solutions to Chapter 8
Chapter 8, Page 1
Chapter 8, Page 2
Chapter 8, Page 3
Chapter 8, Page 4
Chapter 8, Page 5
Chapter 8, Page 6
Chapter 8, Page 7
Chapter 8, Page 8
Chapter 8, Page 9
Chapter 8, Page 10
Chapter 8, Page 11
Chapter 8, Page 12
Chapter 8, Page 13
Chapter 8, Page 14
Chapter 8, Page 15
Chapter 8, Page 16
Chapter 8, Page 17
Chapter 8, Page 18
Chapter 8, Page 19
Chapter 8, Page 20
Chapter 8, Page 21
Chapter 8, Page 22
Chapter 8, Page 23
Chapter 8, Page 24
Chapter 8, Page 25
Chapter 8, Page 26
Chapter 8, Page 27
Chapter 8, Page 28
Chapter 8, Page 29
Chapter 8, Page 30
options=odeset('RelTol',1e-8,'AbsTol',1e-8);
%---------------------------------------------------------------------------
-----
% Set start and end times for calling o.d.e. solver
t0 = 0;
tf = 60;
x_prime = @(t, x) Boat_accel_new(t, x, mass, kappa, H);
X_g = x(:,1);
Y_g = x(:,2);
theta = x(:,3);
speed = sqrt(x(:,4).^2 + x(:,5).^2);
N = length(t);
disp(['Final position: t = ', num2str(t(N))]);
disp([' X_G = ', num2str(X_g(N)), ', Y_G', num2str(Y_g(N)), ...
', theta =', num2str(theta(N))]);
figure(1)
plot(t,X_g,'k-', t,Y_g,'r:')
figure(2)
plot(X_g,Y_g,'K-')
figure(3)
plot(t,speed,'k-')
%-------------------------------------------------------------
function dx_dt = Boat_accel_new(t, x, mass, kappa, H)
% Exercise 8.17. Power boat
% Evaluate right side of state-space differential equations
% q = [X_A Y_A theta]', x' = [q' dq_dt']
theta = x(3);
a = [sin(theta) -cos(theta) 0];
a_dot = [(x(6) * cos(x(3))) (x(6) * sin(x(3))) 0];
m_mat(1,1) = mass;
m_mat(2,2) = mass;
m_mat(3,3) = mass * kappa^2;
beta = -4 * pi/180;
end
150
XG
100
YG
50
C oordinate (meters )
50
100
150
200
0 10 20 30 40 50 60
T ime (s econds )
Chapter 8, Page 32
80
60
40
20
Y G (meters )
0
S tart
20
40
60
80
100
200 150 100 50 0 50 100 150
X G (meters )
20
18
16
14
12
vG (m/s )
10
0
0 10 20 30 40 50 60
T ime (s econds )
Chapter 8, Page 33
Chapter 8, Page 34
% Exercise 8.18
% Main script file
clear all
g_R = 1.6^2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Part (a) Unconstrained generalized coordinates
% Set up initial conditions.
theta_0 = pi/2; x_0 = [theta_0 0]';
t_max = 16;
dt = 0.01;
i_max = ceil(t_max/dt);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Part (b) Constrained generalized coordinates
% Set up initial conditions.
x_0 = [theta_0 0 0 0]';
end
figure(1)
plot(t_val, x_val_un(:,1)*180/pi, '--r', t_val_con, x_val_con(:,1)*180/pi,
'b:')
xlabel('t (sec))')
ylabel('\theta (deg)')
%------------------------------------------------------------------
function rhs = acc_8_18_un(t, x, g_R)
% Evaluate d^2/dt^2(theta) for Problem 8.18 when theta is the unconstrained
% generalized coordinate
F = 16/3 + 2 * cos(x(1))^2/sin(x(1))^4 - 4 * cos(x(1))/sin(x(1));
dF = - 4 * cos(x(1))/sin(x(1))^3 - 8 * cos(x(1))^3/sin(x(1))^5 +
4/sin(x(1))^2;
d2_theta = -(0.5 * dF * x(2)^2 + 2 * g_R * (sin(x(1)) -
Chapter 8, Page 36
cos(x(1))/sin(x(1))^2))/F;
rhs = [x(2) d2_theta]';
%------------------------------------------------------------------
function dx = acc_8_18_con(t, x, g_R)
% Evaluate d^2/dt^2(q) for Problem 8.18 when q = [theta y] are
unconstrained
% generalized coordinates
a = [((x(2) + 1) * cos(x(1))) sin(x(1))];
R = [[16/3 (2 * sin(x(1))) -a(1,1)]; [(2 * sin(x(1))) 2 -a(1,2)]; [-a
0]];
S = [(-2 * g_R * sin(x(1))); (-2 * x(3)^2 * cos(x(1)) - 2 * g_R); ...
(2 * x(3) * x(4) * cos(x(1)) -(x(2) + 1) * x(3)^2 * sin(x(1)))];
sol = R\S;
dx = [x(3:4); sol(1:2)];
Constrained formulation
Unconstrained formulation
90
80
70
θ (deg)
60
50
40
30
0 2 4 6 8 10 12 14 16
t (sec))
Chapter 8, Page 37
Chapter 8, Page 38
t_max = 10;
dt = 0.01;
i_max = ceil(t_max/dt);
end
% Plot paths of center of mass and of Tundra
figure(1)
plot(tundra_coords(:,1), tundra_coords(:,2), z_val(:,1),z_val(:,2))
xlabel('X (meters)')
ylabel('Y (meters)')
legend('Tundra''s path', 'Path of center of the sled')
figure(2)
plot(t_val(:,1), z_val(:,1), t_val(:,1), z_val(:,2))
xlabel('Time (seconds)')
ylabel('Coordinate (meters)')
legend('x_G)', 'y_G')
figure(3)
plot(t_val(:,1), z_val(:,4), t_val(:,1), z_val(:,5))
xlabel('Time (seconds)')
ylabel('Speed (m/s)')
legend('dx_G/dt', 'dy_G/dt)')
Chapter 8, Page 39
figure(4)
[AX,H1,H2] = plotyy(t_val(:,1), z_val(:,3)*180/pi, t_val(:,1), z_val(:,6));
set(get(AX(1),'Ylabel'),'String','Degrees')
set(get(AX(2),'Ylabel'),'String','Rad/s')
set(H1,'LineStyle','-')
set(H2,'LineStyle','--')
xlabel('Time (Seconds)')
% Find t for theta > 89 deg
j = 1;
while z_val(j,3) * 180/pi < 89
j = j + 1;
end
disp(['Theta at 89 deg when t = ', num2str(t_val(j))])
%-------------------------------------------------------------
function rhs = sled_accel(t, z, mass, kappa, H, L, Cable_F)
% Exercise 8.19 - Tundra pulls a sled
% Evaluate right side of state-space differential equations
% Implementation of augmentation method
% {z} is current state-space vector:
% number of generalized coordinates is 3, so size of {z} is 6
35
30
Tundra's path
Path of center of the sled
25
Y (meters)
20
15
10
0
-25 -20 -15 -10 -5 0 5 10 15
X (meters)
30
25
20 xG)
yG
15
Coordinate (meters)
10
-5
-10
-15
0 1 2 3 4 5 6 7 8 9 10
Time (seconds)
Chapter 8, Page 41
5
dxG/dt
4
dyG/dt)
Speed (m/s)
3
2
1
0
-1
-2
0 2 4 6 8 10
Time (seconds)
150 1
100 dq/dt
0.5
Degrees
50 0 Rad/s
0 -0.5
0 1 2 3 4 5 6 7 8 9 10
Time (Seconds)
Chapter 8, Page 42
Chapter 8, Page 43
% Exercise 8.20
% Main script file
clear all
F_0 = 50; omega = 4; m = 0.8; R = 0.2; kappa = 0.15; g = 9.807;
end
v_center = R * z_val(:,3);
subplot (2,1,2)
plot(t_val, v_center)
xlabel('t (sec))')
ylabel('Velocity (m/s)')
title('v_c_e_n_t_e_r = R d\theta\\dt')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function dz = acc_8_20(t, z, F_0, omega, m, R, kappa, g)
% Evaluate dz/dt for Problem 8.20 where
% z = [theta phi d_theta d_phi]'
a = [cos(z(1)) (-2.5 * cos(z(2)))];
M(1,1) = 6 + 2* kappa^2 + 4 * sin(z(1));
M(1,2) = 3.75 * (sin(z(2)) - cos(z(1) + z(2))); M(2, 1) = M(1,2);
M(2,2) = 25/3;
Force = F_0 * sin(omega * t);
F(1,1) = (Force/(m * R)) * (1 + sin(z(1))) - 2 * z(3)^2 * cos(z(1)) ...
- 3.75 * z(4)^2 * (cos(z(2)) + sin(z(1) + z(2)));
F(2,1) = 2.5 * (Force/(m * R)) * sin(z(2)) ...
- 3.75 * z(3)^2 * sin(z(1) + z(2)) - 1.25 *(g/R) * cos(z(2));
Lhs = [M -a'; -a 0];
Rhs = [F; (-z(3)^2 * sin(z(1)) + 2.5 * z(4)^2 * sin(z(2)))];
sol = Lhs\Rhs;
dz = [z(3:4); sol(1:2)];
f (deg)
f
5000 q 0
0 50
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
15
V elocity (m/s )
10 vc e nte r = R dq/dt
0
0 1 2 3 4 5
t (s ec)
Chapter 8, Page 45
Chapter 8, Page 46
% Integration loop
for i = 1:i_max
end
theta1 = z_val(:,1);
theta2 = z_val(:,2);
r_C = L * [(sin(theta1) + sin(theta2)) (cos(theta1) + cos(theta2))];
figure(1)
% subplot(2,1,1)
plot(t_val, theta1 * 180/pi, ':k', t_val, theta2 * 180/pi, '--k')
xlabel('Time (seconds)')
ylabel('Angle (deg)')
legend('\theta_1', '\theta_2')
figure(2)
plot(r_C(:,1), r_C(:,2))
set(gca,'YDir','reverse')
axis equal
title('Path of end C')
xlabel('X_C')
ylabel('Y_C')
%-----------------------------------------------------------
function dz = acc_8_20(t, z, F_0, omega, m, R, kappa, g)
% Evaluate dz/dt for Problem 8.20 where
% z = [theta phi d_theta d_phi]'
a = [cos(z(1)) (-2.5 * cos(z(2)))];
M(1,1) = 6 + 2* kappa^2 + 4 * sin(z(1));
M(1,2) = 3.75 * (sin(z(2)) - cos(z(1) + z(2))); M(2, 1) = M(1,2);
M(2,2) = 25/3;
Force = F_0 * sin(omega * t);
F(1,1) = (Force/(m * R)) * (1 + sin(z(1))) - 2 * z(3)^2 * cos(z(1)) ...
- 3.75 * z(4)^2 * (cos(z(2)) + sin(z(1) + z(2)));
F(2,1) = 2.5 * (Force/(m * R)) * sin(z(2)) ...
- 3.75 * z(3)^2 * sin(z(1) + z(2)) - 1.25 *(g/R) * cos(z(2));
Lhs = [M -a'; -a 0];
Rhs = [F; (-z(3)^2 * sin(z(1)) + 2.5 * z(4)^2 * sin(z(2)))];
sol = Lhs\Rhs;
dz = [z(3:4); sol(1:2)];
200
Angle (deg)
0 q1
q2
200
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
T ime (s econds )
0.4
P ath of end C
0.2
YC
0
0.2
0.5 0 0.5 1
XC
Chapter 8, Page 49
t_max = 2;
dt = 0.005;
i_max = ceil(t_max/dt);
% Integration loop
for i = 1:i_max
end
%Plot paths
figure(1)
plot(x_A, y_A, x_B, y_B)
legend('Collar A', 'Wheel B')
figure(2)
plot(t_val, theta * 180/pi, '-r', t_val, x_A, ':b')
legend('theta (deg)', 'x_A')
% -----------------------------------------------------------------------
function rhs = steerable_linkage(t, z, m_AB, m_A, L, Cable_F)
% Exercise 8.22 - linkage with a steerable wheel
% Evaluate right side of state-space differential equations
% Implementation of augmentation method
% {z} is current state-space vector:
% number of generalized coordinates is 3, so size of {z} is 6
0.8
0.6
Y (meters )
0. 2
0. 4
0 10 20 30 40 50 60 70 80 90
X (meters )
100
q (deg)
x A (meter)
50
50
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
T ime (s ec)
Chapter 8, Page 52
Chapter 8, Page 53
Chapter 8, Page 54
end
r = z_val(:,1);
psi = z_val(:,2);
% Absolute coordinates
r_C = [(r .* cos(psi)) (r .* sin(psi))];
% Coordinates relative to xyz attached to the turntable
for n = 1:length(t_val)
angle = t_val(n);
Rot = [[cos(angle) sin(angle)]; [-sin(angle) cos(angle)]];
r_C_rel(n, :) = r_C(n, :) * Rot';
end
figure(1)
subplot(2,1,1)
plot(t_val, r, ':k')
ylabel('Radial distance (nondim)')
subplot(2,1,2)
plot(t_val, psi * 180/pi, '--k')
xlabel('Time (seconds)')
ylabel('Angle (deg)')
figure(2)
plot(r_C(:,1), r_C(:,2), '-k', r_C_rel(:,1), r_C_rel(:,2), ':k')
axis equal
title('Path of the center of the sphere')
xlabel('x_C')
Chapter 8, Page 55
ylabel('y_C')
legend('stationary XYZ', 'xyz attached to the turntable')
%--------------------------------------------------------
function dz = acc_8_23(t, z)
% Evaluate dz/dt for Problem 8.23
x = z(1:4); dx = z(5:8);
a = [[1 0 -1 0]; [0 1 0 -sin(x(3))]];
M = [[1 0 0 0]; [0 (x(1)^2 + 0.4) 0 (0.4 * cos(x(3)))]; ...
[0 0 0.4 0]; [0 (0.4 * cos(x(3))) 0 0.4]];
F(1,1) = x(1) * dx(2)^2;
F(2,1) = -2 * x(1) * dx(1) * dx(2) + 0.4 * dx(3) * dx(4) * sin(x(3));
F(3,1) = -0.4 * dx(3) * dx(4) * sin(x(3));
F(4,1) = 0.4 * dx(2) * dx(3) * sin(x(3));
F(5,1) = 0;
F(6,1) = dx(3) * dx(4) * cos(x(3));
Lhs = [M -a'; -a zeros(2)];
sol = Lhs\F;
dz = [z(5:8); sol(1:4)];
12
Radial distance (nondim)
10
2
0 0.5 1 1.5 2 2.5 3 3.5
100
80
Angle (deg)
60
40
20
0
0 0.5 1 1.5 2 2.5 3 3.5
Time (seconds)
Chapter 8, Page 56
2
yC
-2
stationary XYZ
xyz attached to the turntable
-4
-6
-8
-10
-10 -5 0 5 10 15
xC
Chapter 8, Page 57
Chapter 8, Page 58
Chapter 8, Page 59
Chapter 8, Page 60
Chapter 8, Page 61
Chapter 8, Page 62
Chapter 8, Page 63
Chapter 8, Page 64
%------------------------------------------------------------
% Integration loop
for i = 1:i_max
%----------------------------------------------------------------
function dz = acc_8_29(t, z, mu)
% Evaluate dz/dt for Problem 8.29
x = z(1); y = z(2); theta = z(3); dx = z(4); dy = z(5); dtheta = z(6);
n_slip = 1; % Set a flag to control program flow according to slipping
% Check whether slipping has occurred:
v_c_x = dx + 0.5 * dtheta * sin(theta);
if (abs(v_c_x)) < 10^-8
n_slip = 0;
Lhs = [[1 0 0 0 -1]; ...
[0 1 0 -1 0]; ...
[0 0 1/12 0.5*cos(theta) -0.5*sin(theta)]; ...
[0 -1 0.5*cos(theta) 0 0];
[-1 0 -0.5*sin(theta) 0 0]];
F = [0 -1 0 0.5*dtheta^2*sin(theta) 0.5*dtheta^2*cos(theta)]';
sol = Lhs\F;
N = sol(4); f = sol(5); q_2dot = sol(1:3);
% Check if friction force is too large
if N < 0
disp('Negative normal force')
elseif abs(f)/N > mu % If true, reset flag to indicate slipping
n_slip = 1;
end
end
if n_slip == 1
Lhs_slip = [[1 0 0 mu*sign(v_c_x)]; ...
[0 1 0 -1]; ...
[0 0 1/12 0.5*cos(theta)+mu*sign(v_c_x)*sin(theta)]; ...
[0 -1 0.5*cos(theta) 0]];
F_slip = [0 -1 0 0.5*dtheta^2*sin(theta)]';
Chapter 8, Page 66
sol = Lhs_slip\F_slip;
q_2dot = sol(1:3);
end
dz = [z(4:6); q_2dot];
m=0.1
0.5
Coordinates (nondim)
XG
0.4
YG
0.3
0.2
0.1
0
0 0.5 1 1.5 2
80
60
q (deg)
40
20
0
0 0.5 1 1.5 2
Time (seconds)
0.4
0.3
yC
0.2
0.1
g_R = 1.6^2;
mu = 0.1;
theta_0 = 20 * pi/180;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Constrained generalized coordinates
% Set up initial conditions.
x_0 = [theta_0 (1/sin(theta_0) - 1) 0 0]';
t_max = 16
;
dt = 0.01;
i_max = ceil(t_max/dt);
end
figure(1)
subplot(2,1,1)
plot(t_val, x_val(:,1)*180/pi, '-k')
ylabel('\theta (deg)')
subplot(2,1,2)
plot(t_val, x_val(:,3)*180/pi, '-k')
xlabel('t (sec))')
ylabel('d\theta/dt (rad/s)')
%---------------------------------------------------
function dx = acc_8_30(t, x, g_R, mu)
% Evaluate d^2/dt^2(q) for Problem 8.18 when q = [theta y] are
unconstrained
Chapter 8, Page 69
% generalized coordinates
a = [((x(2) + 1) * cos(x(1))) sin(x(1))];
R = [[16/3 (2 * sin(x(1))) -cot(x(1))]; [(2 * sin(x(1))) 2
-(mu*sign(x(3)) + sin(x(1)))]; [-a 0]];
S = [(-2 * g_R * sin(x(1))); (-2 * x(3)^2 * cos(x(1)) - 2 * g_R); ...
(2 * x(3) * x(4) * cos(x(1)) -(x(2) + 1) * x(3)^2 * sin(x(1)))];
sol = R\S;
dx = [x(3:4); sol(1:2)];
120
100
80
θ (deg)
60
40
20
0 2 4 6 8 10 12 14 16
100
50
dθ/dt (rad/s)
-50
-100
0 2 4 6 8 10 12 14 16
t (sec))
Chapter 8, Page 70
Chapter 8, Page 71
Chapter 8, Page 72
t_max = 2;
dt = 0.0005;
i_max = ceil(t_max/dt);
end
figure(1)
plot(t_val, phi * 180/pi, '-r', t_val, N_A, ':b', t_val, N_B, '.g')
legend('phi (deg)', 'N_A/m', 'N_B/m')
xlabel('t (sec)')
%--------------------------------
function rhs = bar_wall(t, z, L, H, mu)
Chapter 8, Page 73
%----------------------------------
function rhs = bar_wall(t, z, L, H, mu)
% Evaluate z_dot for Exercise 8.31 solution using a separate function,
% which can be called independently of the ODE solver in order to examine
% the wall forces
60
50
40
phi (deg)
NA/m
30 NB/m
20
10
-10
0 0.05 0.1 0.15 0.2 0.25
t (sec)