Thursday, 13 February 2025

Optimization of Cylindrical Container Design at Minimum Material Cost

Topic: Functional Model and Graphs
Subject: Calculus
Tool: Scilab

By: Gani Comia, Feb. 2025

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.

Cylindrical Container
Volume: \(24 \pi\)  cubic inch
Cost of Material at Top and Bottom: \( \text{PHP 3.00}\) per square inch
Cost of Material at Curved Side: \( \text{PHP 2.00} \) per square inch


Figure 1. Cylindrical Container Drawing

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}$$

Where:
\(C\) – total material cost, PHP
\(C_{tb}\) – cost at top and bottom cap per unit area, PHP/sq.in.
\(A_{tb}\) – material area at top and bottom cap, sq.in.
\(C_{cs}\) – cost at the curved side per unit area, PHP/sq.in.
\(A_{cs}\) – material area at the curved side, sq.in.

$$A_{tb} = \pi r^2 , \quad C_{tb} = 3 \tag{2}$$

$$A_{cs} = 2 \pi r h , \quad C_{cs} = 2 \tag{3}$$

Where:
\(r\) – radius of the cylindrical container, in.
\(h\) – height of the cylindrical container, in.

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. 

Friday, 7 February 2025

Factor-of-Safety using Yield Stress and Maximum Shear Stress Theory

Topic: Steady Loading and Failure Theory

Subject: Machine Design

Tool: Scilab

By: Gani Comia, Feb. 2025

A static or steady load is a stationary force or moment acting on a machine or structural member. There are two approaches to calculate the margin of safety to prevent failures on the member: - factor-of-safety (\({FoS}\)) and reliability approach. These examine or compare the strength of a member and the anticipated induced stress from static loading for the selection of the optimum or suitable material and dimensions.

This article demonstrates the use of \({FoS}\) approach in verifying the suitability of a machine member for the given steady load. Figure 1 illustrates the condition in which the T-bolt made of AISI 1050 will be used as shackle pin to carry or lift a range of steady load from 500 to 2000 kg. The \(FoS\) approach can determine the maximum dead load the pin is capable of lifting steadily.

Figure 1. Shackle pin subjected to a steady loading.

Equations (1), (2), and (4) represent the basis for calculating \({FoS}\) from the given condition.

\({FoS}\) in Simple Tension, Compression, or Bending

$${FoS}_{bending}\;=\;\frac{\sigma_{yp}}{\sigma_{max}} \tag{1}$$

Where:
\({FoS}_{bending}\) – factor-of-safety in simple tension, compression, or bending
\(\sigma_{yp}\) – material’s yield point
\(\sigma_{max}\) – maximum induced stress

\({FoS}\) in Pure Shear

$${FoS}_{shear}\;=\;\frac{\tau_{yp}}{\tau_{max}} \tag{2}$$

Where:
\({FoS}_{shear}\) – factor-of-safety in pure shear
\(\tau_{yp}\) – material’s yield point in shear
\(\tau_{max}\) – maximum induced shear stress

\({FoS}\) using Max Shear Stress Theory

$$\tau_{mss}\;=\;\sqrt{\left(\frac{\sigma_{max}-\sigma_{min}}{2}\right)^2 + \tau_{max}^2} \tag{3}$$

$${FoS}_{mss}\;=\;\frac{\tau_{yp}}{\tau_{mss}} \tag{4}$$

Where:
\({FoS}_{mss}\) – factor-of-safety based on maximum shear stress theory
\(\tau_{mss}\) – induced stress using max shear stress theory
\(\sigma_{max}\) – stress due to bending at outermost surface of the shackle pin
\(\sigma_{min}\) – stress due to bending at neutral axis of the shackle pin

For steady loading, the recommended factor-of-safety is from 1.5 to 3.0 for the general engineering applications and ductile materials. The use of 1.5 as factor-of-safety will determine the maximum allowable steady load for a member. Presented below is the Scilab script for calculation documentation and validation of design in a typical engineering organizational setup.

Scilab Script

// Copyright (C) 2025 - Gani Comia
// Date of creation: 7 Feb 2025
// Shackle Pin Stress Analysis Rev 01
clear;clc;

// (1) Primary and secondary parameters.
d = 17.5;               // mm, minor dia for M20 thread
L = 42.0;               // mm, length under load
Wt = 500:10:2000;       // kg, weight of load
F = Wt.*9.8;            // N, load per pin
A = (%pi/4)*d.^2;       // mm^2, cross-sectional area at thread
S = (%pi/32)*d.^3;      // mm^3, section modulus of pin

// (2) Maximum moment and shear load.
Mmax = F.*L./4;         // N-mm, max moment load
V = F./2;               // N, max shear load

// (3) Bending and shear stress.
sigmaMax = Mmax./S;     // MPa, max bending stress
tauMax = (4/3)*V./A;    // MPa, max shear stress

// (4) Material properties, AISI 1050
sigmaYp = 375.0;        // MPa, yield point
tauYp = 0.5*sigmaYp;    // MPa, yield point in shear

// (5) Factor-of-safety (FoS), Bending and Pure Shear
FoSbending = sigmaYp./sigmaMax;     // factor-of-safety in bending
FoSshear = tauYp./tauMax;           // factor-of-safety in pure shear

// (6) Factor-of-safety (Fos), Max Shear Stress Theory
sigma1 = sigmaMax;          // MPa, max principal stress, outermost
sigma3 = 0;                 // MPa, min principla stress, neutral axis
tauMss = sqrt(((sigma1-sigma3)/2).^2 + tauMax.^2);  // MPa, MSST
FoSmsst = tauYp./tauMss;    // factor-of-safety in max shear stress

// (7) Plot of analysis
clf;
plot("ln",Wt,FoSmsst,"b-","linewidth",3);
plot("ln",Wt,FoSbending,"r--","linewidth",1.5);
plot("ln",Wt,FoSshear,"m-","linewidth",2.5);
note1 = ["Max Shear Stress","Bending Stress","Shear Stress"];
legend(note1,with_box=%F);
xgrid(3,0);
title("Shackle Pin FoS based on Failure Theory","fontsize",3.5);
xlabel("Lifting Load [kg]","fontsize",3);
ylabel("Factor of Safety","fontsize",3);

// Interpolating weight for the min factor-of-safety 1.5
format(6);
fos = 1.5;
wtInt = interp1(FoSmsst,Wt,fos);
disp(fos, wtInt);
xVerMin = [wtInt wtInt]; xHorMin = [400 wtInt];
yVerMin = [0 fos]; yHorMin = [fos fos]; 
plot(xVerMin, yVerMin,"b--");
plot(xHorMin, yHorMin,"b--");
plot(wtInt, fos,"marker","s","markerFaceColor","blue");
note2 = ["Max Load (kg) =",string(wtInt),"@ FoS =",string(fos)];
xstring(wtInt-50,fos+0.4,note2);
note3 = "https://gani-mech-toolbox.blogspot.com";
xstring(1200,11,note3);

Scilab Script Output (Figure 2)


Figure 2. Plot of Calculation of the Three Failure Theories.

The resulted plot shows that for a minimum factor-of-safety of 1.5, the shackle pin should only be loaded with not more than 1232 kg to prevent failure. 

Just like any engineering drawings to document the mechanical design, calculation in the form of scripts and notebooks are also kept for design review and future reference.

Feel free to comment for inquiry, clarification, or suggestion for improvement. Drop your email to request the soft copy of the file. 

Saturday, 25 January 2025

Simple Harmonic Motion Solution using Runge-Kutta RK4 Method

Topic: Oscillatory Motion and Numerical Solution of ODE

Subject: Physics and Numerical Methods

Tool: Scilab

By: Gani Comia, Jan. 2025

The 4th -order Runge-Kutta methods (RK4) is also used for numerical technique of approximating solution to the initial value problem (IVP) of 2nd- order ordinary differential equation (ODE). This article presents the solution to the basic equation of simple harmonic motion (SHM) using RK4 algorithm in Scilab.

SHM is a form of nonhomogeneous linear differential equation (LDE) of second-order as shown in Equation (1).

$$y''\;+\;p(t)\,y'\;+\;q(t)\,y\;=\;r(t) \tag{1}$$ 

In order to solve a given higher-order differential equation, it is required to be converted to a system of first-order differential equations as presented below.

Let us define the following dependent variables, \(y_1\) and \(y_2\):

$$y_1\;=\;y \tag{2}$$

$$y_2\;=\;y' \tag{3}$$

Then, the nonhomogeneous LDE can be re-written as a system of 1st-order ODE in Equation (4) and (5):

$$y'_1\;=\;y_2 \tag{4}$$

$$y'_2\;=\;-p(t)\,y_2\;-\;q(t)\,y_1\;+\;r(t) \tag{5}$$

With that presented, let us define and illustrate a problem using the basic equation of SHM and convert its 2nd-order ODE to a system of 1st-order to use the RK4 method in finding its approximate solution.

Figure 1. Single-Degree of Freedom (SDOF) Spring-Mass Model Oscillation Problem

The SDOF spring-mass model oscillation can be described by the basic equation of SHM shown in Equation (6).

$$m\,\frac{d^2y}{dt^2}\,+\,k\,y\,=\,0, \quad y(t_0)=y_0\;\;\text{and}\;\;y'(t_0)=y'_0 \tag{6}$$

Where:

\(m\) – mass
\(k\) – spring constant
\(t\) – time
\(t_0\) - initial time
\(y_0\) – initial displacement
\(y’_0\) – initial velocity

The solution to the ODE of SHM can be approximated using the Runge-Kutta (RK4) Method. The RK4 will be using the same algorithm presented in the previous article “First-Order IVP ODE Solution using Runge-Kutta RK4 Method” with the link shown: https://gani-mech-toolbox.blogspot.com/2025/01/first-order-ivp-ode-solution-using.html. Figure 2 shows the solution to the problem illustrated in Figure 1.

Figure 2. Solution to Spring-Mass Model System with RK4 using Scilab Script

The Scilab script to solve the given problem is presented below. Each block of the code is commented comprehensively for better understanding of the program sequence by the reader.

Scilab Script:

clear;clc;
// single-degree of freedom spring-mass model oscillator system
// m*y'' + k*y = 0  or  y'' + (k/m)*y = 0
// nonhomogeneous linear differential equation (LDE) of second-order
// y'' + p(t)y' + q(t)y = g(t) 
// where: p(t)=0; q(t)=k/m; g(t)=0

// (1) 2nd-order LDE re-written in the system of 1st-order ODEs
function dydt=f(t, y)
    m = 1;                  // kg, mass of the object
    k = 20;                 // N/m, spring constant
    p = 0;                  // coefficient of y'
    q = k/m;                // coefficient of y
    g = 0;                  // forcing function
    dydt = [y(2); -p*y(2) - q*y(1) + g];
endfunction

As you may compare the \(rk4\) function in block (2) to the previous article, the final time, \(t_f\), is used as one of the input arguments instead of the number of intervals, \(n\). Both \(rk4\) functions can be used to come up with the same solution.

// (2) RK4 function or algorithm for 1st-order ODEs
function [t, y]=rk4(f, t0, y0, h, tf)
    n = round((tf - t0)./h);
    t(1) = t0;          // initial time, t0
    y(:, 1) = y0;       // y(t0)=y0 & y'(t0)=y0' in column vector

    for i = 1:n
        // approximate values of slopes of solution curves
        k1 = h * f(t(i), y(:, i));
        k2 = h * f(t(i) + h / 2, y(:, i) + k1 / 2);
        k3 = h * f(t(i) + h / 2, y(:, i) + k2 / 2);
        k4 = h * f(t(i) + h, y(:, i) + k3);
        // estimates of numerical solution
        y(:, i + 1) = y(:, i) + (k1 + 2 * k2 + 2 * k3 + k4) / 6;
        t(i+1) = t(i) + h;
    end
endfunction

// (3) initial conditions and parameters
t0 = 0;             // sec, initial time
tf = 5;             // sec, final time
h = 0.01;           // sec, time step size
y0 = [0.05; 0];     // initial disp & velocity: y(0)=0.05, y'(0)=0

// (4) solution to the ODE by calling RK4 defined function
[t, y] = rk4(f, t0, y0, h, tf);

// (5) solution plot
clf;
plot(t, y(1, :),"b-","linewidth",4);       // displacement plot
plot(t, y(2, :),"r--","linewidth",1.8);    // velocity plot
xlabel("$\Large t \quad \text{(time)}$");
ylabel("$\Large y(t)\;\;\text{or}\;\;\frac{dy(t)}{dt}$");
note1 = "Spring-Mass Model System using Runge-Kutta RK4";
title(note1,"fontsize",3.5);
note2 = ["$\Large y(t)$","$\Large \frac{dy(t)}{dy}$"];
legend(note2, with_box = %F);
note3 = "https://gani-mech-toolbox.blogspot.com"
xstring(0.1,0.35,note3);
xgrid(3,1);

// (6) other plot information
disp(max(y(1,:)), min(y(1,:)))
disp(max(y(2,:)), min(y(2,:)))
ax = gca();
ax.data_bounds = [0 -0.4; 5 0.4];

// (7) natural frequency
format(5);
k = 20;                     // N/m, spring constant
m = 1;                      // kg, mass of object
omega = sqrt(k/m);          // Hz, natural frequency
disp(omega);
note4 = ["$\LARGE\mathbf{\omega_n}\;=\;\text{4.5 Hz}$"];
xstring(0.1,0.25,note4)

The Scilab script in this article can be one of your references to solve any engineering problems that can be described by the nonhomogeneous linear differential equation (LDE) of second-order.

Feel free to comment for inquiry, clarification, or suggestion for improvement. Drop your email to request the soft copy of the file.

A Shooting Method Approach to Boundary-Value ODEs

Topic: Differential Equations Boundary-Value Problems Subject: Numerical Methods Tool: Scilab By: Gani Comia, July 2025 The Shooting Me...