1

Appendix A:
Matlab codes:
Step1:
clc;
clear all;
syms p1
syms p2
syms p3
x1=561;y1=7.92;z1=0.00156;x2=310;y2=7.85;z2=0.00194;x3=78;y3=7.97;z3=0.0048
2;
f1= x1+y1*p1+z1*p1^2;
f2= x2+y2*p2+z2*p2^2;
f3= x3+y3*p3+z3*p3^2;
%diffreniation%
A=diff(f1);
B=diff(f2);
C=diff(f3);
N=ones(4,4);%making an matrix to fill it with values'
%filling the values of the equations into a matrix to be solved later%
N(1,1)=2*z1;
N(2,2)=2*z2;
N(3,3)=2*z3;
% the value of lamda
N(1,4)= -1;
N(2,4)= -1;
N(3,4)= -1;
%the rest values of the equations
N(1,2)= 0;
N(1,3)= 0;
N(2,1)= 0;
N(2,3)= 0;
N(3,1)= 0;
N(3,2)=0;
N(4,4)=0;
Y= [-y1; -y2; -y3;850];
Z=N\Y;% solving the 4 matrcies
p1=Z(1)
p2=Z(2)
P3=Z(3)
Lamda=Z(4)

Step2
clc;
clear all;
syms p1 ; syms p2 ; syms p3 ;
L1=0;L2=0;L3=0;
x1=459;y1=6.48;z1=0.00128;x2=310;y2=7.85;z2=0.00194;x3=78;y3=7.97;z3=0.0048
2;
f1= x1+y1*p1+z1*p1^2;

-y2. -y3.m1=150.4)= -1.m3=50. f3= x3+y3*p3+z3*p3^2. N(4.% solving the 4 matrcies p1=Z(1). end if p2>M2 p2=M2. C=diff(f3).4)= -1. Z=N\Y. %diffreniation% A=diff(f1). N(1. N(2. % the value of lamda in the matrix N(1. N(2. else p1=p1.1)=2*z1. iter=1. elseif p1<m1 p1=m1. p3=Z(3).4). Lamda=Z(4). N(3.4)= -1. N=ones(4. Y= [-y1. %the rest values of the equations N(1. end . iter=1.4)=0.3)= 0.2 f2= x2+y2*p2+z2*p2^2.1)= 0. %Checking the limitations% if p1>M1 p1=M1. N(3.2)= 0.3)=2*z3.850]. M3=200. p2=Z(2).%making an matrix to fill it with values' %filling the values of the equations into a matrix to be solved later% N(1. iter=2.m2=100. elseif p2<m2 p2=m2. N(3.1)= 0. %putting the limits M1=600. M2=400. N(3. load=850.3)= 0. N(2. iter=2. N(2. B=diff(f2).2)=2*z2. else p2=p2.2)=0.

if L2 >= lamda p2=m2. if L2<= lamda p1=M1. else p3=p3. if M2<p2<m2 lamda = y2*1 + z2*2*p2.3 if p3 >M3 p3=M3. end p2=850-p1-p3. end end if p3==M3 L3=y3*1 + z3*2*p3. elseif p3<m3 p3=m3. elseif M1<p1<m1 lamda = y1*1 + z1*2*p1. end if (iter==1) if p1==M1 L1=y1*1 + z1*2*p1. iter=2. if L2 <= lamda p2=M2. if L2>= lamda p1=m1. elseif M3<p3<m3 lamda = y3*1 + z3*2*p3. end . end end if p2==M2 L2=y2*1 + z2*2*p2. if L3<= lamda p3=M3. iter=1. iter=1. end end end if (iter==2) if p1==m1 L1=y1*1 + z1*2*p1. end end if p2==m2 L2=y2*1 + z2*2*p2.

%the variable of teh losses% xloss=0.00156.1 1 0].c3=0. syms p1 syms p2 syms p3 x1=561. Z1=N1\Y1. end end % diffrentiation of cost functions& .3) -1.Y(3).y2=7. if L3>= lamda p3=m3.y3=7.00003. lamda= Z1(3). p2= Z1(1).load-p1]. %the equations of the cost functions% f1= x1+y1*p1+z1*p1^2.z2=0.00194. yloss=0.y1=7.2) 0 -1. f3= x3+y3*p3+z3*p3^2.97.85.0048 2.92.0 N(3.00009. p3= Z1(2). end end end p1 p2 p3 lamda Step3 clc. p(2)=input('initial guess for the 2nd unit: '). zloss=0. while(prog==1) p(1)=input('initial guess for the 1st unit: '). if((p(1)+p(2)+p(3))>850|| (p(1)+p(2)+p(3))<850) prog=1.x3=78. load=850.z1=0. p(3)=input('initial guess for the 3rd unit: '). f2= x2+y2*p2+z2*p2^2. clear all. % to make sure that the inital guess are between the limits% prog=1. Y1=[Y(2).00012.4 end if p3==m3 L3=y3*1 + z3*2*p3. else N1=[N(2. else prog=0.x2=310.

3)=2*z3. %initiate matrix to fill it with linear cost and losses functions elements% N=zeros(4. N(4. N(1.4)= -(1-diffloss(1.4). %solving the equations simltanously% M=N\Y. p(1)=M(1).001. N(4. Y= [-y1.% intiate amtrix to put the updated value in ot% iter=0. N(1.5 A=diff(f1). 0. 0].% the toleranced K=[0. end p1 P2 P3 Lamda . N(4. -y3. N(2.4)= -(1-diffloss(1. Lamda=M(4).3)= 1.3)). p(3)=M(3).2)).1)= 1.1)=2*z1. C=diff(f3). p(2)=M(2).2)= 1.2)=2*z2. N(2.1)). iter=iter+1. N(3. N(3. while (abs(p(1)-Q(1))>e||abs(p(2)-Q(2))>e|| abs(p(3)-Q(3))>e) K=p. e=0. diffloss=[2*xloss*p(1) 2*yloss*p(2) 2*zloss*p(3)].% to keep the new value updated% loss= xloss*p(1)^2+ yloss*p(2)^2+ zloss*p(3)^2. -y2. (850+loss)].4)= -(1-diffloss(1. B=diff(f2).

Sign up to vote on this title
UsefulNot useful