code no good :(

4 views (last 30 days)
Hussein Altameemi
Hussein Altameemi on 26 Sep 2022
Edited: Jan on 26 Sep 2022
im getting :
Error in draft1 (line 45)
areaReduction(i) = areaOriginal-(E1(i)*E2(i)); % Make Plot for Report notate initiation of necking
clc,clear all
%% Load Data - Initilize Variables
DP980TD_S2 = xlsread('DP980TD-S2.xlsx'); % Data File
% Constants
widthOriginal = DP980TD_S2(1,2); % Original gauge width (mm)
thicknessOriginal = DP980TD_S2(2,2); % Original gauge thickness (mm)
lengthOriginal = DP980TD_S2(3,2); % Original gauge length (mm)
widthFinal = DP980TD_S2(4,2); % Final gauge width at fracture (mm)
thicknessFinal = DP980TD_S2(5,2); %final gauge thickness at fracture (mm)
% Arrays
force = DP980TD_S2([14:end],1).';
disp = DP980TD_S2([14:end],2).';
E1 = DP980TD_S2([14:end],3).';
E2 = DP980TD_S2([14:end],4).';
% Area
areaOriginal = area(widthOriginal,thicknessOriginal);
areaNeck = area(widthFinal,thicknessFinal);
%#######################################################################
%% Area of Reduction
areaInstant = [];
for i = 1:length(E1)
areaReduction(i) = areaOriginal-(E1(i)*E2(i)); % Make Plot for Report notate initiation of necking
areaInstant(i) = areaOriginal*exp(-E1(i));
end
%#####################################################################
%% Onset of necking Calculation: Stress and Strain at UTS; Uniform Elongation
uniformElongation = 0;% percent
UTSIndex = 0;
strainUTS = 0;
for i = 1:length(force)
if force(i) == max(force) % index UTS
uniformElongation = (disp(i) / lengthOriginal) * 100; % (mm)
strainUTS = E1(i);
UTSIndex = i;
end
end
%########################################################################
%% total elongation at failure
totalElongation = (disp(end) / lengthOriginal) * 100; % (mm)
%########################################################################
%% At fracture Sigma Ultimate Tensile Strength ; TrueUTS ; true Strain
sigmaUTS = max(force);
%Incorrect
sigmaUTSTrue = trueUTS(sigmaUTS,areaOriginal,areaInstant(UTSIndex));
strainUTSTrue = trueStrain((lengthOriginal + disp(end)),lengthOriginal,0,0,0,0);
%##########################################################################
%% Engineering and True Strain and Stress Arrays
EngStress = [];
EngStrain = [];
stressTrue = [];
strainTrue = [];
for i = 1:length(force)
EngStress(i) = engineeringStress(force(i),areaOriginal);
EngStrain(i) = engineeringStrain(lengthOriginal+disp(i),lengthOriginal);
strainTrue(i) = trueStrain(lengthOriginal+disp(i),lengthOriginal);
stressTrue(i) = trueStress(force(i),areaInstant(i));
end
% Engineering Stress and Strain at UTS
EngStressUTS = max(EngStress); % MPa
StrainUTS = 0;
% Uniform Elongation At Eng. Stress UTS
for i = 1:length(EngStress)
if EngStress(i) == max(EngStress) % index UTS
uniformElongationEngStress = (disp(i) / lengthOriginal) * 100; % (mm)
StrainUTS = EngStrain(i); % MPa
end
end
%% Strength Coefficient K @ UTS
%power law equtaion at UTS of True Stress
K = strenghtCoefficient(stressTrue(UTSIndex),strainTrue(UTSIndex));
% Strength Coefficient from DIC data and Engeering data for plot B
kDIC = strenghtCoefficient(stressTrue(UTSIndex),strainTrue(UTSIndex)); %May not need this
kEng = strenghtCoefficient(max(EngStress),EngStrain(UTSIndex));
%######################################################################
%% Strain Hardening-Exponent @ UTS n = e
% length at onset of necking (UTS)
lengthTrueUTS = (lengthOriginal+disp(UTSIndex)); % total length atpoint of UTS of True Stress
lengthEngUTS = (lengthOriginal+disp(UTSIndex)); % total length atpoint of UTS of Eng Stress
n = trueStrain(lengthTrueUTS,lengthOriginal,0,0,0,0); % n = e = ln(l/lo)
nDIC = n; % At uts The solution for 'n' is equal for all data methoods (True, Eng, DIC)
%########################################################################
%% 2 Percent Offset curve Force and Strain
% Initilize array
EngStrainOffset = [1:200];
EngStressLinearFit = [1:200];
% 2 Percent Offset Slope from index of [1:75]
offsetSlope = (EngStress(75)-EngStress(1)) / (EngStrain(75)-EngStrain(1));
% strain offset curve for graph
for i = 1:length(EngStrainOffset)
EngStrainOffset(i) = EngStrain(i) + .002;
EngStressLinearFit(i) = offsetSlope*EngStrain(i);
end
%######################################################################3
%% Yeild Point Stress and Strain
% % Central Difference
% dfdxC = TwoCdfdx(EngStress,EngStrain);
% df2dx2C = TwoCdfdx(dfdxC,EngStrain);
%Three Point Forward difference
dfdxF = ThreeFdfdx(EngStress,EngStrain);
df2dx2F = ThreeFdfdx(dfdxF,EngStrain);
dfde = [];
df2de2 = [];
%% This is basically junk but it happened to work, but I do not believe it is very reliable
sigmaY =[];
strainY = [];
Tolerence = 0.01;
sigmaYIndex = 0;
dfdxY = 0;
for i = 1:200
if (EngStressLinearFit(i) >= EngStress(i)+Tolerence)
sigmaY = EngStress(i);
strainY = EngStrain(i);
dfdxY = dfdxF(i);
sigmaYIndex = i;
break
end
end
%% Modulus of Elasticity at yeild point
modElasticity = EngStress(sigmaYIndex)/EngStrain(sigmaYIndex);
%########################################################################
%% Posson's Ratio in Elastic Range
poissonsRatio = [];
poissonsRatio(1) = 0;
for i = 2:sigmaYIndex
elastRange(i) = abs(E2(i) / E1(i));
end
elastRangeAvg = mean(elastRange);
poissonsRatio([1:sigmaYIndex]) = elastRangeAvg;
for i = 116:1565%(sigmaYIndex + 1):length(E2(sigmaYIndex:E2(end)))
poissonsRatio(i) = E2(i) / E1(i);
end
%########################################################################
%% Toughness
u = toughness(K,strainTrue(end),n); % NEED WORK STILL
%#######################################################################
%% Plots
%% Engineering Stress-Strain curve and True Stress - True Strain Curve
figure("Name","Graph A")
plot(strainTrue,stressTrue,'r.',EngStrain,EngStress,'b.'); xlabel('Total Strain \epsilon'); ylabel('Stress \sigma');
title('DP1180RD S1');xlim([-0.01,0.15]);ylim([0,1.9]);
hold on
plot(EngStrain(end),EngStress(end),'rX');
text(0.075,0.8,['( ',num2str(EngStrain(end)),' , ',num2str(EngStress(end)),' )'],'FontSize',9,'Color','black');
text(0.08,0.87,'Fracture Point','FontSize',9,'Color','red'); hold on;
plot(StrainUTS,EngStressUTS,'r*');
text(0.058,1.15,'UTS','FontSize',9,'Color','red');
text(0.048,1.09,['( ',num2str(StrainUTS),' , ',num2str(EngStressUTS),' )'],'FontSize',9,'Color','black');
text(0.04,0.5,['Uniform Elongation @ UTS: ',num2str(uniformElongation),' mm'],'FontSize',9,'Color','black');
text(0.04,0.4,['Total Elongation @ Fracture Point: ',num2str(totalElongation),' mm'],'FontSize',9,'Color','black');
legend("True Strain","Eng. Strain",'Location',"southeast");
hold off;
%###########################################################################
%% Power-Law Equation Curve fitting
figure("Name","Graph B")
plot(EngStrain([sigmaYIndex:UTSIndex]),EngStress([sigmaYIndex:UTSIndex]),'k.'); hold on
plot(strainTrue([sigmaYIndex:UTSIndex]),stressTrue([sigmaYIndex:UTSIndex]),'bo'); hold on
%plot(EngStrain,EngStrain([]).*slopeCurveFit'Fitted-EngSS') hold on
plot(strainTrue([sigmaYIndex:end]),stressTrue([sigmaYIndex:end]),'r.'); hold on
%plot('Fitted-DIC') hold on
text(0.03,1.25,['\sigma','=K(\it\epsilon_{o}+\epsilon)^{n}'],'FontSize',9,'Color','black');
text(0.04,0.6,['K, n, \it\epsilon_{o} :'],'FontSize',9,'Color','black');
text(0.04,0.5,['DIC: ',num2str(kDIC),' , ',num2str(n),' , ',num2str(strainTrue([1]))],'FontSize',9,'Color','black');
text(0.04,0.4,['Eng: ',num2str(kEng),' , ',num2str(n),' , ',num2str(EngStrain([1]))],'FontSize',9,'Color','black');
title('DP1180RD S1 - Plastic');xlim([0,0.15]);ylim([0,1.9]);
xlabel('Plastic Strain'); ylabel('Stress, MPa');
legend("EngSS",'TrueSS-Eng Data',"TrueSS-DIC Data",'Location',"southeast");
hold off
%#########################################################################
%% Engineering Stress-Strain Curve 2% Offset Yeild Point
figure("Name","Graph C")
plot(EngStrain,EngStress,'b.'); xlabel('Strain \epsilon'); ylabel('Stress, MPa \sigma'); hold on
title('DP1180RD S1 - Elastic');xlabel('EngStrain \it e');ylabel('EngStress, MPa');
xlim([0,0.007]);ylim([0,1.2]);
plot(strainY,sigmaY,'rO'); hold on
% Linear Fitting
plot(EngStrain([1:200]),EngStressLinearFit,'r-'); hold on
% 2 Percent Offset Stress-Strain Curve
plot(EngStrainOffset,EngStressLinearFit,'k-'); hold on
text(.0038,0.2,['E = ',num2str(modElasticity),' (GPa)',' ; ','\it u = ',num2str(u)],'FontSize',9,'Color','black');
legend("Expt data",'Linear fitting','Data for fitting','0.2% offset','Location',"northwest");
hold off;
%
% ########################################################################
%% Principle True Strain Ratio vs. E1
figure("Name","Graph D")
plot(E1,poissonsRatio,'b.'); xlabel('Strain \epsilon'); ylabel('Stress, MPa \sigma'); hold on
title('DP1180RD S1 - E2/E1');xlabel('Strain E1');ylabel('E2/E1')
%xlim([0,0.007]);ylim([0,1.2]);
hold off

Answers (2)

VBBV
VBBV on 26 Sep 2022
clc,clear all
%% Load Data - Initilize Variables
DP980TD_S2 = xlsread('DP980TD-S2.xlsx'); % Data File
% Constants
widthOriginal = DP980TD_S2(1,2); % Original gauge width (mm)
thicknessOriginal = DP980TD_S2(2,2); % Original gauge thickness (mm)
lengthOriginal = DP980TD_S2(3,2); % Original gauge length (mm)
widthFinal = DP980TD_S2(4,2); % Final gauge width at fracture (mm)
thicknessFinal = DP980TD_S2(5,2); %final gauge thickness at fracture (mm)
% Arrays
force = DP980TD_S2([14:end],1).';
disp = DP980TD_S2([14:end],2).';
E1 = DP980TD_S2([14:end],3).'
E1 = 1×1023
1.0e+00 * 0.0000 0.0001 0.0002 0.0002 0.0002 0.0003 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0003 0.0003 0.0004 0.0004 0.0005 0.0002 0.0004 0.0003 0.0004 0.0004 0.0004 0.0003 0.0004 0.0004 0.0004 0.0004 0.0004
E2 = DP980TD_S2([14:end],4).'
E2 = 1×1023
1.0e+00 * 0 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 0.0001 0.0001 0.0003 0.0002 0.0001 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0002 0.0001 0.0002 0.0002
% Area
areaOriginal = (widthOriginal*thicknessOriginal) % simple area calculation
areaOriginal = 10.4297
areaNeck = (widthFinal*thicknessFinal);
%#######################################################################
%% Area of Reduction
areaInstant = [];
for i = 1:length(E1)
areaReduction = areaOriginal - (E1(i)*E2(i)); % Make Plot for Report notate initiation of necking
areaInstant(i) = areaOriginal*exp(-E1(i));
end
%#####################################################################
%% Onset of necking Calculation: Stress and Strain at UTS; Uniform Elongation
uniformElongation = 0;% percent
UTSIndex = 0;
strainUTS = 0;
for i = 1:length(force)
if force(i) == max(force) % index UTS
uniformElongation = (disp(i) / lengthOriginal) * 100; % (mm)
strainUTS = E1(i);
UTSIndex = i;
end
end
%########################################################################
%% total elongation at failure
totalElongation = (disp(end) / lengthOriginal) * 100; % (mm)
%########################################################################
%% At fracture Sigma Ultimate Tensile Strength ; TrueUTS ; true Strain
sigmaUTS = max(force);
%Incorrect
sigmaUTSTrue = trueUTS(sigmaUTS,areaOriginal,areaInstant(UTSIndex));
Unrecognized function or variable 'trueUTS'.
strainUTSTrue = trueStrain((lengthOriginal + disp(end)),lengthOriginal,0,0,0,0);
%##########################################################################
%% Engineering and True Strain and Stress Arrays
EngStress = [];
EngStrain = [];
stressTrue = [];
strainTrue = [];
for i = 1:length(force)
EngStress(i) = engineeringStress(force(i),areaOriginal);
EngStrain(i) = engineeringStrain(lengthOriginal+disp(i),lengthOriginal);
strainTrue(i) = trueStrain(lengthOriginal+disp(i),lengthOriginal);
stressTrue(i) = trueStress(force(i),areaInstant(i));
end
% Engineering Stress and Strain at UTS
EngStressUTS = max(EngStress); % MPa
StrainUTS = 0;
% Uniform Elongation At Eng. Stress UTS
for i = 1:length(EngStress)
if EngStress(i) == max(EngStress) % index UTS
uniformElongationEngStress = (disp(i) / lengthOriginal) * 100; % (mm)
StrainUTS = EngStrain(i); % MPa
end
end
%% Strength Coefficient K @ UTS
%power law equtaion at UTS of True Stress
K = strenghtCoefficient(stressTrue(UTSIndex),strainTrue(UTSIndex));
% Strength Coefficient from DIC data and Engeering data for plot B
kDIC = strenghtCoefficient(stressTrue(UTSIndex),strainTrue(UTSIndex)); %May not need this
kEng = strenghtCoefficient(max(EngStress),EngStrain(UTSIndex));
%######################################################################
%% Strain Hardening-Exponent @ UTS n = e
% length at onset of necking (UTS)
lengthTrueUTS = (lengthOriginal+disp(UTSIndex)); % total length atpoint of UTS of True Stress
lengthEngUTS = (lengthOriginal+disp(UTSIndex)); % total length atpoint of UTS of Eng Stress
n = trueStrain(lengthTrueUTS,lengthOriginal,0,0,0,0); % n = e = ln(l/lo)
nDIC = n; % At uts The solution for 'n' is equal for all data methoods (True, Eng, DIC)
%########################################################################
%% 2 Percent Offset curve Force and Strain
% Initilize array
EngStrainOffset = [1:200];
EngStressLinearFit = [1:200];
% 2 Percent Offset Slope from index of [1:75]
offsetSlope = (EngStress(75)-EngStress(1)) / (EngStrain(75)-EngStrain(1));
% strain offset curve for graph
for i = 1:length(EngStrainOffset)
EngStrainOffset(i) = EngStrain(i) + .002;
EngStressLinearFit(i) = offsetSlope*EngStrain(i);
end
%######################################################################3
%% Yeild Point Stress and Strain
% % Central Difference
% dfdxC = TwoCdfdx(EngStress,EngStrain);
% df2dx2C = TwoCdfdx(dfdxC,EngStrain);
%Three Point Forward difference
dfdxF = ThreeFdfdx(EngStress,EngStrain);
df2dx2F = ThreeFdfdx(dfdxF,EngStrain);
dfde = [];
df2de2 = [];
%% This is basically junk but it happened to work, but I do not believe it is very reliable
sigmaY =[];
strainY = [];
Tolerence = 0.01;
sigmaYIndex = 0;
dfdxY = 0;
for i = 1:200
if (EngStressLinearFit(i) >= EngStress(i)+Tolerence)
sigmaY = EngStress(i);
strainY = EngStrain(i);
dfdxY = dfdxF(i);
sigmaYIndex = i;
break
end
end
%% Modulus of Elasticity at yeild point
modElasticity = EngStress(sigmaYIndex)/EngStrain(sigmaYIndex);
%########################################################################
%% Posson's Ratio in Elastic Range
poissonsRatio = [];
poissonsRatio(1) = 0;
for i = 2:sigmaYIndex
elastRange(i) = abs(E2(i) / E1(i));
end
elastRangeAvg = mean(elastRange);
poissonsRatio([1:sigmaYIndex]) = elastRangeAvg;
for i = 116:1565%(sigmaYIndex + 1):length(E2(sigmaYIndex:E2(end)))
poissonsRatio(i) = E2(i) / E1(i);
end
%########################################################################
%% Toughness
u = toughness(K,strainTrue(end),n); % NEED WORK STILL
%#######################################################################
%% Plots
%% Engineering Stress-Strain curve and True Stress - True Strain Curve
figure("Name","Graph A")
plot(strainTrue,stressTrue,'r.',EngStrain,EngStress,'b.'); xlabel('Total Strain \epsilon'); ylabel('Stress \sigma');
title('DP1180RD S1');xlim([-0.01,0.15]);ylim([0,1.9]);
hold on
plot(EngStrain(end),EngStress(end),'rX');
text(0.075,0.8,['( ',num2str(EngStrain(end)),' , ',num2str(EngStress(end)),' )'],'FontSize',9,'Color','black');
text(0.08,0.87,'Fracture Point','FontSize',9,'Color','red'); hold on;
plot(StrainUTS,EngStressUTS,'r*');
text(0.058,1.15,'UTS','FontSize',9,'Color','red');
text(0.048,1.09,['( ',num2str(StrainUTS),' , ',num2str(EngStressUTS),' )'],'FontSize',9,'Color','black');
text(0.04,0.5,['Uniform Elongation @ UTS: ',num2str(uniformElongation),' mm'],'FontSize',9,'Color','black');
text(0.04,0.4,['Total Elongation @ Fracture Point: ',num2str(totalElongation),' mm'],'FontSize',9,'Color','black');
legend("True Strain","Eng. Strain",'Location',"southeast");
hold off;
%###########################################################################
%% Power-Law Equation Curve fitting
figure("Name","Graph B")
plot(EngStrain([sigmaYIndex:UTSIndex]),EngStress([sigmaYIndex:UTSIndex]),'k.'); hold on
plot(strainTrue([sigmaYIndex:UTSIndex]),stressTrue([sigmaYIndex:UTSIndex]),'bo'); hold on
%plot(EngStrain,EngStrain([]).*slopeCurveFit'Fitted-EngSS') hold on
plot(strainTrue([sigmaYIndex:end]),stressTrue([sigmaYIndex:end]),'r.'); hold on
%plot('Fitted-DIC') hold on
text(0.03,1.25,['\sigma','=K(\it\epsilon_{o}+\epsilon)^{n}'],'FontSize',9,'Color','black');
text(0.04,0.6,['K, n, \it\epsilon_{o} :'],'FontSize',9,'Color','black');
text(0.04,0.5,['DIC: ',num2str(kDIC),' , ',num2str(n),' , ',num2str(strainTrue([1]))],'FontSize',9,'Color','black');
text(0.04,0.4,['Eng: ',num2str(kEng),' , ',num2str(n),' , ',num2str(EngStrain([1]))],'FontSize',9,'Color','black');
title('DP1180RD S1 - Plastic');xlim([0,0.15]);ylim([0,1.9]);
xlabel('Plastic Strain'); ylabel('Stress, MPa');
legend("EngSS",'TrueSS-Eng Data',"TrueSS-DIC Data",'Location',"southeast");
hold off
%#########################################################################
%% Engineering Stress-Strain Curve 2% Offset Yeild Point
figure("Name","Graph C")
plot(EngStrain,EngStress,'b.'); xlabel('Strain \epsilon'); ylabel('Stress, MPa \sigma'); hold on
title('DP1180RD S1 - Elastic');xlabel('EngStrain \it e');ylabel('EngStress, MPa');
xlim([0,0.007]);ylim([0,1.2]);
plot(strainY,sigmaY,'rO'); hold on
% Linear Fitting
plot(EngStrain([1:200]),EngStressLinearFit,'r-'); hold on
% 2 Percent Offset Stress-Strain Curve
plot(EngStrainOffset,EngStressLinearFit,'k-'); hold on
text(.0038,0.2,['E = ',num2str(modElasticity),' (GPa)',' ; ','\it u = ',num2str(u)],'FontSize',9,'Color','black');
legend("Expt data",'Linear fitting','Data for fitting','0.2% offset','Location',"northwest");
hold off;
%
% ########################################################################
%% Principle True Strain Ratio vs. E1
figure("Name","Graph D")
plot(E1,poissonsRatio,'b.'); xlabel('Strain \epsilon'); ylabel('Stress, MPa \sigma'); hold on
title('DP1180RD S1 - E2/E1');xlabel('Strain E1');ylabel('E2/E1')
%xlim([0,0.007]);ylim([0,1.2]);
hold off
  2 Comments
VBBV
VBBV on 26 Sep 2022
Edited: VBBV on 26 Sep 2022
Area is a 2D fill plot function and dosent return scalar value

Sign in to comment.


Jan
Jan on 26 Sep 2022
Edited: Jan on 26 Sep 2022
areaOriginal = area(widthOriginal,thicknessOriginal);
This creates a diagram and returns the handle to the graphics object.
areaReduction(i) = areaOriginal-(E1(i)*E2(i));
Here you subtract a number from the graphics handle. This is not meaningful.
The error message should clarify this already.
Some notes:
force = DP980TD_S2([14:end],1).';
% No need for brackets:
force = DP980TD_S2(14:end, 1).';
% a:b is a vector already
And:
for i = 1:length(force)
if force(i) == max(force) % index UTS
uniformElongation = (disp(i) / lengthOriginal) * 100; % (mm)
strainUTS = E1(i);
UTSIndex = i;
end
end
can be simplified to:
i = find(force == max(force), 1, 'last');
uniformElongation = (disp(i) / lengthOriginal) * 100; % (mm)
strainUTS = E1(i);
UTSIndex = i;

Categories

Find more on Stress and Strain in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by