Exercise 4.31: Design of a cantilever beam (GP)

% Boyd & Vandenberghe "Convex Optimization"
% Almir Mutapcic - 01/30/06
% Updated to use GP mode 02/08/06
% (a figure is generated)
%
% We have a segmented cantilever beam with N segments. Each segment
% has a unit length and variable width and height (rectangular profile).
% The goal is minimize the total volume of the beam, over all segment
% widths w_i and heights h_i, subject to constraints on aspect ratios,
% maximum allowable stress in the material, vertical deflection y, etc.
%
% The problem can be posed as a geometric program (posynomial form)
%     minimize    sum( w_i* h_i)
%         s.t.    w_min <= w_i <= w_max,       for all i = 1,...,N
%                 h_min <= h_i <= h_max
%                 S_min <= h_i/w_i <= S_max
%                 6*i*F/(w_i*h_i^2) <= sigma_max
%                 6*F/(E*w_i*h_i^3) == d_i
%                 (2*i - 1)*d_i + v_(i+1) <= v_i
%                 (i - 1/3)*d_i + v_(i+1) + y_(i+1) <= y_i
%                 y_1 <= y_max
%
% with variables w_i, h_i, d_i, (i = 1,...,N) and v_i, y_i (i = 1,...,N+1).
% (Consult the book for other definitions and a recursive formulation of
% this problem.)

% optimization variables
N = 8;

% constants
wmin = .1; wmax = 100;
hmin = .1; hmax = 6;
Smin = 1/5; Smax = 5;
sigma_max = 1;
ymax = 10;
E = 1; F = 1;

cvx_begin gp
  % optimization variables
  variables w(N) h(N) v(N+1) y(N+1);

  % objective is the total volume of the beam
  % obj = sum of (widths*heights*lengths) over each section
  % (recall that the length of each segment is set to be 1)
  minimize( w'*h )
  subject to
    % non-recursive formulation
    d = 6*F*ones(N,1)./(E*ones(N,1).*w.*h.^3);
    for i = 1:N
      (2*i-1)*d(i) + v(i+1) <= v(i);
      (i-1/3)*d(i) + v(i+1) + y(i+1) <= y(i);
    end

    % constraint set
    wmin <= w; w <= wmax;
    hmin <= h; h <= hmax;
    Smin <= h./w; h./w <= Smax;
    6*F*[1:N]'./(w.*(h.^2)) <= sigma_max;
    y(1) <= ymax;
cvx_end

% display results
disp('The optimal widths and heights are: ');
w, h
fprintf(1,'The optimal minimum volume of the beam is %3.4f.\n', sum(w.*h))

% plot the 3D model of the optimal cantilever beam
figure, clf
cantilever_beam_plot([h; w])
 
Calling SeDuMi: 815 variables (32 free), 473 equality constraints
------------------------------------------------------------------------
SeDuMi 1.1 by AdvOL, 2005 and Jos F. Sturm, 1998, 2001-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
Split 32 free variables
eqs m = 473, order n = 423, dim = 1273, blocks = 32
nnz(A) = 1727 + 0, nnz(ADA) = 5697, nnz(L) = 3264
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            2.84E-001 0.000
  1 :  1.05E+001 1.11E-001 0.000 0.3897 0.9000 0.9000   2.33  1  1  2.7E+000
  2 :  9.23E+000 4.44E-002 0.000 0.4012 0.9000 0.9000   1.88  1  1  8.0E-001
  3 :  7.45E+000 1.50E-002 0.000 0.3368 0.9000 0.9000   1.44  1  1  2.3E-001
  4 :  5.98E+000 5.69E-003 0.000 0.3809 0.9000 0.9000   1.40  1  1  7.5E-002
  5 :  4.49E+000 2.06E-003 0.000 0.3619 0.9000 0.9000   1.30  1  1  2.5E-002
  6 :  4.11E+000 1.00E-003 0.000 0.4861 0.9000 0.9000   1.16  1  1  1.2E-002
  7 :  3.93E+000 4.53E-004 0.000 0.4525 0.9000 0.9000   1.12  1  1  5.1E-003
  8 :  3.82E+000 1.71E-004 0.000 0.3762 0.9000 0.9000   1.09  1  1  1.8E-003
  9 :  3.78E+000 7.41E-005 0.000 0.4348 0.9000 0.9000   1.08  1  1  7.8E-004
 10 :  3.76E+000 2.02E-005 0.000 0.2723 0.9000 0.9000   1.06  1  1  2.1E-004
 11 :  3.75E+000 5.07E-006 0.000 0.2512 0.9000 0.9000   1.04  1  1  5.0E-005
 12 :  3.75E+000 6.18E-008 0.000 0.0122 0.8658 0.9000   1.03  1  1  1.0E-005
 13 :  3.75E+000 2.06E-008 0.000 0.3340 0.9000 0.7479   1.01  1  2  3.5E-006
 14 :  3.75E+000 4.55E-009 0.000 0.2203 0.9106 0.9000   1.00  1  2  8.5E-007
 15 :  3.75E+000 1.62E-009 0.000 0.3562 0.9134 0.9000   1.00  2  2  3.3E-007
 16 :  3.75E+000 4.31E-010 0.000 0.2660 0.9000 0.9119   0.99  2  3  7.7E-008
 17 :  3.75E+000 8.22E-011 0.000 0.1907 0.9000 0.9017   1.00  2  4  1.4E-008

iter seconds digits       c*x               b*y
 17      0.3   Inf  3.7485428839e+000  3.7485429210e+000
|Ax-b| =  1.7e-007, [Ay-c]_+ =  4.6E-009, |x|= 4.0e+001, |y|= 4.7e+000

Detailed timing (sec)
   Pre          IPM          Post
0.000E+000    3.004E-001    0.000E+000    
Max-norms: ||b||=4.605170e+000, ||c|| = 2.202759e+000,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 17.8239.
------------------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +42.4592
The optimal widths and heights are: 

w =

    0.6214
    0.7830
    0.9076
    1.0142
    1.1012
    1.1773
    1.2000
    1.3333


h =

    3.1072
    3.9149
    4.5381
    5.0709
    5.5062
    5.8865
    6.0000
    6.0000

The optimal minimum volume of the beam is 42.4514.