Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Matlab code: WRITE A MATLAB CODE: Assignment: Write a function that determines the critical travel time and critical oxygen concentration by using the

Write a Matlab code:

image text in transcribed

WRITE A MATLAB CODE:

Assignment: Write a function that determines the critical travel time and critical oxygen concentration by using the Parabolic Interpolation method. Your main function, myPI, should include a sub-function with the Golden-Section Search method, as given in Figure 7.7 of your text. This function returns the local minimum, which corresponds to the critical travel time and critical oxygen concentration. The approximate error and the number of iterations it took to converge to the minimum value with the approximate error are also returned. Your function should perform the same task by using parabolic interpolation, as explained in Section 7.7.2 of your text. Please note that Eq. 7.10 shows the function evaluated at the three points used to define the parabola. This is only necessary for the first step. In subsequent steps, the values of the function at those points are known. Do not reevaluate them. Your function should return the location of the minimum and the number of iterations needed to achieve the same approximate error limit of 0.1%. Create two vectors: PImin = [xminPI, fminPI, iterPI], and GSmin = [xminGSS, fmGSS, iterGSS]. Return these two vectors as the output of your function:

function [ PImin, GSmin ] = myPI (f, xl, xu, es, maxit)

% Input:

% f = name of function

% xl & xu = initial guesses

% es = desired error, 0.1%

% maxit = maximum allowable iterations

% Output:

% xminPI = critical travel time from PI, xminGSS = critical travel time from GSS,

% fminPI = critical oxygen concentration from PI, fminGSS = critical oxygen

% concentration from GSS

% iterPI = number of iterations from PI, iterGSS = number of iterations from GSS

[xminGSS,fmGSS,eaGSS,iterGSS]=goldmin(f,xl,xu,es,maxit);

GSmin = [xminGSS, fmGSS, iterGSS];

end % end of function

The function of Golden-Section Search is below:

function [xminGSS, fmGSS, iterGSS]= goldmin(f,xl,xu,es,maxit)

% goldmin: minimization golden section search

% [xminGSS, fmGSS, iterGSS]=goldmin(f,xl,xu,es,maxit):

% uses golden section search to find the minimum of f

% input:

% f = name of function

% xl, xu = lower and upper guesses

% es = desired relative error (default = 0.1%)

% maxit = maximum allowable iterations (default = 100)

% output:

% xminGSS = location of minimum

% fmGSS = minimum function value

% iterGSS = number of iterations

if nargin

if nargin

if nargin

phi=(1+sqrt(5))/2;

iterGSS = 0;

while(1)

d = (phi-1)*(xu - xl);

x1 = xl + d;

x2 = xu - d;

if f(x1)

xopt = x1;

xl = x2;

else

xopt = x2;

xu = x1;

end

iterGSS = iterGSS + 1;

if xopt~=0, ea = (2 - phi) * abs((xu - xl) / xopt) * 100;end

if ea = maxit,break,end

end

xminGSS = xopt;

fmGSS = f(xopt);

end% end of the function

Background:The Streeter-Phelps model can be used to compute the dissolved oxygen concentration in a river below a point discharge of sewage (Fig. 1), where o = dissolved oxygen concentration (mg/L), o,-oxygen saturation concentration (mg/L), t- travel time (d), L.- biochemical oxygen demand (BOD) concentration at the mixing point (mg/L), kd-rate of decomposition of BOD (d"), ks= rate of settling of BOD (d"), k,-reaeration rate (d-1), and Sb - sediment oxygen demand (mg/L/d) 12 kd +k,-k Sb mg/L) 0 4 0 10 t (d) 15 20 Fig. 1 As indicated in Fig. 1, Eq. (1) produces an oxygen "sag" that reaches a critical minimum level oc, some travel time t, below the point discharge. This point is called "critical" because it represents the location where biota that depends on oxygen (like fish) would be the most stressed 1 Os = 10 mg/L k, = 0.05 k,-0.1d' L,-50 mg/L k, = 0.6 S,-1 mg/L/d Background:The Streeter-Phelps model can be used to compute the dissolved oxygen concentration in a river below a point discharge of sewage (Fig. 1), where o = dissolved oxygen concentration (mg/L), o,-oxygen saturation concentration (mg/L), t- travel time (d), L.- biochemical oxygen demand (BOD) concentration at the mixing point (mg/L), kd-rate of decomposition of BOD (d"), ks= rate of settling of BOD (d"), k,-reaeration rate (d-1), and Sb - sediment oxygen demand (mg/L/d) 12 kd +k,-k Sb mg/L) 0 4 0 10 t (d) 15 20 Fig. 1 As indicated in Fig. 1, Eq. (1) produces an oxygen "sag" that reaches a critical minimum level oc, some travel time t, below the point discharge. This point is called "critical" because it represents the location where biota that depends on oxygen (like fish) would be the most stressed 1 Os = 10 mg/L k, = 0.05 k,-0.1d' L,-50 mg/L k, = 0.6 S,-1 mg/L/d

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions