% % % Project # 1 Problem 1-Design of Thin Cylindrical Vessel Graphical solution % ro=7850; density, kg/m^3 % L=8; length, m % P=3.5e6 gas pressure, Pa % E=210e9 stress, Pa % R is the radius % T is the thickness % The problem can be written is standard optimization problem as follows: % Minimize f(x1,x2) = 2*pi*ro*L*R*T+2*0.03*ro*pi*R^2 % subject to the following constraints: % Volum g1(x1,x2) = pi*L*R^2 >= 25 % Stress g2(x1,x2) = P*(2-0.3)/(2*E)*R/T <= 0.001 % Strain g3(x1,x2) = P*R/T <= 210e6 %% side g4(x1,x2) = T <= 0 %% side g5(x1,x2) = R <= 0 % % % % WARNING : The hash marks for the inequality constraints must % be determined and drawn outside of the plot % generated by matlab % %---------------------------------------------------------------ro=7850; % kg/m^3 L=8; %m P=3.5e6 % gas pressure, Pa E=210e9 % stress, Pa x1=0:0.001:2; x2=0:0.0005:0.1; % x1 and x2 are vectors filled with numbers starting % at 0 and ending at 2 and 0.1 with values at intervals of 0.001 [X1 X2] = meshgrid(x1,x2); % generates matrices X1 and X2 correspondin % vectors x1 and x2 % for clarity we define the foolowing variables a1=2*pi*ro*L; a2=pi*L; a3=P*(2-0.3)/(2*E); 1 % objective function is given by f1=a1.*X1.*X2+2*0.03*ro*pi.*X1.^2; % The set inequality constraints are given by ineq1=-a2.*X1.^2+25; ineq2=a3.*X1./X2-0.001; ineq3=3.5e6.*X1./X2-210e6; ineq4=-X2; ineq5=-X1; % poltting the contours [C1,h1] = contour(x1,x2,ineq1,[0,0],'r-'); set(h1,'LineWidth',1) %clabel(C1,h1); hold on % allows multiple plots k1 = gtext('g1=0'); % add text tothe figure set(k1,'FontName','Times','FontWeight','bold','FontSize',10,'Color','red') % will place the string 'g1' on the lot where mouse is clicked [C2,h2] = contour(x1,x2,ineq2,[0,0],'r--'); %clabel(C2,h2); set(h2,'LineWidth',1) k2 = gtext('g2=0'); set(k2,'FontName','Times','FontWeight','bold','FontSize',10,'Color','red') [C3,h3] = contour(x1,x2,ineq3,[0,0],'b-'); %clabel(C3,h3); set(h3,'LineWidth',1) k3 = gtext('g3=0'); set(k3,'FontName','Times','FontWeight','bold','FontSize',10,'Color','blue') [C4,h4] = contour(x1,x2,ineq4,[0,0],'b--'); %clabel(C4,h4); set(h4,'LineWidth',1) k4 = gtext('g4=0'); set(k4,'FontName','Times','FontWeight','bold','FontSize',10,'Color','blue') [C5,h5] = contour(x1,x2,ineq5,[0,0],'b--'); %clabel(C5,h5); set(h5,'LineWidth',1) 2 k5 = gtext('g5=0'); set(k5,'FontName','Times','FontWeight','bold','FontSize',10,'Color','blue') [C,h] = contour(x1,x2,f1,[8000,10000,20000],'g'); clabel(C,h); set(h,'LineWidth',1) % The equality and inequality constraints are not written % with 0 on the right hand side. If you do write them that way % you would have to include [0,0] in the contour commands xlabel(' R (m)','FontName','times','FontSize',10,'FontWeight','bold'); % label for x-axes ylabel(' t (m)','FontName','times','FontSize',10,'FontWeight','bold'); k6 = gtext('Project 1: Problem 1') set(k6,'FontName','Times','FontSize',10,'FontWeight','bold') %grid on hold off The result of graphical solution is obtained as follows: 3 % Problem 1 –Solution using MATLAB toolbox clear x0=[0.001 0.001]; xlb=[0.0001 0.0002 ]; % lower bound xub=[] ; % upper bound options=optimset('LargeScale','off','Display','iter'); [x,f]=fmincon('objfunc1',x0,[],[],[],[],xlb,xub,'cons1',options) function f = objfunc1(x) a1=2*pi*7850*8; a2=pi*8; a3=3.5e6*(2-0.3)/(2*210e9); f=a1.*x(1).*x(2)+2*0.03*7850*pi.*x(1).^2; function [c, ceq] = cons1(x) a1=2*pi*7850*8; a2=pi*8; a3=3.5e6*(2-0.3)/(2*210e9); ineq1=-a2.*x(1).^2+25; ineq2=a3.*x(1)./x(2)-0.001; ineq3=3.5e6.*x(1)./x(2)-210e6; ineq4=-x(2); ineq5=-x(1); c=[ineq1;ineq2;ineq3;ineq4;ineq5]; ceq=[]; The exact solution using MATLAB toolbox is obtained as: R = 0.9974m , t = 0.0166 m , f = 8.0135e+003 4 % Project # 1 % Problem 2- Design of Flag Pole % Graphical solution % standard form of the optimization problem is : % minimize f=(X1.^2-X2.^2); % subject to % g1=(a1+a2)./I-0.1; % deflection % g2=M*X1./(2*I)-165e6; % bending stress % g3=(a3./I).*(X2.^2+X2.*X1+X1.^2)-50e6; % shear stress % g4=(X1+X2)./(X1-X2)-60; % Mean diam./thickness % g5=(X1-X2)/2-0.02; % thickness< .02 m % g6=-(X1-X2)/2+0.005; % g7=X1-0.5; % g8=0.05-X1; % g9=X2-0.45; % g10=0.04-X2; % whre X1 is " do " and X2 is " di " %---------------------------------------------------------------clear x1=0:0.01:0.50; % The semi-colon at the end prevents the echo x2=0:0.01:0.50; % These are also the side constraints [X1 X2] = meshgrid(x1,x2); % generates matrices X1 and X2 corresponding % vectors x1 and x2 E=210e9; ro=7800; W=2000; H=10; P=4000; M=(P*H+0.5*W*H^2); S=(P+W*H); A=(pi/4)*(X1.^2-X2.^2); I=(pi/64)*(X1.^4-X2.^4); a1=P*H^3/(3*E); a2=W*H^4/(8*E); a3=S/12; %Pa %kg/m^3 %N/m %m %N %N.m %N %m^2 %m^4 f1=(X1.^2-X2.^2); ineq1=(a1+a2)./I-0.1; % deflection ineq2=M*X1./(2*I)-165e6; % bending stress ineq3=(a3./I).*(X2.^2+X2.*X1+X1.^2)-50e6; % shear stress ineq4=(X1+X2)./(X1-X2)-60; % Mean diam./thickness ineq5=(X1-X2)/2-0.02; % thickness< .02 m 5 ineq6=-(X1-X2)/2+0.005; ineq7=X1-0.5; ineq8=0.05-X1; ineq9=X2-0.45; ineq10=0.04-X2; [C1,h1] = contour(x1,x2,ineq1,[0,0],'r-'); % %clabel(C1,h1); % set(h1,'LineWidth',1) % % ineq1 is plotted [at the contour value of 8] % hold on % allows multiple plots % k1 = gtext('g1=0'); % add text tothe figure set(k1,'FontName','Times','FontWeight','bold','FontSize',10,'Color','red') % % % will place the string 'g1' on the lot where mouse is clicked % [C2,h2] = contour(x1,x2,ineq2,[0,0],'r--'); % %clabel(C2,h2); set(h2,'LineWidth',1) k2 = gtext('g2=0'); set(k2,'FontName','Times','FontWeight','bold','FontSize',10,'Color','red') [C3,h3] = contour(x1,x2,ineq3,[0,0],'b-'); % %clabel(C3,h3); set(h3,'LineWidth',1) k3 = gtext('g3=0'); set(k3,'FontName','Times','FontWeight','bold','FontSize',10,'Color','blue') %will place the string 'g1' on the lot where mouse is clicked [C4,h4] = contour(x1,x2,ineq4,[0,0],'b--'); %clabel(C4,h4); hold on set(h4,'LineWidth',1) k4 = gtext('g4=0'); set(k4,'FontName','Times','FontWeight','bold','FontSize',10,'Color','blue') [C5,h5] = contour(x1,x2,ineq5,[0,0],'b--'); %clabel(C5,h5); set(h5,'LineWidth',1) k5 = gtext('g5=0'); 6 set(k5,'FontName','Times','FontWeight','bold','FontSize',10,'Color','blue') % [C6,h6] = contour(x2,x1,ineq6,[0,0],'c--'); %clabel(C6,h6); set(h6,'LineWidth',1) k6 = gtext('g6=0'); set(k6,'FontName','Times','FontWeight','bold','FontSize',10,'Color','blue') [C7,h7] = contour(x1,x2,ineq7,[0,0],'r--'); %clabel(C6,h6); set(h7,'LineWidth',1) k7 = gtext('g7=0'); set(k7,'FontName','Times','FontWeight','bold','FontSize',10,'Color','blue') [C8,h8] = contour(x1,x2,ineq8,[0,0],'b--'); %clabel(C6,h6); set(h8,'LineWidth',1) k8 = gtext('g8=0'); set(k8,'FontName','Times','FontWeight','bold','FontSize',10,'Color','blue') [C9,h9] = contour(x1,x2,ineq9,[0,0],'r--'); %clabel(C6,h6); set(h9,'LineWidth',1) k9 = gtext('g9=0'); set(k9,'FontName','Times','FontWeight','bold','FontSize',10,'Color','blue') [C10,h10] = contour(x1,x2,ineq10,[0,0],'b--'); %clabel(C6,h6); set(h10,'LineWidth',1) k10 = gtext('g10=0'); set(k10,'FontName','Times','FontWeight','bold','FontSize',10,'Color','blue') [C,h] = contour(x1,x2,f1,[0,0.0111,.1],'g'); clabel(C,h); set(h,'LineWidth',1.5) grid on % The equality and inequality constraints are not written % with 0 on the right hand side. If you do write them that way % you would have to include [0,0] in the contour commands xlabel(' do (m)','FontName','times','FontSize',12,'FontWeight','bold'); % label for x-axes ylabel(' di (m)','FontName','times','FontSize',12,'FontWeight','bold'); k11 = gtext('project 1: problem 2') set(k11,'FontName','Times','FontSize',12,'FontWeight','bold') grid on hold off 7 The graphical solution is obtained as: 8 % Problem 2 –Solution using MATLAB toolbox clear x0=[.05 .6]; xlb=[0.05 0.04 ]; xub=[0.50 0.45] ; % lower bound % upper bound options=optimset('LargeScale','off','Display','iter'); [x,f]=fmincon('objfunc2',x0,[],[],[],[],[],[],'cons2',options) g=cons2(x) function f = objfunc2(x) f=(x(2)^2-x(1)^2); function [c, ceq] = cons2(x) E=210e9; %Pa ro=7800; %kg/m^3 W=2000; %N/m H=10; %m P=4000; %N M=(P*H+0.5*W*H^2); %N.m S=(P+W*H); %N A=(pi/4)*(x(2).^2-x(1).^2); %m^2 I=(pi/64)*(x(2).^4-x(1).^4); %m^4 a1=P*H^3/(3*E); a2=W*H^4/(8*E); a3=S/12; ineq1=(a1+a2)./I-0.1; %ineq1=P*H^3./(3*E*I)+W*H^4./(8*E*I)-0.10; ineq2=M*x(2)./(2*I)-165e6; %ineq3=(S./(12*I)).*(x(2).^2+x(2).*x(1)+x(1).^2)-50e6; ineq3=(a3./I).*(x(2).^2+x(2).*x(1)+x(1).^2)-50e6; ineq4= (x(2)+x(1))/(x(2)-x(1))-60; ineq5=(x(2)-x(1))/2-0.02; ineq6=-(x(2)-x(1))/2+0.005; ineq7=x(2)-0.5; ineq8=0.05-x(2); ineq9=x(1)-0.45; ineq10=0.04-x(1); % deflection % bending stress % shear stress % Mean diam./thickness % thickness< .02 m c=[ineq1;ineq2;ineq3;ineq4;ineq5;ineq6;ineq7;ineq8;ineq9;ineq10]; 9 ceq = []; The results obtained by MATLAB toolbox are x = [ 0.4018 0.4154] and f = 0.0111 where x(1) is “ do” and x(2) is “ di” 10