Docsity

ME2016 Fall 2008 HW3: Solving Mechanism Equation Roots with Matlab - Prof. Aldo Ferri, Assignments of Computer Science

Toggle sidebar
bg1
ME2016, Fall 2008, Dr. Ferri
Homework Assignment 3
Due Wednesday, September 10, 2008
θ2θ4
a
b
c
d
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:
41 42 23 24
() cos() cos() cos( )0fk k k
θ
θθ θθ
=−+−−=
where
1d
ka
=, 2d
kc
=
, and
222 2
32
abcd
kac
−
++
=
Write a Matlab script that performs the following operations (Use θ2 = π/6 radians):
(i) Defines an anonymous function for 4
()f
θ
.
(ii) Solves for the closest root to θ4 = 2 radians using the Matlab function fzero
(iii) Defines a second anonymous function 44 4
() ()gf
θ
θθ
=
+.
(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
create a function
(
)
22
() 3 /
x
f
xxe x
−
=− . Suppose also that we want to find the closest root to
x = 0.5. This can be accomplished with the Matlab commands (in blue), generating the Matlab
responses (in black):
>> fc = @(x) (3*x.^2 - exp(-2*x))./sqrt(x)
fc =
@(x)(3*x.^2-exp(-2*x))./sqrt(x)
pf2

Partial preview of the text

Download ME2016 Fall 2008 HW3: Solving Mechanism Equation Roots with Matlab - Prof. Aldo Ferri and more Assignments Computer Science in PDF only on Docsity!

ME2016, Fall 2008, Dr. Ferri Homework Assignment 3 Due Wednesday, September 10, 2008

a

b

c

d

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:

f ( θ 4 ) = k 1 cos( θ 4 ) − k 2 cos(θ 2 ) + k 3 − cos(θ 2 − θ 4 ) = 0

where

1

d

k

a

d

k

c

= , and

2 2 2 2 3

a b c d

k

ac

Write a Matlab script that performs the following operations (Use θ 2 = π/6 radians):

(i) Defines an anonymous function for f ( θ 4 ).

(ii) Solves for the closest root to θ 4 = 2 radians using the Matlab function fzero

(iii) Defines a second anonymous function g ( θ 4 ) = θ 4 + f (θ 4 ).

(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

create a function f ( ) x = ( 3 x^2 − e −^2 x )/ x. Suppose also that we want to find the closest root 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 =

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?

Problem 3 (2 points) Write a Matlab script that solves for θ 4 - values given a vector of θ 2 – values. In particular, your script should: (i) Take a vector of theta2 = 0:0.01:(2*pi); (ii) At each value of θ 2 in the vector theta2 , solves for θ 4 using fzero and stores the result in a vector, theta. (iii) Plots θ 4 vs θ 2

From inspection of the plot, give the minimum and maximum values attained by θ 4 as θ 2 goes through a complete revolution.