Topic: Functional Model and Graphs
Subject: Calculus
Tool: Scilab
This article demonstrates the use of Scilab in solving a simple optimization problem for the calculation of a cylindrical container’s radius, \( \mathbf{r} \), and height, \( \mathbf{h} \), at the minimum material cost. Let us illustrate an example problem with the following given values and figures.
For optimal cost, there is a size of cylindrical container in terms of the combination of radius and height that will bring the material cost at a minimum. This problem needs a derivation of the function model for the material cost in terms of radius. The total material cost in making the container can be expressed in Equation (1).
$$C = 2 C_{tb} A_{tb} + C_{cs} A_{cs} \tag{1}$$
$$A_{tb} = \pi r^2 , \quad C_{tb} = 3 \tag{2}$$
$$A_{cs} = 2 \pi r h , \quad C_{cs} = 2 \tag{3}$$
Substituting Equations (2) and (3) to (1),
$$C = 2(3)(\pi r^2) + 2(2\pi r h) \tag{4}$$
$$C = 6 \pi r^2 + 4 \pi r h \tag{5}$$
The above cost function should be expressed using one independent variable, as in this case radius, \(r\). For the given volume, \(V\), we can find the relationship between \(r\) and \(h\).
$$V = \pi r^2 h \tag{6}$$
$$24 \pi = \pi r^2 h \quad \text{or} \quad h = \frac{24}{r^2} \tag{7}$$
By substituting \(h\) from Equation (7) to (5), the total material cost \(C\) can be rewritten in Equation (8).
$$C(r) = 6 \pi r^2 + \frac{96 \pi}{r} \tag{8}$$
Equation (8) can be the functional model to determine the value of radius, \(r\), for the minimum material cost, \(C(r)\). The solution can be found with the use of Scilab functions of finding the minimum value of the cost, \( \mathbf{min()}\), and \( \mathbf{interp1()}\), to find the radius using interpolation.
Scilab Script
// Copyright (C) 2025 - Gani Comia // Date of creation: 13 Feb 2025 // Cylindrical Container Design at Minimum Material Cost clear;clc; // (1) derived functional model function C=f(r) C = 6*%pi.*r.^2 + 96*%pi./r; endfunction // (2) domain and range of the function r = 0.5:0.1:4; C = f(r); // (3) plot of the function clf; plot(r,C,"linewidth",3); note1 = "Material Cost for Cylindrical Container Design"; title(note1,"fontsize",3.5); xlabel("Radius [inch]","fontsize",3.5); ylabel("Material Cost [PHP]", "fontsize",3.5); xgrid(3,0); legend("$\LARGE C(r)=6\,\pi\,r^2\;+\;\frac{96\,\pi}{r}$",with_box=%F); xstring(2.4,550,"https://gani-mech-toolbox.blogspot.com"); // (4) interpolated value of radius and minimum cost cost = min(C); disp(cost); radius = interp1(C,r,cost); disp(radius); xVer = [radius radius]; yVer = [150 cost]; plot(xVer,yVer,"r--","linewidth",1.75); xHor = [0.5 radius]; yHor = [cost cost] plot(xHor,yHor,"r--","linewidth",1.85); plot(radius,cost,"marker","s","markerFaceColor","blue"); format(7); note2 = ["Min Cost (PHP):", string(cost); "Radius (in.): ", string(radius)]; xstring(radius-0.1,cost+20,note2);
Scilab Output (Figure 2)
Figure 2. Plot of Material Cost Function for Cylindrical Container
After solving the radius, \(r\), the height, \(h\), of the cylindrical container can be computed using Equation (7). The solution is shown in Equation (9).
$$h = \frac{24}{r^2} = \frac{24}{2^2} = 6 \; \text{in.} \tag{9}$$
An alternative method to solve for the minimum, \(r\), is by derivation of the cost function, \(C(r)\), and setting its derivative to zero to solve for \(r\).
Feel free to comment for inquiry, clarification, or suggestion for improvement. Drop your email to request the soft copy of the file.