Presentation is loading. Please wait.

Presentation is loading. Please wait.

ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

Similar presentations


Presentation on theme: "ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical."— Presentation transcript:

1 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege.edu Engineering 25 Chp3 Tutorial: Prob 3.14 Solution

2 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 2 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods P3.14 Water Reservoir Vol Using estimates of rainfall, evaporation, and water consumption, the town engineer developed the following model of the water volume in the reservoir as a function of time where V is the water volume in liters, t is time in days, and r is the town's consumption rate in liters per day. Write TWO user-defined functions. The first function should define the function V(t) for use with the fzero function. The second function should use fzero to compute how long it will take for the water volume to decrease to x percent of its initial value of 10 9 L. The inputs to the second function should be x and r. Test your functions for the case where x = 50 percent and r = 10 7 L/day.

3 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 3 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods A NearBy Reservoir

4 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 4 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods A NearBy Reservoir This 315-acre anglers oasis sits in the heart of Suburban Castro Valley but, you'd never know it from your surroundings once inside the park. Miles of parkland and trails make Chabot a haven for outdoor enthusiasts. Hikers can enjoy scenic walks on the 280-acre Fairmont Ridge. Park trails are designed for shared useage. Lake Chabot is well known among the running community. The park hosts Half Marathons, 5K's and the Kids Fun Run. In fact, Trail Runner magazine chose this setting as one of America's Most Scenic Races.

5 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 5 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Water Reservoir Vol  Problem 3-14 appears to have an inconsistency The fzero built-in function operates on any SINGLE VARIABLE function as described in Tab 3.2-1 of the text book. –In this case want to input a V(t), function, NOT a V(t,x,r) function to determine the %-decrease time. The problem, however, says that TWO parameters, x & r, must also be sent to the V(t) function before using fzero

6 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 6 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Use GLOBALS for x&r  We can “work around” the fzero single-varialbe requirement for V(t) by declaring x & r as GLOBAL Variables as described on pg 124 of the Text  Declaring x & r as globals in BOTH the calling function and the V(t) function gives the single-Var function, V(t), access to r & x withOUT listing them in the V-function argument

7 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 7 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Physical Analysis  The Reservoir Volume vs t Function  Now need to find the time, t d, for the volume to decrease TO x-percent of the initial Volume for a given water consumption rate, r i.e, Find t d such that

8 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 8 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Physical Analysis  Now need to define a function for which zeros exist  In this case define a DIFFERENCE Function  Now ΔV will be ZERO when t = t d so that V(t d ) = V final  Thus the function to be zeroed is the DIFFERENCE between V final (the Goal) and V(t) (the Guess) Want: V goal − V guess = 0

9 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 9 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Guess&Check Demo  Make a Time Guess, t Guess  Calc V Guess = V(t Guess )  Calc % Full for the Guess  Calc Difference  Guess AGAIN

10 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 10 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Guess&Check Demo  First Trial Run (Cmd Window) >> r = 1e7 r = 10000000>> >> VtoverVi = @(t) (1e9 + 1e8*(1 - exp(- t/100)) - r*t)/1e9 VtoverVi = @(t)(1e9+1e8*(1-exp(-t/100))-r*t)/1e9 >> Goal = 0.55 Goal = 0.5500 >> Guess31 = VtoverVi(31) Guess31 = 0.7167 >> del31 = Goal - Guess31 del31 = -0.1667

11 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 11 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Guess & Check Ans >> P3_14_ReservoirVolume_1302 r = 10000000 VtoverVi = @(t)(1e9+1e8*(1-exp(-t/100))-r*t)/1e9 Goal = 0.5500 Guess31 = 0.7167 del31 = -0.1667 Guess62 = 0.4262 del62 = 0.1238 Guess47 = 0.5675 del47 = -0.0175 Guess48 = 0.5581 del48 = -0.0081 Guess49 = 0.5487 del49 = 0.0013

12 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 12 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Guess&Check.m-file % Bruce Mayer, PE % ENGR25 * 12Feb13 % Problem 3_14 % P3_14_ReservoirVolume_1302.m r = 1e7 % consumption rate % Create ANON fcn to return % of Initial Vol VtoverVi = @(t) (1e9 + 1e8*(1 - exp(-t/100)) - r*t)/1e9 Goal = 0.55 % to 55% of initial Volume Guess31 = VtoverVi(31) del31 = Goal - Guess31 Guess62 = VtoverVi(62) del62 = Goal - Guess62 Guess47 = VtoverVi(47) del47 = Goal - Guess47 Guess48 = VtoverVi(48) del48 = Goal - Guess48 Guess49 = VtoverVi(49) del49 = Goal - Guess49

13 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 13 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods MATLAB GamePlan  Write the single variable (var = t) function deltaV(t) for use in fzero This function receives parameters r & x as GLOBAL variables rd & xd  Write the calling function, time_to_decrease(x,r), that calls into action fzero with deltaV as its argument This calling function sends rd & xd to deltaV by way of the GLOBAL declaration

14 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 14 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Structure Chart  Note How GLOBALS ByPass the Normal Communication Path

15 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 15 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Fcn deltaV.m

16 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 16 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods time_to_decrease(x,r).m

17 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 17 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods The Calling Program

18 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 18 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Example Call  User Inputs x = 50 & r = 1e7  Takes 54.2 days to drop to 50% initial for use rate of 1e7 Liters per Day Percent of Initial Storage, x = 50 Consumption Rate in L/day, r = 1e7 for x = 50 for r = 10000000 The time to Decrease in Days = 54.1832

19 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 19 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Cmd Window Session  For x = 50%, and r = 1e7 liters per day >> td50_1e7 = time_to_decrease(50,1e7) Rd = 10000000 Xd = 50 t_dec = 54.1832 td50_1e7 = 54.1832  Thus for a 1e7 liter/day consumption rate, a 50% decrease in volume takes about 54 days

20 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 20 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Cmd Window Session  For x = 27%, and r = 4e6 liters/day >> td27_4e6 = time_to_decrease(27,4e6) Rd = 4000000 Xd = 27 t_dec = 204.2576 td27_4e6 = 204.2576  Thus for a 4e6 liter/day consumption rate, a decrease to 27% of the initial volume takes about 204 days

21 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 21 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods DeltaV Plot  Anonymous fcn For x = 27%, and r = 4e6 liters/day dV = Goal – Guess –Goal = 1e9*(27/100) –Guess = (1e9 + 1e8*(1-exp(- tg/100)) - 4e6*tg); >> dV27_4e6 = @(tg) (1e9*(1-73/100 )) - (1e9 + 1e8*(1-exp(-tg/100)) - 4e6*tg); % Vfinal - Vguess >> tplot = linspace(-350,350,700); >> VolDiff = dV27_4e6(tplot); >> plot(tplot, VolDiff, 'LineWidth', 3), grid, xlabel('t (days)'), ylabel('DeltaV (L)'), title('P3-14: Need to ZERO‘)

22 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 22 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods DeltaV Plot  Note that fzero can Return ERRONEOUS (negative) Results if Start-Pt is Off

23 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 23 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Erroneous result  For x = 65%, and r = 1e6 liters/day >> td65_1e6 = time_to_decrease(65,1e6) Rd = 1000000 Xd = 65 t_dec = -184.8166 td65_1e6 = -184.8166  For THIS SET of Parameters fzero found a NEGTIVE (erroneous Root)

24 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 24 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Erroneous DeltaV Plot  fzero found the negative root The can be fixed by changing the starting point to 200

25 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 25 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Erroneous result  For x = 65%, and r = 1e6 liters/day Change This Line in the time_to_decrease code t_dec = fzero('deltaV', 200)  The new (Mathimatically Correct) result >> td65_1e6 = time_to_decrease(65,1e6) Rd = 1000000 Xd = 65 t_dec = 448.8765 td65_1e6 = 448.8765

26 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 26 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Erroneous Comment  Even though 448.9 Days is correct by the Equation, it is NOT physically reasonable  Since Weather is CYCICAL on a 365 day basis, anything over a Year violates nature and is thus NOT Applicable  Some Advice Always do a Reality Check on the Results returned by ANY computer program When in Doubt PLOT

27 BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 27 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods


Download ppt "ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical."

Similar presentations


Ads by Google