"EE Student " <np7@cec.wustl.edu> wrote in message <hv3h60$d1d$1@fred.mathworks.com>...
> Hey guys, I have a problem I have been working on for a bit and seem to be stuck with. Hopefully I can describe the problem well enough so that everyone understands what I am trying to do. Just so everyone knows, this is not a homework or school related problem. What I have is a matrix, lets call it LD, which has size = [365 24]. Yep, you guessed it, its 365 days worth of hourly data. I also have 3 sets of monthly target data. The target data described the hourly maximum, hourly minimum, and total energy for each month for 3 regions. My goal is to take my known matrix LD, and scale it such that I create 3 new matrices, call the P1, P2, and P3 such that the targets for each month, for each region are met. My initial approach is to scale LD on a monthly basis for each of the target regions to create 3 new matrices that meet the monthly max and min target, then to ajust these new
> matrices to match the monthly energy targets.
>
> This is not my code but an attempt to explain my goals using equations, and also note that siince I have monthly target numbers each of these in effect will represent a months worth of hourly data and the process will be repeated 12 times.
>
> LD = P1 + P2 + P3;
> P1 = LD * S1 + E*Y1
> P2 = LD * S2 + E*Y2
> P3 = LD * S3 + E*Y3
>
> Where
>
> S1,S2,S3 are the scale factors to meet the monthly max and min targets.
>
> X1 = LD*S1
> X2 = LD*S2
> X3 = LD*S3
>
> X1,X2,X3 are known ouputs of the scaling portion of the algorithm which has been accomplished. Therefore in the following equations X1,X2,X3 and LD are all known matrices with size = [number_of _days_in_month hour] and the minimum and maximum targets are exactly met by the respective X matrices for each region so these two hours in each of the X matices cannot be adjusted further.
>
> LD = X1 + X2 + X3 + E
> P1 = X1 + E*Y1
> P2 = X2 + E*Y2
> P3 = X3 + E*Y3
>
> E = LD  sum(X1+X2+X3)
>
> sum(P1) = monthly energy target for region 1
> sum(P2) = monthly energy target for region 2
> sum(P3) = monthly energy target for region 3
>
> P1(day,hour) +P2(day,hour)+P3(day,hour) = LD(Day,hour) for all days and hours in the year.
>
> Any suggestions on how to determine Y1,Y2,and Y3 subject to these constraints would be appreciated. To me this sounds like an optimization problem, however I am not that familiar with the optimization toolbox. I have been trying to solve using fgoalobtain but never reaches a solution, it runs for about an hour and I end up stopping it as I figure after that ammount of time if it doesnt reach a solution it is not going to or I have entered somthing incorrectly. Below are the code used so far, there is quite a bit.
>
> %%%%%%%%%%%%%%%%%%%%
> Scalling functions:
>
> function signalOut = signalScale(baseSignal,targetMin,targetMax)
>
>
> target = [targetMin targetMax];
> baseChar = [min(baseSignal(:)) max(baseSignal(:))];
>
> %determination of process
> test = fliplr(target)  baseChar;
>
> if sum(test<0) == 2
> signalOut = scaleValleys(baseSignal,target);
> signalOut = scalePeaks(signalOut,target);
> else
> signalOut = scalePeaks(baseSignal,target);
> signalOut = scaleValleys(signalOut,target);
> end
>
> function signalOut = scaleValleys(baseSignal,target)
>
> baseChar = [min(baseSignal(:)) max(baseSignal(:))];
> alphaMax = diff(baseChar);
> signalOut = zeros(size(baseSignal));
> x = @(alpha) alphaMax/(alphaMaxalpha);
> %scale valleys
> if baseChar(1) > target(1)
> peakDiff=(baseChar(1)target(1))/target(1);
>
> for day=1:size(baseSignal,1)
> for hour=1:24
> alpha=max(baseChar(1),baseSignal(day,hour))...
> min(baseChar(1),baseSignal(day,hour));
> if alpha == alphaMax
> alpha = alpha  1e43;
> end
> signalOut(day,hour)=baseSignal(day,hour)/...
> ((peakDiff)/(x(alpha))+1);
> end
> end
> elseif baseChae(1) < target(1)
> peakDiff=(target(1)baseChar(1))/baseChar(1);
> for day=1:size(baseSignal,1)
> for hour=1:24
> alpha=max(baseChar(1),baseSignal(day,hour))...
> min(baseChar(1),baseSignal(day,hour));
> if alpha == alphaMax
> alpha = alpha  1e43;
> end
> signalOut(day,hour)=baseSignal(day,hour)*...
> ((peakDiff)/(x(alpha))+1);
> end
> end
> else
> signalOut = baseSignal;
> end
>
> function signalOut = scalePeaks(baseSignal,target)
>
> baseChar = [min(baseSignal(:)) max(baseSignal(:))];
> alphaMax = diff(baseChar);
> signalOut = zeros(size(baseSignal));
> x = @(alpha) alphaMax/(alphaMaxalpha);
>
> %scale peaks
> if baseChar(2) > target(2)
> peakDiff=(baseChar(2)target(2))/target(2);
>
> for day=1:size(baseSignal,1)
> for hour=1:24
> alpha=max(baseChar(2),baseSignal(day,hour))...
> min(baseChar(2),baseSignal(day,hour));
> if alpha == alphaMax
> alpha = alpha  1e43;
> end
> signalOut(day,hour)=baseSignal(day,hour)/...
> ((peakDiff)/(x(alpha))+1);
> end
> end
> elseif baseChae(2) < target(2)
> peakDiff=(target(2)baseChar(2))/baseChar(2);
> for day=1:size(baseSignal,1)
> for hour=1:24
> alpha=max(baseChar(2),baseSignal(day,hour))...
> min(baseChar(2),baseSignal(day,hour));
> if alpha == alphaMax
> alpha = alpha  1e43;
> end
> signalOut(day,hour)=baseSignal(day,hour)*...
> ((peakDiff)/(x(alpha))+1);
> end
> end
> else
> signalOut = baseSignal;
> end
>
> %%%%%%%%%%%%%%%%%%%%%
>
> The Targets and Base Signal are imported from excel and seperated into months but i figured I did not need to share that portion, if I do let me know andI can post it.
>
> The sclaing operations are done for each month and for each of the 3 regions.
>
> %%%%%%%%%%%%%%%%%%%%%%%
> Then my attempt at using fgoalobtain for january
>
> LD_month = zeros(31,31);
> LD_month(1:31,1:24) = LD(1:31,:);
> y = zeros(31,31,3);
> for i = 1:3
> newMonthlyStats(:,:,i) = xlsread('monthlyLoadStats1.xls',sheet{1,i},'N23:P34');
> y(1:31,1:24,i) = X(1:31,:,i);
> end
> Z = zeros(31,31);
> Z(1:31,1:24) = sum(y,3);
> dE = LD_monthZ;
>
> x0 = zeros([31 31 3]);
> x0(1:31,1:24,:) = 1;
> weight = ones(size(LD));
> goal = LD;
>
> targetEnergyRegion1=newMonthlyStats(1,1,1);
> targetEnergyRegion2=newMonthlyStats(1,1,2);
> targetEnergyRegion3=newMonthlyStats(1,1,3);
>
> x = fgoalattain(@(x) fun(x,y(:,:,1),y(:,:,2),y(:,:,3),LD,dE),x0,goal,weight,[],[],[],[],[],[],@(x) confun(x,y(:,:,1),y(:,:,2),y(:,:,3),targetEnergyRegion1,targetEnergyRegion2,targetEnergyRegion3,dE));
>
>
>
> function f=fun(x,p1,p2,p3,P,E)
> f = P  ((p1+E*x(:,:,1))+(p2+E*x(:,:,2))+(p3+E*x(:,:,3)));
>
>
> function [c ceq] = confun(x,p1,p2,p3,g1,g2,g3,dE)
> c=[];
> ceq(1) = g1sum(sum(p1 +dE*x(:,:,1)));
> ceq(2) = g2sum(sum(p2+dE*x(:,:,2)));
> ceq(3) = g3sum(sum(p3+dE*x(:,:,3)));
>
>
> Again, any help or suggestions are appreciate, if I have done a poor job explaining my problem or you feel as though I have left any important information out, please let me know.
>
> Nick
Oh and my mistake, I accidently called the function fgoalobtain instead it should have been fgoalattain and in the snips of code
this:
weight = ones(size(LD));
goal = LD;
should have been:
weight = ones(size(LD_month));
goal = LD_month;
I was chaning the variable from my actual code to match the equation I used to descibe the problem above and missed these changes. Hopefully I didnt miss any other but I would hope you can see what I was trying to do
Thanks
