Extra Material for Tutorial 4

2
Tutorial #4 (extra material for those who has trouble with Quiz #2) A belt runs around two pulleys as shown . The length L of the belt can be calculated using the equations given. where A = an angle (in radians) R1 = radius of larger pulley (in m) R2 = radius of smaller pulley (in m) C = distance between pulley centres (in m) L = belt length (in m) Reminder: Matlab has a built-in constant called "pi". Suppose that we would like a function (calcL.m) that, given values for C, R1, and R2, computes and returns L. Apart from the fact that the computation is best done in two steps (first calculate A, then calculate L) the required function is about as straightforward as one can get. function [L] = calcL (C, R1, R2) A = ...; L = ....; end Write and test the function. Now suppose that what is really needed is a function (calcC.m) that, given values for L, R1, and R2, computes and returns C. As a first step, one might consider trying to "invert" the given equations. This is a good idea when it's possible but when it's not banging one's head against the wall for 65 minutes isn't such a great idea. Instead it's time for root finding. The problem boils down to finding a value of C such that calcL (C, R1, R1) = the given value for L Or, to put it another way, we want to find the value of C that satisfies calcL (C, R1, R1) - L = 0 ) 2 ( 2 ) 2 ( 1 cos 2 2 1 sin 1 A R A R A C L C R R A C radius R2 radius R1

description

tutorial

Transcript of Extra Material for Tutorial 4

Page 1: Extra Material for Tutorial 4

Tutorial #4 (extra material for those who has trouble with Quiz #2) A belt runs around two pulleys as shown . The length L of the belt can be calculated using the equations given.

where A = an angle (in radians) R1 = radius of larger pulley (in m) R2 = radius of smaller pulley (in m) C = distance between pulley centres (in m) L = belt length (in m) Reminder: Matlab has a built-in constant called "pi". Suppose that we would like a function (calcL.m) that, given values for C, R1, and R2, computes and returns L. Apart from the fact that the computation is best done in two steps (first calculate A, then calculate L) the required function is about as straightforward as one can get. function [L] = calcL (C, R1, R2) A = ...; L = ....; end Write and test the function. Now suppose that what is really needed is a function (calcC.m) that, given values for L, R1, and R2, computes and returns C. As a first step, one might consider trying to "invert" the given equations. This is a good idea when it's possible but when it's not banging one's head against the wall for 65 minutes isn't such a great idea. Instead it's time for root finding. The problem boils down to finding a value of C such that calcL (C, R1, R1) = the given value for L Or, to put it another way, we want to find the value of C that satisfies calcL (C, R1, R1) - L = 0

)2(2)2(1cos2

21sin 1

ARARACLC

RRA

C

radius R2

radius R1

Page 2: Extra Material for Tutorial 4

As we've already written calcL and have given values for R1 and R2, the root finding function can be written as f = @(C) calcL(C, R1, R2) - L; If L is reasonable C must lie somewhere between R1 + R2 (pulleys just touching) and L/2 (the distance we'd get if the pulleys were infinitely small). This provides the necessary limits for root finding. It is a good idea to check that the given L is in fact reasonable (i.e. that the belt is not too short to go around the pulleys even when they are just touching each other). Note that you have the means (calcL) of calculating the shortest possible belt length. Note also that it doesn't make much sense to do all the calculations and then check to see whether the inputs are unreasonable. Check first and abort the function (using "error") if there's a problem. Write function calcC and then test it. What should we get if we enter the following? >>calcC (calcL (5, 10, 20), 5, 10) Finally, let us imagine that all we really want is calcC and that we don't want to clutter up our folder by having calcL in a separate file. There are two possible approaches. If calcL were sufficiently simple that it could easily be implemented as an anonymous function, we could just define an appropriate anonymous function inside calcC. A separate calcL would then no longer be required. As this isn't really practical in this case, the second approach must be used instead. This involves adding calcL (exactly "as is") to the end of file calcC.m. Once this is done file calcL.m can be discarded. Function calcL becomes a subfunction of calcC and can only be accessed from within calcC.m.