Y= β0 + β1X1 +β2X2 +...+ βnXn + ε
where:
Y = Dependent variable (target)
X1, X2, ...,Xn = Independent variables (features, inputs)
β0 = Intercept
β1, β2,...,βn = Regression coefficients
ε = Error
It can assume that Yield strength depends on the alloy composition, heat treatment, and grain size. A simple linear regression model can be:
YS = b0 + b1(Carbon Content) + b2(Grain Size) + b3(Temperature)
Example Equation (Hypothetical Data):
YS = 250 + 150C − 20D + 0.5T
Where:
C = Carbon content (%)
D = Average grain diameter (µm)
T = Heat treatment temperature (°C)
Interpretation:
Adding 1% carbon increases yield strength by 150 MPa.
Increasing grain size by 1 µm reduces yield strength by 20 MPa (Hall-Petch effect).
Raising the heat treatment temperature by 1°C increases yield strength by 0.5 MPa.
% Sample Training Data
Carbon = [0.1; 0.2; 0.3; 0.4; 0.5]; % Carbon content (%)
GrainSize = [50; 40; 30; 20; 10]; % Grain size (µm)
Temperature = [600; 650; 700; 750; 800]; % Heat treatment temperature (°C)
YieldStrength = [250; 270; 290; 310; 330]; % Yield Strength (MPa)
% Independent variable matrix
X = [Carbon, GrainSize, Temperature]
% Train the linear model
mdl = fitlm(X, YieldStrength)
% New input data
newData = [0.35, 25, 720]; % Carbon, GrainSize, Temperature
% Predict Yield Strength
predicted_YS = predict(mdl, newData)
disp("Predicted Yield Strength: " + predicted_YS + " MPa")
predictedValues = predict(mdl, X);
figure;
scatter(YieldStrength, predictedValues, 'filled')
xlabel('Actual Values')
ylabel('Predicted Values')
title('Regression Model Performance')
grid on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Results
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X =
0.1000 50.0000 600.0000
0.2000 40.0000 650.0000
0.3000 30.0000 700.0000
0.4000 20.0000 750.0000
0.5000 10.0000 800.0000
mdl =
Linear regression model:
y ~ 1 + x1 + x2 + x3
Estimated Coefficients:
Estimate SE tStat pValue
________ __________ _________ __________
(Intercept) 0 0 NaN NaN
x1 0 0 NaN NaN
x2 0.058824 2.3059e-07 2.551e+05 2.4956e-06
x3 0.41176 1.087e-08 3.788e+07 1.6806e-08
Number of observations: 5, Error degrees of freedom: 3
Root Mean Squared Error: 8.81e-06
R-squared: 1, Adjusted R-Squared: 1
F-statistic vs. constant model: 3.09e+29, p-value = 1.28e-44
predicted_YS =
297.9412
Predicted Yield Strength: 297.9412 MPa
CR = b0 + b1C + b2T + b3pH
Where:
C = Chloride concentration (ppm)
T = Temperature (°C)
pH = Acidity of the solution
Train the Model
% Sample Training Data
Chloride = [100; 200; 300; 400; 500]; % ppm
Temperature = [20; 30; 40; 50; 60]; % °C
pH = [3; 4; 5; 6; 7]; % pH level
CorrosionRate = [0.1; 0.15; 0.2; 0.28; 0.35]; % mm/year
% Independent variables
X = [Chloride, Temperature, pH];
% Train model
mdl = fitlm(X, CorrosionRate);
Predict corrosion rate for:
Chloride = 350 ppm
Temperature = 45°C
pH = 5.5
New input data
newData = [350, 45, 5.5];
% Predict corrosion rate
predicted_CR = predict(mdl, newData);
disp("Predicted Corrosion Rate: " + predicted_CR + " mm/year")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Results
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X =
100 20 3
200 30 4
300 40 5
400 50 6
500 60 7
mdl =
Linear regression model:
y ~ 1 + x1 + x2 + x3
Estimated Coefficients:
Estimate SE tStat pValue
________ __________ ______ _______
(Intercept) 0 0 NaN NaN
x1 0.00036 0.00016062 2.2413 0.26717
x2 0.0027 0.0012557 2.1503 0.27712
x3 0 0 NaN NaN
Number of observations: 5, Error degrees of freedom: 3
Root Mean Squared Error: 0.012
R-squared: 0.989, Adjusted R-Squared: 0.986
F-statistic vs. constant model: 277, p-value = 0.000472
newData = 350.0000 45.0000 5.5000
predicted_CR = 0.2475
Predicted Corrosion Rate: 0.2475 mm/year