0 While we wish to have the input and output angles expressed in degrees, we shall also need the radian values to use the cosine function in the Freudenstein equation.. 258 A Guide to Mi
Trang 1Differential Equations 253
Problems 1 .* Solve the first-order differential equation y’ = -x$ with y(0)
= 1 with steps of h = 0.2 to estimate the value of y( 1) using (a) Euler’s method and (b) the Runge-Kutta method
2 In this chapter we have examined two methods of solving differential equations There are many more One of these is the midpoint method which uses:
Yn+, = y , + W X , + % h a n + W f ( X n 7 Y n ) )
Develop a worksheet to use this method to solve y’ = xy at x
= 0.5 when the initial condition is y(0) = 1 We solved the same problem in Exercises 1 and 2 Which of the three methods gives the more accurate result with the same h
where I,(O) =I,(O) = 0
Use the Runge-Kutta method to approximate I,(t) and 12(t)
at t = 0 to 0.5 seconds in 0.1 second intervals
4 A rocket has a mass of 2000 kg of which 1500 kg is fuel It
burns the fuel at the rate of 25 kg/s and develops a thrust of
5000 N Construct a worksheet to find how the velocity varies with time What will be the height when the fuel is all consumed?
Trang 313
Concepts In this chapter we use what we have learnt in the last three chapters
to model some practical problems
Exercise 1 : The Four- In this exercise we examine an engineering mechanism used to
generate a complex motion from a simple rotational motion
bar Crank: Using
The four-bar mechanism (see Figure 13.1) consists of three movable links (a, b and c ) and a fixed link d The link a is rotated
causing link c to rotate
a sin 8+b sin p-csin <p = 0
a c&+b COS p c COS+ + d = 0 Adding the squares of these gives the Freudenstein equation:
R, -~,cos<p+~,-cos(e-<p)=o
Trang 4256 A Guide to Microsoft Excel 2002 for Scientists and Engineers
be convenient to use named cells
(b) Enter the text and values in A4:B8 Select A5:BS and name the cells B5:B8
(c) Enter the text in A9:All Enter the formulas:
B9: =d/c-
B10: =d/a
Bf 1 : =(aA2 -bA2 + c-A2 + dA2)/(2*a*c-)
(d) Select A9:B 1 I and name the cells in B9:B 1 1
We begin by solving the Freudenstein equation for two input angles, 0" and 5 O
Trang 5Modelling I1 257
(e) Enter 0 and 5 in D3 and D4, respectively
(0 While we wish to have the input and output angles expressed
in degrees, we shall also need the radian values to use the cosine function in the Freudenstein equation So, enter the following formulas:
E3: =RADIANS(D3) Converts the input angle to radians F3: =DEGREES (G3) Converts the output angle to degrees G3: 1 The starting point for Solver
H3: =Ratiol*COS(E3) - Ratio2*COS(G3) + Ratio3 -
COS( E3-G3)
Formatting F3 to show one decimal place improves the readability of the worksheet
(g) Copy E3:H3 down to line 4
(h) Invoke Solver (ToolslSolver) Click the Reset All button to restore the options to the default values: Max Time = 100 secs, Iterations = 100, Precision = 0.00000 1 and Convergence = 0.0001
(i) Set the Target CeII to H3 Click the radio button EquaI to Value and enter 0 in the value box In the By Changing Cells
enter G3 Click the Solve button Solver should be given a value close to 0 in H3 The output angle in G3 should be approximately 0.72 radians and the corresponding value in degrees in F3 should be 41.4
(j) Use Solver to find the output angle corresponding to an input
angle of 5' in row 4 Remember to change the Target and
Changing cells The result should be 43 I"
Do not be concerned that the values in column H are not identically
zero but are in the range 1 x IO-' to 1 x IO-' depending on your computer system We are modelling a real system; the components will have some slack so we do not need extreme precision
We now expand the worksheet in preparation for finding the output angles corresponding to input angles in the range 0 to 360 in 5 degree intervals
(k) Enter values of I in G3:G4 Select D3:H4 and copy the cells down to line 75 The value in D75 will be 360 - we have covered the full input range
Trang 6258 A Guide to Microsoft Excel 2002 for Scientists and Engineers
In earlier editions of this book we
solved this problem by using Solver
four times - one for each quadrant
ofthe input range Modem Pentium
computers have no trouble finding
the solution to 73 equations
(I) Enter the text shown in A 13 :A 14 and in B 14 enter the formula
=SUMSQ(H3:H75) This should result in the value 35.56
(m) Use Solver with the following input parameters: Target B 14,
Equal to Value of 0 and Changing Cell G3:G75
Solution: 30 Set target cell: 1.87E-OI
2 It is possible that Solver will report one of the following
conditions: The maximum time limit was reached: continue
anyway? or The maximum iterations limit was reached; continue anyway? If either message occurs, click Continue
3 If at any time you wish to halt Solver, press m+m
When Solver has completed its task B 14 will have a value of about
3 x lo-’ There is too much data to absorb so it would be a good idea to make a chart Figure 13.3 shows the results graphically
Trang 7Modelling II 259
You may wish to try other values for the lengths of the cranks
Bear in mind that the sum a + b + c- should be somewhat larger
than d
Exercise 2:
Circular References
When the formula in a cell refers to its own address we say that
there is a circular reference in the worksheet Normally, we wish
to avoid this condition but there are occasions when it is useful One such use is explored in this exercise
Temperature Profile:
Side A T = 100°C
Side C T = 200°C Figure 13.4
Description
The edges of a thin metal sheet are maintained at specified
temperatures and the sheet is allowed to come to thermal equi I i bri um
so we will use an approximation We shall consider a finite number
Trang 8260 A Guide to Microsoft Excel 2002 for Scientists and Engineers
of equidistant points on the plate and use the discrete mean-value theory which states that the temperature at point P is the average
of the temperatures of P’s nearest neighbours
The most convenient way to arrive at the equidistant point is to divide the plate using equally spaced vertical and horizontal lines
In Figure 13.4 two such lines have been drawn parallel to each axis This gives four interior points for the calculation With such
a small number, the results will not be very accurate However, the methodology is the same regardless of the number of points, and
it is simpler to describe and test the method initially with four points
The equations for the four interior points are:
(a) Move to Sheet2 ofCHAPl3.XLS From the Tools menu select
Options, and click on the Calculation tab Set the calculation method to Manual Click to the Iteration box to put a check mark in it and set the Maximum Iterations to 1
the end ofthe exercise
Trang 9Modelling 11 261
(b) Enter the text shown in Al:A14 of Figure 13.5 and Select A4:B14 and name the cells in the B column Although B11 is named TI, we shall need to refer to it as TI- since T1 is a cell address
(c) Enter the formulas shown below Be careful to use commas not
+ signs between each item in the AVERAGE arguments B11: =IF(Flag=l, AVERAGE(SideA, T2-, T3-, SideD), 0)
B12: =IF(Flag=l, AVERAGE(SideA, SideB, T4-,T1-), 0)
B13: =IF(Flag=l, AVERAGE(Tl-, T4-, SideC, SideD), 0)
B14: =IF(Flag=l, AVERAGE(T2-, SideB, SideC, T3-), 0)
The worksheet is now ready to use Every time we enter a new value, the worksheet must be recalculated by pressing [ because
we are using manual recalculation mode
(d) Enter the value 1 in the Flag cell and press @ The Tvalues will change Repeatedly tap @ and Microsoft Excel will repeat the calculation After a number of iterations (20 or so), the values will cease to change and will be as shown in Figure 13.6 You may wish to check that the temperature of each internal point is the average of its nearest neighbours
(e) If you wish to experiment with the I value do the following:
(i) Enter 0 in the Flag cell and press [
(ii) UseToolslQptions to set theMaximum Iterations to 100
(iii) Enter a value of 1 in the Flag cell and press [
(iv) Repeatedly press [F91 until the Tvalues remain constant You will need to press [ far fewer times with
Maximum Iterations set to 100
Repeat steps (i) to (iv) to experiment with other values (v)
You may wish to make a note on the worksheet reminding yourself, or other users, to set Manual Calculations on next time
the workbook is used
Here is where we reset the
Calculation options (0 Using ToolslQptions, open the Calculations tab and reset
Calculation to Automatic, uncheck the iterations box and set the Maximum Calculations to 100 Save the workbook
A
You are encouraged to expand on the exercise to solve the same problem but using more internal points Divide the plate into 36 squares and note how the temperatures of the points corresponding
to those we have calculated come out with slightly different values
Trang 10262 A Guide to Microsoft Excel 2002 for Scientists and Engineers
Exercise 3: ~~~ ~ ~ In this exercise we model the same system as in Exercise 2 but use
a matrix method to compute the temperatures Again, we use only four internal points to facilitate discussion A more accurate model
is obtained using more points
To be able to use a matrix method each equation in Equation 13.2
must have the same form:
t , = (O.OOt, + 0.25t2 + 0.25t3 +o.oot4) + (a + d)/4 t2 = (0.25t, + 0.00t2 + 0.00t3 +0.25t4) + (a + b)/4
From Equation 13.6 we note that, in the worksheet, we shall need
a matrix M for the coefficients, an identity matrix I of the same rank as M, a matrix B for the temperatures of the sides, and a matrix T to hold the solutions
Trang 11If the status bar displays Continue,
then you overlooked the last step in
the previous exercise You need to
reset Excel for automatic
calculations
(a) On Sheet3 of CHAPl3.XLS, enter the text and values shown
in rows 1,3 and 4 of Figure 13.7 Select A3:D4, name the cells A4:D4
(b) Enter the text and values as shown in A7:D19
(c) In A20 enter the formula =A14 - A8 Copy this to A20:D23 to compute the elements of [ I - A ]
(d) Enter the text in F7 Select F8:II 1 and type the formula
=MINVERS(MO: D23) Press [Ctrll+[mShift+[Enterl to complete the array formula This computes [I - A 4 - l
(e) Enter the text in F13 The formulas for this matrix are: F14: =(SideA + SideD)/4
F15: =(SideA + SideB)/4
F16: =(SideC + SideD)/4
F 17: =(SideB + SideC)/4
(f) Enter the text in H13:H17
(g) All that remains is to multiply [I - A]-' by B Select I14:117,
type the formula =MMULT(F8:111, F14:F17) Press
Trang 12264 A Guide to Microsoft Excel 2002 for Scientists and Engineers
[Ctrll+[m]+[Enterl The solutions in I1 4:117 should agree with those found in the previous exercise
(h) Save the workbook
Exercise 4: Emptying In this exercise we solve a simple differential equation using the
Runge-Kutta method In Chapter 12 we placed the terms needed for the Rung-Kutta approximation on the worksheet In this exercise we use a user-defined function In the subsequent exercise
a function is used to iterate the approximation
the Tank
The problem chosen has an analytical solution You may wish to find it and compare the results from it with those found using the Runge-Kutta approximation
The analytical result i s a parabolic
function Only values to the left o f
the minimum are meaningful
Description
A cylindrical tank of diameter D has a short pipe of diameter d at
the bottom The tank is initially filled with water to a height h
Working in metric units, we shall use g = 9.8 ms-2
We begin by developing a user-defined function to compute dWdt
for any value of h Since we wish to vary the diameter of the pipe,
we could treat d as a variable also To make the function more
general, it is better to make both d and D variables The number of variables may be reduced if we write the equation as
dh/dt = -R2 Jzgh where R = d/D The quantity R is not really
a variable; it is a parameter which we wish to vary from case to case We pass it to the user-defined function in the same way as a true variable The required function in given in Figure 13.8 This uses the VBA square root function SQR rather than the worksheet function SQRT
Trang 13Modelling N 265
The parentheses around 2*kl and
2*k2 in line 7 are not required
However, because ofthe way VBA
spaces, they were added to make
the equation more readable
'The function of the differential equation
tank = -(ratio * 2) * Sqr(2 * g * height)
Figure 13.8
The'function to perform the Runge-Kutta approximation is shown
in Figure 13.9 Compare the k expressions with those in Equation 12.12 Since t does not appear to the right in the differential equation we are solving, there are no x terms in our k expressions They term of Equation 12.12 becomes the height term What was called h in Equation 12.12, we call incr (short for increment) in our function The ratio term has been added so that it may be passed
to the tank function Line 7 performs the final calculation We must
be careful in the worksheet to call this function with the height, incr and ratio arguments in the correct order
'Function to compute Runge-Kutta approximation Function RKapprox(height, incr, ratio)
k l = incr * tank(height, ratio) k2 = incr * tank(height + k l / 2, ratio) k3 = incr * tank(height + k2 / 2, ratio) k4 = incr * tank(height + k3, ratio) RKapprox = height + ( k l + (2 * k2) + (2 * k3) + k4) / 6 End Function
(b) On Sheet 4, enter the values shown in A1 :D7 of Figure 13.10 The formula in C7 is: =C6*0.01/C5 The 0.01 converts the pipe diOameter to metres
(c) Enter the text in B9:C9
(d) Cells B10 and C 10 contain the initial time and height values
In B 10 enter the value 0 and in C 10 enter the formula 4 3
Trang 14266 A Guide to Microsoft Excel 2002 for Scientists and Engineers
(f) Hopefully, your worksheet returns the value 0.999 in C 1 I An
error value of #NAME! means that the name of the function in the cell does not match that in the module If C11 shows
#VALUE!, check (i) that the arguments in the formula point to the correct value and (ii) that the RKapprox function is correctly coded
(g) Save the workbook
Clearly, the tank has discharged very little in 1 second We cannot increase the value in C4 since this would cause the Runge-Kutta function to return inaccurate values We must extend the worksheet
if we wish to find the height at large time values
Trang 15Modelling 11 267
(h) Copy B 1 1 :C11 down to row 1 IO Row 1 10 will give the height (0.892 m) at 10 seconds
Our data extends over more than 100 rows and is too much to
absorb We need to make a summary
(i) Enter the text shown in El :F2 and the series shown in E3:E12
of Figure 13.1 I
0.935 0.924 0.91 3
Figure 13.11
6 ) in F3 enter the formula =VLOOKUP(E3, B10:CI I O , 2, TRUE)
This function is used to do a ‘lookup’ on a vertical table such
as the one in B 1O:C 1 IO The first argument (E3) specifies that
we wish to find in the first column (the function always searches the first column) of the table a value matching that in E3 The next argument gives the range of the table to be searched The third argument (2) specifies that we wish to return the value in the second column of the table from the row
in which a match was found The final argument (TRUE) specifies that we want an exact, not an approximate, match The function returns the value 0.989 since, on row 20 of the table, the value in the first column (B) has a value matching that in E3 The function then returns the value from the second column
(k) Copy E3:F3 down to row 12 Save the workbook
We may now vary the pipe diameter value and observe how the discharge changes You may wish to make a graph of either
BI0:CI I O or the summary data Do not be misled into thinking
that the height is linearly related to the time This may be
Trang 16268 A Guide to Microsoft Excel 2002 for Scientists and Engineers
The worksheet we developed in the previous exercise had two faults The second is readily addressed: use column D to hold the parameters and results for a second pipe diameter The fact that the worksheet gives results for a limited time range could be addressed
by extending the table further down the sheet but would result in
a very large worksheet In this exercise we investigate another way
of achieving the same end
Figure 13.12a shows our first attempt to design a function to call the RKapprox function n times
We may call this function from the worksheet in, for example, C 1 I
using the formula =NewHeight(ClO, incr, ratio, I O ) where C10 contains the starting value for the height of the water in the tank,
incr is a name cell containing the increment for the Runge-Kutta calculation, and ratio is a named cell holding the value of the ratio
rows in the previous worksheet is now done on one row
The Runge-Kutta method is not accurate when h gets small
compared to incr and may result in negative values which are meaningless in this model We therefore modify the iteration function so that it stops before completing the n iterations if h is
small This is shown in Figure 13.12b