Appendix A. Analytical Calculations for Workpiece Material K1045 Using Excel
Figure A1.
Analytical calculations for workpiece material K1045 using Excel.
Figure A1.
Analytical calculations for workpiece material K1045 using Excel.
Appendix B. Analytical Calculations for Workpiece Material Mild Steel Using Excel
Figure A2.
Analytical calculations for workpiece material Mild Steel using Excel.
Figure A2.
Analytical calculations for workpiece material Mild Steel using Excel.
Appendix C. MATLAB Calculations for Workpiece Material K1045
clear all;
% Given data
T = [1.7155, 1.69433, 0.70466, 1.3285, 0.6535, 1.32, 0.901833, 2.80075]′;
he = [0.029180642, 0.029180642, 0.029180642, 0.030567975, 0.031797251, 0.0175152, 0.023349056, 0.0175152]′;
Vc = [200, 300, 400, 300, 300, 300, 300, 200]′;
% Calculate required logarithmic and transformed terms
ln_Vc = log(Vc);
ln_he = log(he);
ln_T = log(T);
% First Phase: Optimize K, H, M, No, and L
% Define the objective function for the first run
objFun1 = @(params, x) params(1) − ((x(:,2)-params(2)).^2)/(4*params(3)) − (params(4) − params(5)*x(:,2)).*x(:,1);
% Initial guesses for the first run
initial_guess1 = [6.192, −2.921, 1.404, 0.1, 0.1];
% Bounds for the parameters for the first run
lb1 = [−Inf, −5, 0.2, −0.2, 0.1];
ub1 = [Inf, −2, 9.9999, 0, 0.6];
% Create the input matrix for the first run
X1 = [ln_T, ln_he];
% Perform the constrained fitting for the first run
options = optimoptions(‘lsqcurvefit’, ‘Display’, ‘off’);
params1 = lsqcurvefit(@(params, x) exp(objFun1(params, x)), initial_guess1, X1, Vc, lb1, ub1, options);
% Extract the coefficients from the first run
K1 = params1(1);
H1 = params1(2);
M1 = params1(3);
No1 = params1(4);
L1 = params1(5);
% Display the results from the first run
fprintf(‘Results from the first run:\n’);
fprintf(‘K = %.6f\n’, K1);
fprintf(‘H = %.6f\n’, H1);
fprintf(‘M = %.6f\n’, M1);
fprintf(‘No = %.6f\n’, No1);
fprintf(‘L = %.6f\n’, L1);
% Calculate predicted ln(Vc) using the optimized parameters from the first phase
predicted_Vc1 = exp(objFun1(params1, X1));
% Calculate error percentage for each Vc
error_percentage1 = abs((Vc − predicted_Vc1) ./Vc) * 100;
% Display error percentages
fprintf(‘\nError percentages for each Vc (first run):\n’);
for i = 1:length(Vc)
fprintf(‘Vc = %d: Error = %.2f%%\n’, Vc(i), error_percentage1(i));
end
% Display the predicted Vc for given T values
fprintf(‘\nPredicted Vc values for given T (first run):\n’);
for i = 1:length(T)
fprintf(‘T = %.8f: Vc = %.2f\n’, T(i), predicted_Vc1(i));
end
% Second Phase: Refine fitting using the same initial guess and bounds
% Perform the constrained fitting for the second run
params2 = lsqcurvefit(@(params, x) exp(objFun1(params, x)), params1, X1, Vc, lb1, ub1, options);
% Extract the coefficients from the second run
K2 = params2(1);
H2 = params2(2);
M2 = params2(3);
No2 = params2(4);
L2 = params2(5);
% Display the results from the second run
fprintf(‘\nResults from the second run:\n’);
fprintf(‘K = %.6f\n’, K2);
fprintf(‘H = %.6f\n’, H2);
fprintf(‘M = %.6f\n’, M2);
fprintf(‘No = %.6f\n’, No2);
fprintf(‘L = %.6f\n’, L2);
% Calculate predicted ln(Vc) using the optimized parameters from the second phase
predicted_Vc2 = exp(objFun1(params2, X1));
% Calculate error percentage for each Vc
error_percentage2 = abs((Vc − predicted_Vc2) ./Vc) * 100;
% Display error percentages
fprintf(‘\nError percentages for each Vc (second run):\n’);
for i = 1:length(Vc)
fprintf(‘Vc = %d: Error = %.2f%%\n’, Vc(i), error_percentage2(i));
end
% Display the predicted Vc for given T values
fprintf(‘\nPredicted Vc values for given T (second run):\n’);
for i = 1:length(T)
fprintf(‘T = %.8f: Vc = %.2f\n’, T(i), predicted_Vc2(i));
end
Appendix D. MATLAB Calculations for Workpiece Material Mild Steel
clear all;
% Given data
T = [2.830333333, 0.785, 1.0167, 1.452, 0.796, 1.32, 0.82625, 2.0025]′;
he = [0.029180642, 0.029180642, 0.029180642, 0.030567975, 0.031797251, 0.0175152, 0.023349056, 0.0175152]′;
Vc = [200, 300, 400, 300, 300, 300, 300, 200]′;
% Calculate required logarithmic and transformed terms
ln_Vc = log(Vc);
ln_he = log(he);
ln_T = log(T);
% First Phase: Optimize K, H, M, No, and L
% Define the objective function for the first run
objFun1 = @(params, x) params(1) − ((x(:,2)-params(2)).^2)/(4*params(3)) − (params(4) − params(5)*x(:,2)).*x(:,1);
% Initial guesses for the first run
initial_guess1 = [6.192, −2.921, 1.404, 0.1, 0.1];
% Bounds for the parameters for the first run
lb1 = [−Inf, −5, 0.2, −0.2, 0.1];
ub1 = [Inf, −2, 9.9999, 0, 0.6];
% Create the input matrix for the first run
X1 = [ln_T, ln_he];
% Perform the constrained fitting for the first run
options = optimoptions(‘lsqcurvefit’, ‘Display’, ‘off’);
params1 = lsqcurvefit(@(params, x) exp(objFun1(params, x)), initial_guess1, X1, Vc, lb1, ub1, options);
% Extract the coefficients from the first run
K1 = params1(1);
H1 = params1(2);
M1 = params1(3);
No1 = params1(4);
L1 = params1(5);
% Display the results from the first run
fprintf(‘Results from the first run:\n’);
fprintf(‘K = %.6f\n’, K1);
fprintf(‘H = %.6f\n’, H1);
fprintf(‘M = %.6f\n’, M1);
fprintf(‘No = %.6f\n’, No1);
fprintf(‘L = %.6f\n’, L1);
% Calculate predicted ln(Vc) using the optimized parameters from the first phase
predicted_Vc1 = exp(objFun1(params1, X1));
% Calculate error percentage for each Vc
error_percentage1 = abs((Vc − predicted_Vc1) ./Vc) * 100;
% Display error percentages
fprintf(‘\nError percentages for each Vc (first run):\n’);
for i = 1:length(Vc)
fprintf(‘Vc = %d: Error = %.2f%%\n’, Vc(i), error_percentage1(i));
end
% Display the predicted Vc for given T values
fprintf(‘\nPredicted Vc values for given T (first run):\n’);
for i = 1:length(T)
fprintf(‘T = %.8f: Vc = %.2f\n’, T(i), predicted_Vc1(i));
end
% Second Phase: Refine fitting using the same initial guess and bounds
% Perform the constrained fitting for the second run
params2 = lsqcurvefit(@(params, x) exp(objFun1(params, x)), params1, X1, Vc, lb1, ub1, options);
% Extract the coefficients from the second run
K2 = params2(1);
H2 = params2(2);
M2 = params2(3);
No2 = params2(4);
L2 = params2(5);
% Display the results from the second run
fprintf(‘\nResults from the second run:\n’);
fprintf(‘K = %.6f\n’, K2);
fprintf(‘H = %.6f\n’, H2);
fprintf(‘M = %.6f\n’, M2);
fprintf(‘No = %.6f\n’, No2);
fprintf(‘L = %.6f\n’, L2);
% Calculate predicted ln(Vc) using the optimized parameters from the second phase
predicted_Vc2 = exp(objFun1(params2, X1));
% Calculate error percentage for each Vc
error_percentage2 = abs((Vc − predicted_Vc2) ./Vc) * 100;
% Display error percentages
fprintf(‘\nError percentages for each Vc (second run):\n’);
for i = 1:length(Vc)
fprintf(‘Vc = %d: Error = %.2f%%\n’, Vc(i), error_percentage2(i));
end
% Display the predicted Vc for given T values
fprintf(‘\nPredicted Vc values for given T (second run):\n’);
for i = 1:length(T)
fprintf(‘T = %.8f: Vc = %.2f\n’, T(i), predicted_Vc2(i));
end
Appendix E. Python Calculations for Workpiece Material K1045
import numpy as np
from scipy.optimize import least_squares
import matplotlib.pyplot as plt
# Given data
T = np.array([1.7155, 1.69433, 0.70466, 1.3285, 0.6535, 1.32, 0.901833, 2.80075])
he = np.array([0.0292, 0.029180642, 0.029180642, 0.030567975, 0.031797251, 0.0175152, 0.023349056, 0.0175152])
Vc = np.array([200, 300, 400, 300, 300, 300, 300, 200])
# Transform the data
ln_T = np.log(T)
ln_he = np.log(he)
# Define the objective function
def objective_function(params, ln_T, ln_he, Vc):
K, H, M, No, L = params
predicted_Vc = np.exp(K − (H**2)/(4 * M) − (ln_he**2)/(4 * M) + (2 * H * ln_he)/(4 * M) − No * ln_T + L * ln_he * ln_T)
return predicted_Vc − Vc
#%%
# Initial guess for parameters
initial_guess = [1, −3, 1, 0, 0.3]
# Define bounds for the parameters
# Lower bounds: [K_min, H_min, M_min, No_min, L_min]
# Upper bounds: [K_max, H_max, M_max, No_max, L_max]
bounds = ([−np.inf, −5, 0.2, −0.2, 0.1], [np.inf, −2, 9.9999, 0, 0.6])
#%%
# Perform the fitting
result = least_squares(objective_function, initial_guess, args = (ln_T, ln_he, Vc), bounds = bounds)
# Extract optimized parameters
K, H, M, No, L = result.x
# Display results
print(f‘Results from the fitting:’)
print(f‘K = {K:.6f}
’)
print(f‘H = {H:.6f}’)
print(f‘M = {M:.6f}’)
print(f‘No = {No:.6f}’)
print(f‘L = {L:.6f}’)
#%%
# Calculate predicted Vc using the optimized parameters
predicted_Vc = np.exp(K − (H**2)/(4 * M) − (ln_he**2)/(4 * M) + (2 * H * ln_he)/(4 * M) − No * ln_T + L * ln_he * ln_T)
# Calculate and display error percentages
error_percentage = np.abs((Vc − predicted_Vc)/Vc) * 100
print(‘\nError percentages for each Vc:’)
for i in range(len(Vc)):
print(f’Vc = {Vc[i]}: Error = {error_percentage[i]:.2f}%’)
Appendix F. Python Calculations for Workpiece Material Mild Steel
import numpy as np
from scipy.optimize import least_squares
import matplotlib.pyplot as plt
# Given data
T = np.array([2.830333333, 0.785, 1.452, 0.796, 1.32, 0.82625, 2.0025])
he = np.array([0.029180642, 0.029180642, 0.030567975, 0.031797251, 0.0175152, 0.023349056, 0.0175152])
Vc = np.array([200, 300, 300, 300, 300, 300, 250])
# Transform the data
ln_T = np.log(T)
ln_he = np.log(he)
# Define the objective function
def objective_function(params, ln_T, ln_he, Vc):
K, H, M, No, L = params
predicted_Vc = np.exp(K − (H**2)/(4 * M) − (ln_he**2)/(4 * M) + (2 * H * ln_he)/(4 * M) − No * ln_T + L * ln_he * ln_T)
return predicted_Vc − Vc
# Define the bounds for the parameters
bounds = ([−np.inf, −5, 0.2, −0.2, 0.1], [np.inf, −2, 9.9999, 0, 0.6])
# Generate a refined grid of initial guesses
K_range = np.linspace(−5, 5, 10)
H_range = np.linspace(−5, −2, 10)
M_range = np.linspace(0.2, 9.9999, 10)
No_range = np.linspace(−0.2, 0, 10)
L_range = np.linspace(0.1, 0.6, 10)
#%%
# Initialize lists to store results
initial_guesses = []
results = []
residuals = []
# Iterate through refined combinations of initial guesses
for K in K_range:
for H in H_range:
for M in M_range:
for No in No_range:
for L in L_range:
guess = [K, H, M, No, L]
result = least_squares(objective_function, guess, args = (ln_T, ln_he, Vc), bounds = bounds)
residual = np.sum(result.fun**2)
# Store the initial guess, result, and residual
initial_guesses.append(guess)
results.append(result)
residuals.append(residual)
# Find the index of the best result
best_index = np.argmin(residuals)
best_result = results[best_index]
best_guess = initial_guesses[best_index]
best_residual = residuals[best_index]
# Extract optimized parameters from the best result
K_opt, H_opt, M_opt, No_opt, L_opt = best_result.x
# Display results
print(f‘Best Initial Guess: {best_guess}’)
print(f‘Optimized Parameters:’)
print(f‘K = {K_opt:.6f}’)
print(f‘H = {H_opt:.6f}’)
print(f‘M = {M_opt:.6f}’)
print(f‘No = {No_opt:.6f}’)
print(f‘L = {L_opt:.6f}’)
#%%
# Calculate predicted Vc using the optimized parameters
predicted_Vc = np.exp(K_opt − (H_opt**2)/(4 * M_opt) − (ln_he**2)/(4 * M_opt) + (2 * H_opt * ln_he)/(4 * M_opt) − No_opt * ln_T + L_opt * ln_he * ln_T)
# Calculate and display error percentages
error_percentage = np.abs((Vc − predicted_Vc)/Vc) * 100
print(‘\nError percentages for each Vc:’)
for i in range(len(Vc)):
print(f‘Vc = {Vc[i]}: Error = {error_percentage[i]:.2f}%’)