Problem: In short, I am trying to use a loop to evaluate a function over a range of one variable input with everything else held equal and continue getting the error "In an assignment A(I) = B, the number of elements in B and I must be the same."
I've pre-allocated matrices for the output and can't figure out what I'm doing wrong. I've tried to keep the code vectorized by using a 3D variable and element-wise multiplication, but eventually learned that was not the correct method to use.
My code is below, and a more thorough overview of the calculations is discussed below the code.
My desired output from the loop are the pvq_pr and payout_pr values at every value in the variable price
Thanks in advance.
Code:
price = 3.00:0.50:5.00;
pvq_pr = zeros(size(price,2),size(qm_30,2));
payout_pr = zeros(size(price,2),size(qm_30,2));
for ii = 1:length(price)
netcfq_pr = sum(qm_30.*(nri.*(price(ii)+pricediff) - price(ii).*prodtax - opex_var) - opex_fix);
netcfq_pr(isnan(netcfq_pr))=0;
netcfq_ec_pr = netcfq_pr.*(netcfq_pr>0);
cfq_pr = [-wellcost_row; netcfq_ec_pr];
netcfcumq_pr = cumsum(cfq_pr);
pvq_pr(ii) = pvvar(cfq_pr,disc_rate/12);
payout_pr(ii) = sum(netcfcumq_pr<0);
end
Further detail:
qm_30 is the output of a function I wrote which generates production values for a hybrid curve which is both hyperbolic and exponential (representing natural gas production from a well). So with., qm_30 solved for, I am then trying to assess the economic viability of the separate well cases (each column in qm_30) by calculating netcfq_pr (monthly net cash flow) given qm_30, commodity price (price), and certain costs (production taxes, variable operating expenses, and fixed operating expenses).
Calculating netcfq for one (scalar) price was easy, but when I wanted to calculate what netcfq_pr for price = $3.00:0.50:$5.00 I ran into trouble.