Challenge

FINAL INDEPENDENT PROJECT (MATLAB for Mechanical engineers)

***********File (strain stress 1018 steel) containing the data************************

https://drive.google.com/file/d/148-2Zb6M7QydCShOZPVBSemSmFyrEr4j/view?usp=sharing

**************************************************************************

AIM: To write a code in MATLAB to fit cubic and quartic polynomial for tensile strain, stress data (experimental) of 1018 steel using MATLAB.

OBJECTIVES:

  1. To plot the cubic and quartic fit curves along with the raw data points.
  2. To explain the parameters used to measure the fitness characteristics for both the curve fits.
  3. To find the Young’s modulus, yield point and the ultimate tensile strength of 1018 steel from the original curve.
  4. To write a code showing the split-wise method.

THEORY:

  1. Parameters used to measure the fitness characteristics for both the curves:

*R-square

This quantity measures how successful the fit is in explaining the variation of the data. It is also called the square of the multiple co-relation coefficient and the coefficient of multiple determination. R- square is 0 (min) for the worst possible fit for the data set. R-square is 1 (max) for the best possible fit for the data set. If R-square is greater than 0.95, the fit is assumed to be good.

Sum of squared errors (SSE): It is the summation of squares all errors. Error is the difference between predicted value and the original value.

Sum of squares of regression (SSR): It is basically the square of the difference between the value of the fitting function at a given point and the arithmetic mean of the data set.

SST: Summation of SSR and SSE.

*Root mean squared error (RMSE)

This statistic is also known as the fit standard error and the standard error of the regression. It is an estimate of the standard deviation of the random component in the data, and is defined as,

2. How to calculate the Young's modulus, the Yield point and the Ultimate tensile strength from the original dataset.

To calculate the Young's modulus, we have to find the slope of the original stress-strain curve (before the proportional limit).

Yield point is the point above the proportional limit in the original stress-strain curve.

Ultimate tensile strength is the maximum value of stress in the original stress-strain curve.

CODE:

Main code:

clear all
close all
clc

% reading the file 'strain stress data 1018 steel' and taking the inputs
stressdata=load('strain stress 1018 steel') ;          %loading the particular file
strain=stressdata(:,1);                                %storing the values of strain   
stress=stressdata(:,2);                                %storing the values of stress

%curve fitting for a cubic polynomial 
coeff=polyfit(strain,stress,3);                        %coefficients of the polynomial are generated using polyfit() command
predictedstress=polyval(coeff,strain);                 %predicted values of stress are generated using polyval() command

%compare my cubic curve fit with original dataset
figure(1)
plot(strain,stress,'linewidth',3,'color','b')          %plotting of original data set
hold on
plot(strain,predictedstress,'linewidth',3,'color','r') %plotting of cubic curve fit
xlabel('Strain')
ylabel('Stress[MPa]')
legend('original dataset','my curvefit')
title('curve fit for a cubic polynomial')
hold off

%checking error for cubic curve fit
disp('For the cubic curve fit, we have found :')
fitness_characteristics(stress,predictedstress)        %calling the user-defined function fitness_characteristics() to find the goodness of curve fit

%curve fitting for a quartic polynomial
coeff=polyfit(strain,stress,4);                        %coefficients of the quartic polynomial are generated using polyfit() command
predictedstress=polyval(coeff,strain);                 %predicted values of stress are generated using polyval() command

%compare my quartic curve fit with original dataset
figure(2)
plot(strain,stress,'linewidth',3,'color','b')          %plotting of original data set
hold on
plot(strain,predictedstress,'linewidth',3,'color','r') %plotting of curve fit
xlabel('Strain')
ylabel('Stress[MPa]')
legend('original dataset','my curvefit')
title('curve fit for a quartic polynomial')
hold off

%checking error for quartic curve fit
disp('For the quartic curve fit, we have found :')
fitness_characteristics(stress,predictedstress)        %calling the user-defined function fitness_characteristics() to find the goodness of curve fit

%finding the Young's modulus, the yield point and the ultimate tensile
%strength from the original stress-strain curve
Ultimate_tensile_strength_MPa = max(stress)
Youngs_modulus_MPa = (295-196)/(0.002-0.0015)
Yield_point_MPa = 330

Function:

function [f]= fitness_characteristics(stress,predictedstress)
meancp=mean(stress);
ssr=0;
sse=0;
for i=1:length(stress)
    sse=sse+(stress(i)-predictedstress(i))^2;
end
for i=1:length(stress)
    ssr=ssr+(meancp-predictedstress(i))^2;
end
sst=sse+ssr;
Rsquare=ssr/sst
rmse=(sse/length(stress))^0.5
if (Rsquare>0.95)
    disp('The fit is GOOD because Rsquare > 0.95')
else disp('The fit is NOT GOOD because Rsquare <= 0.95')
end
    

OUTPUT:

EXPLANATION OF THE CODE AND THE OUTPUT:

In the main code, I first opened the file ‘strain stress 1018 steel’ using the load() command.Then, I stored the values of strain and stress. Then, I did the curve fitting for cubic polynomial where I used the polyfit() and polyval() command for finding the coefficients and predicted value of stress respectively. I compared my cubic curve fit with the original dataset. I used the user defined function fitness_characteristics() to find the goodness of the fit. I used the similar process for doing the curve fitting for quartic polynomial. Then, with the help of original stress-strain curve, I found Ultimate tensile strength(MPa), Young’s modulus(MPa) and Yield strength(MPa).

In the user defined function fitness_characteristics(), I first calculated the value of ssr, sse and sst. Then I calculated the value of Rsquare and rmse. If the value of Rsquare > 0.95 then the fit is good otherwise the fit is not good. Depending on this, I displayed whether the fit is good or not.

In the output, I showed the two plots – cubic polynomial fit and quartic polynomial fit. I also showed the values of Rsquare and rmse for each fit.

ERROR:

No major error was displayed.

SPLIT-WISE METHOD (improving the quartic polynomial fit):

Main code:

clear all
close all
clc

% reading the file 'strain stress 1018 steel' and taking the inputs
stressdata=load('strain stress 1018 steel');             %loading the particular file
strain=stressdata(:,1);                                  %storing the values of strain                                
stress=stressdata(:,2);                                  %storing the values of stress

%splitting the data in four parts
strain1=stressdata(1:15,1);
stress1=stressdata(1:15,2);

strain2=stressdata(16:30,1);
stress2=stressdata(16:30,2);

strain3=stressdata(31:45,1);
stress3=stressdata(31:45,2);

strain4=stressdata(46:53,1);
stress4=stressdata(46:53,2);

%curve fitting for a quartic polynomial
coeff1=polyfit(strain1,stress1,4);                        %coefficients of the polynomial are generated using polyfit() command
predictedstress1=polyval(coeff1,strain1);                 %predicted values stress are generated using polyval() command

coeff2=polyfit(strain2,stress2,4);                        %coefficients of the polynomial are generated using polyfit() command
predictedstress2=polyval(coeff2,strain2);                 %predicted values stress are generated using polyval() command

coeff3=polyfit(strain3,stress3,4);                        %coefficients of the polynomial are generated using polyfit() command
predictedstress3=polyval(coeff3,strain3);                 %predicted values stress are generated using polyval() command

coeff4=polyfit(strain4,stress4,4);                        %coefficients of the polynomial are generated using polyfit() command
predictedstress4=polyval(coeff4,strain4);                 %predicted values stress are generated using polyval() command 

%compare my quartic curve fit with original dataset
plot(strain,stress,'linewidth',3,'color','b')             %plotting of original data set
hold on
plot(strain1,predictedstress1,'linewidth',3,'color','r')  %plotting of curve fit
plot(strain2,predictedstress2,'linewidth',3,'color','r')
plot(strain3,predictedstress3,'linewidth',3,'color','r')
plot(strain4,predictedstress4,'linewidth',3,'color','r')
xlabel('strain')
ylabel('stress[MPa]')
legend('original dataset','splitwise curvefit')
title('curve fit (split-wise) for a quartic polynomial')
hold off

predictedstress(1:15)=predictedstress1;
predictedstress(16:30)=predictedstress2;
predictedstress(31:45)=predictedstress3;
predictedstress(46:53)=predictedstress4;

%checking error for quartic curve fit
disp('For the quartic curve fit, we have found :')
fitness_characteristics(stress,predictedstress)                          %calling the user-defined function fitness_characteristics() to find the goodness of curve fit

Function:

function [f]= fitness_characteristics(stress,predictedstress)
meancp=mean(stress);
ssr=0;
sse=0;
for i=1:length(stress)
    sse=sse+(stress(i)-predictedstress(i))^2;
end
for i=1:length(stress)
    ssr=ssr+(meancp-predictedstress(i))^2;
end
sst=sse+ssr;
Rsquare=ssr/sst
rmse=(sse/length(stress))^0.5
if (Rsquare>0.95)
    disp('The fit is GOOD because Rsquare > 0.95')
else disp('The fit is NOT GOOD because Rsquare <= 0.95')
end
    

Output:

RESULT: A code in MATLAB to fit cubic and quartic polynomial for tensile strain, stress data (experimental) of 1018 steel using MATLAB is created.

REFERENCE:

https://projects.skill-lync.com/projects/Curve-Fitting-and-criterion-to-choose-best-fit-41860

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.