[email protected] engr-25_hw-01_solution.ppt 1 bruce mayer, pe engineering/math/physics 25:...

27
[email protected] • ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected] Engineering 25 Chp3 Tutorial: Prob 3.14 Solution

Upload: jarrod-standring

Post on 14-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 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

[email protected] • ENGR-25_HW-01_Solution.ppt1

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Bruce Mayer, PELicensed Electrical & Mechanical Engineer

[email protected]

Engineering 25

Chp3Tutorial: Prob 3.14Solution

Page 2: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt2

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

P3.14 Water Reservoir VolUsing 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 109 L. The inputs to the second function should be x and r. Test your functions for the case where x = 50 percent and r = 107 L/day.

Page 3: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt3

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

A NearBy Reservoir

Page 4: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt4

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.

Page 5: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt5

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

Page 6: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt6

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

Page 7: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt7

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Physical Analysis

The Reservoir Volume vs t Function

rtetV t 10089 11010

Now need to find the time, td, for the volume to decrease TO x-percent of the initial Volume for a given water consumption rate, r• i.e, Find td such that

100/xVVtV initialfinald

Page 8: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt8

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

tVVtV final Now ΔV will be ZERO when

t = td so that V(td) = Vfinal

Thus the function to be zeroed is the DIFFERENCE between Vfinal (the Goal) and V(t) (the Guess)• Want: Vgoal − Vguess = 0

Page 9: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt9

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Guess&Check Demo

Make a Time Guess, tGuess

Calc VGuess = V(tGuess)

Calc % Full for the Guess

Calc Difference

Guess AGAIN

9

10089

10

11010Guess%

rte

V

tV t

init

Guess%Goal%del

Page 10: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt10

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Guess&Check Demo

First Trial Run (Cmd Window)>> r = 1e7r = 10000000>>

>> VtoverVi = @(t) (1e9 + 1e8*(1 - exp(-t/100)) - r*t)/1e9VtoverVi = @(t)(1e9+1e8*(1-exp(-t/100))-r*t)/1e9

>> Goal = 0.55Goal = 0.5500

>> Guess31 = VtoverVi(31)Guess31 = 0.7167

>> del31 = Goal - Guess31del31 = -0.1667

Page 11: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt11

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Guess & Check Ans>> P3_14_ReservoirVolume_1302r = 10000000VtoverVi = @(t)(1e9+1e8*(1-exp(-t/100))-r*t)/1e9Goal = 0.5500Guess31 = 0.7167del31 = -0.1667Guess62 = 0.4262del62 = 0.1238Guess47 = 0.5675del47 = -0.0175Guess48 = 0.5581del48 = -0.0081

Guess49 = 0.5487del49 = 0.0013

Page 12: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt12

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.mr = 1e7 % consumption rate% Create ANON fcn to return % of Initial VolVtoverVi = @(t) (1e9 + 1e8*(1 - exp(-t/100)) - r*t)/1e9 Goal = 0.55 % to 55% of initial VolumeGuess31 = VtoverVi(31)del31 = Goal - Guess31Guess62 = VtoverVi(62)del62 = Goal - Guess62Guess47 = VtoverVi(47)del47 = Goal - Guess47Guess48 = VtoverVi(48)del48 = Goal - Guess48Guess49 = VtoverVi(49)del49 = Goal - Guess49

Page 13: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt13

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

Page 14: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt14

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Structure Chart

Note How GLOBALS ByPass the Normal Communication Path

Page 15: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt15

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Fcn deltaV.mfunction diffV = deltaV(t);% Bruce Mayer, PE * 3Mar12% ENGR25 * Problem 3-14%% Function to find Vfinal - V(t) where%* Vfinal = 1e9*(x/100)%** x = the percent OF the 1e9 starting vol%* V(t) = 1e9 + 1e8(1-exp(-t/100) - r*t per eqn in P3-14%** r => water consumption rate%** 1e8(1-exp(-t/100) => Rain Replenishment function over 100 day% time constant for the rainy season%** 1e9 => Starting Volume at beginning of rainy season%% This function is to be used in the fzero built-in function% fzero accepts ONLY SINGLE variable functions%* Thus Parameters X & R MUST be passed into this fcn as GLOBALS%global Rd XdV_of_t = 1e9 + 1e8*(1-exp(-t/100)) - Rd*t;% Waterlevel dropping BY x-pctVfinal = 1e9*(Xd/100); %% calc DIFFERENCE between the final and V(t) valuesdiffV = Vfinal - V_of_t;

Page 16: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt16

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

time_to_decrease(x,r).mfunction t_dec = time_to_decrease(x,r);% Bruce Mayer, PE * 01Mar12% ENGR25 * Problem 3-14%% Function to find: diffV = Vfinal - V(td) = 0 % calc diffV using Function deltaV%% Now function deltaV needs parameters x & r passed into % it as GLOBALS as discussed within deltaV.m%* need to change the names of the Globalsso that they are not%* confused with local variables X & Rglobal Rd XdRd = rXd = x%% calc time to decrease stored volume by x-percent using% fzero on diffV caluation using fcn deltaV%* use general guess of 100 days [the rain replenishment time-constant]%* for the diffv(t_dec) = 0t_dec = fzero('deltaV', 100)

Page 17: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt17

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

The Calling Program% Bruce Mayer, PE% ENGR25 * 17Sep12% file = Prob3_14_1209.m% UDF's:%* time_to_decrease.m%* deltaV.m%% Ask Town Engineer for Scenario-ParaMeter InPutxi = input('Percent of Initial Storage, x = ');ri = input('Consumption Rate in L/day, r = ');%% Call Into Action the solving functiontd = time_to_decrease(xi,ri);%% Display Results%disp('for x = ')disp(xi)disp('for r = ')disp(ri)disp(' ')disp('The time to Decrease in Days = ')disp(td)

Page 18: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt18

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 = 50Consumption Rate in L/day, r = 1e7for x = 50

for r = 10000000

The time to Decrease in Days = 54.1832

Page 19: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt19

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 = 10000000Xd = 50t_dec = 54.1832td50_1e7 = 54.1832

Thus for a 1e7 liter/day consumption rate, a 50% decrease in volume takes about 54 days

Page 20: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt20

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 = 4000000Xd = 27t_dec = 204.2576td27_4e6 = 204.2576

Thus for a 4e6 liter/day consumption rate, a decrease to 27% of the initial volume takes about 204 days

Page 21: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt21

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‘)

Page 22: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt22

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

DeltaV Plot

Note that fzero can Return ERRONEOUS (negative) Results if Start-Pt is Off

-400 -300 -200 -100 0 100 200 300 400-1

-0.5

0

0.5

1

1.5x 10

9

t (days

Del

taV

(L)

P3-14: Need to ZERO

Page 23: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt23

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 = 65t_dec = -184.8166td65_1e6 = -184.8166

For THIS SET of Parameters fzero found a NEGTIVE (erroneous Root)

Page 24: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt24

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

-400 -200 0 200 400 600 800-4

-3

-2

-1

0

1

2

3

4

5

6x 10

8

t (days

Del

taV

(L)

P3-14: Need to ZERO

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

[email protected] • ENGR-25_HW-01_Solution.ppt25

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 = 1000000Xd = 65t_dec = 448.8765td65_1e6 = 448.8765

Page 26: BMayer@ChabotCollege.edu ENGR-25_HW-01_Solution.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical

[email protected] • ENGR-25_HW-01_Solution.ppt26

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

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

[email protected] • ENGR-25_HW-01_Solution.ppt27

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods