How do you control flow with conidtional statement to evaluate multivariable function?

1 view (last 30 days)
After trying a variety of things (logical variables, dummy variables, etc), I'm turning here for help. Any assistance would be greatly appreciated.
My target output variable is q. I am calculating values for q using a hyperbolic decline function shown in my code at the bottom (hyperdecline) over a time range t and a range of constants b. For b >1 and as t --> infinity so does my output q --> infinity. So, my goal is to modify my analysis in the most efficient manner possible so that beyond a certain point my decline curve declines at such a rate that eventually q = 0.
My goal: generate output for q over the same range of t and b as I have previously, however, subject to the conditions/constraints below:
For t = 0:365, calculate q using hyperdecline
For t= 366:n, if q(t-1) < qab then q = 0…otherwise q = Min (hyperdecline(at time t) or q(t-366)*(1-dt))
In practice…for t = 366, if the value of q at t=366 using hyperdecline is < qab then I’d want q(366) = 0, otherwise I’d want the minimum of q(366) using hyperdecline or q(0) of hyperdecline multiplied by (1-dt).
When done correctly, I would end up with a curve like in the graph below that continued along the blue curve and then transitioned to the red curve.
Code for function and generating curves
% hyperdecline function
function q = hyperdecline(qi,B,di,T)
q = qi*(1+B.*di.*T).^(-1./B);
%Decline curve with b-factor comparison
% qi = IP rate (initial 24-hr production rate)
% di = initial decline rate (nominal)
% b = B-factor (constant)
% n = terminal day
% t = time period range (normally days) from 0 to n
% qab = production abandonment rate
% dt = terminal decline rate (exponential)
% Type curve inputs
qi = 20000;
di=.01;
b=1:0.1:2;
n=14399
t = 0:n;
qab=500;
dt=.05;
% Curve Calculations
[T B] = ndgrid(t,b);
q = hyperdecline(qi,B,di,T);
qcum = cumsum(q);
qm = squeeze(sum(reshape(q',size(b,2),30,[]),2))'; % Aggregate q into 30 day months
Example curves from excel:

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!