



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




ME2016, Fall 2008, Dr. Ferri Homework Assignment 3 Due Wednesday, September 10, 2008
Problem 1 (5 points) A 4-bar mechanism is a popular mechanism that converts rotary motion of one link to oscillatory or “rocking” motion of another. In the mechanism above, the following dimensions are given: a = 1, b = 2, c = 4, and d = 4. If θ 2 is specified, θ 4 can be obtained as the solution (root) of the following equation:
where
1
2 2 2 2 3
Write a Matlab script that performs the following operations (Use θ 2 = π/6 radians):
(ii) Solves for the closest root to θ 4 = 2 radians using the Matlab function fzero
(iv) Uses the function g to perform a fixed-point algorithm, starting with θ 4 = 2 radians. (v) Automatically stops the fixed-point algorithm when εa < 0.01 %.
Compare the result from your fixed-point algorithm to the answer obtained using fzero.
Anonymous Functions To make an anonymous function in Matlab, use the following syntax. Suppose that we want to
x = 0.5. This can be accomplished with the Matlab commands (in blue), generating the Matlab responses (in black):
>> fc = @(x) (3x.^2 - exp(-2x))./sqrt(x)**
fc =
@(x)(3x.^2-exp(-2x))./sqrt(x)
>> fzero(fc,0.5)
ans =
Solution: With θ 2 = π/6, the function is shown in the figure below.
0 0.5 1 1.5 2 2.5 3 3.
0
2
4
6
θ 4 (rad)
f(θ
) 4
It is seen that the root is near the location θ 4 = 2.5 rad, or 143O. Before applying the fixed-point algorithm, let us compute g(θ 4 ) and its derivative:
4 1 4 2 4 4
1 sin( ) sin( ) dg k d
fixed-point method should converge. The first few iterates are given below, clearly showing (oscillatory) convergence
2.0000, 3.0001, 2.5859, 2.4187, 2.4968, 2.4505, 2.4759, 2.4612, 2.4695, 2.4648, 2.4674, 2.4659, 2.4668, 2.4663, 2.4666, 2.
Problem 2 (3 points) Compute the true, relative, percent error, εt, in the fixed point algorithm of Problem 1; use the value of θ 4 obtained using fzero as the “true root” value. Plot the log of the magnitude of εt vs the iteration number n for n = 1 to 10. What does the plot resemble, especially as n increases?
Solution According to the theory, we should have (^) ( Et ) (^) i + 1 = g ′( xr )( Et ) i where Et is the true error. Used
recursively, we have
0 1 2 3 4 5 6 7
3
θ 2 (rad)
θ^4
(rad)
% Solution to HW % 4-Bar Mechanism
a=1; b=2; c=4; d=4; t2 = pi/6; % theta2 in radians k1=d/a; k2=d/c; k3=(a^2 - b^2 + c^2 + d^2)/(2ac);
fa = @(x) k1cos(x)-k2cos(t2)+k3-cos(t2-x);
% Plot function
figure(5) x=0:0.01:pi; plot(x,fa(x),'linewidth',2) xlabel('\theta_4 (rad)') ylabel('f(\theta_4)') grid
x4 = 2 x4true = fzero(fa,x4)
eps_a = 1e6; eps_s = 0.01; i = 1; x4 = 2; x4v(1) = x4; while eps_a > eps_s; i = i + 1;
x4old = x4; x4 = x4 + fa(x4); x4v(i) = x4; % store intermediate values eps_a = 100*abs((x4-x4old)/x4); end i x4v'
eps_t = 100*abs((x4true - x4v)/x4true); Elog = log10(eps_t); n = 1:i; % form vector from n = 1 to n = last value of i figure(12) plot(n,Elog,'linewidth',2) xlabel('n'); ylabel('log(\epsilon_t)'); grid
gprime = @(x) -k1*sin(x) - sin(t2-x) + 1; figure(6) plot(x,gprime(x)) grid
x2=0:0.01:(2pi); L2=length(x2); x4i=3; % initial guess for theta for i = 1:L2; t2 = x2(i); fa = @(x) k1cos(x)-k2*cos(t2)+k3-cos(t2-x); x4i = fzero(fa,x4i); x4(i) = x4i; end
figure(7) plot(x2,x4,'linewidth',2) xlabel('\theta_2 (rad)') ylabel('\theta_4 (rad)') grid
min_theta4 = min(x4)180/pi max_theta4 = max(x4)180/pi