%Solution for problem 22 on page 129
r = [2:0.1:10];  % create r vector, within 2 and 10 with step 0.1

%capacity is fixed 500
capacity = 500;

%capacity = 2*pi*r^3/3 + pi*r^2*h
%so, 
h = (capacity - 2*pi*r.^3/3) ./ (pi*r.^2);

%now we calculate cost
cost_clylind = 2*pi*r.*h*300;
cost_top = 2*pi*r.^2*400;
cost = cost_clylind + cost_top;

%remember cost, as well as r and h, is a vector
%now we find the min cost
%as before, x is the min cost and k is the index
[x, k] = min(cost);

%prepare the final result
%format: h, r, min_cost
T = [h(k), r(k), cost(k)]

