% ========================================================================= % Filename: Unrecov2.m % Copyright (c) 2015 John George Anasis % Second MATLAB code to compute unrecovered costs for resources that peak, then drop off % over the time horizon of study. The code computes unrecovered costs for % resources that are still decreasing lambda years after the peak. The % computes the unrecovered costs starting at lambda years after the peak and % then going out to either lambda years or the end of the simulation, % whichever occurs first. % Read in the initial optimization results of the resource of interest, % along with the number of years , time of the simulation, time % step to begin the calculation, the time step to end the calculation, % the resource capital cost K, the discount rate, and the % total number of years that the resource was actually used. % Note that the total number of years the resource was deployed may be made % up of more than one time block (such as a few years of deployment early % in the simulation, no deployment, then another block of deployment). q = xlsread('peakq.xls'); peakparameters2 = xlsread('peakparameters2.xls'); lambda = peakparameters2(1); % Resource lifetime. time = peakparameters2(2); % Total length of the simulation. start = peakparameters2(3); % Time step to start the calculation endtime = peakparameters2(4); % Time step to end the calculation. K = peakparameters2(5); % Resource capital cost. dis_rate = peakparameters2(6); % Assumed discount rate. usetime = peakparameters2(7); % Total number of years the resource was actually deployed. % Compute the resource's annual capital recovery cost per unit of resource % deployed. AnnCap = K * ( (dis_rate/(((1+dis_rate)^lambda)- 1)) + dis_rate ); % Create matrices to track the unrecovered actual cost of the resource deployed. unrecovcost2 = zeros(time,1); % Compute the unrecovered resource costs. Each unrecovered cost is % converted to a net present value (NPV). for u = start:endtime rho = 1/((1+dis_rate)^u); unrecovcost2(u) = ((q(start) - q(u)) * AnnCap * rho); end % Compute the per unit unrecovered cost based on the total resource % deployed over the entire simulation. Sum the NPV's of all the unrecovered costs % and convert this to an annual payment stream over the total number of years the resource was actually deployed. % Divide this annual stream by the sum of all the resource deployed over % the full simulation to get a per unit annual adjustment value that can % then be added to the resource cost. unrecovpu2 = (sum(unrecovcost2(1:time)) * ( (dis_rate/(((1+dis_rate)^usetime)- 1)) + dis_rate ))/sum(q(1:time)); % Write out the results. xlswrite('unrecovcost2.xls',unrecovcost2); xlswrite('unrecovpu2.xls',unrecovpu2);