NEED MATLAB CODE Can someone provide the matlab code to solv
NEED MATLAB CODE:
Can someone provide the matlab code to solve the question to the link below. I only need part a)
https://www.chegg.com/homework-help/questions-and-answers/tensile-testing-machine-one-shown-figure-p511a-b-used-determine-behavior-materials-deforme-q13656267?trackid=4e1f111c&strackid=01199da6&ii=1
Solution
function mat_analysis(strs, strn, lin_range)
lregress_strn = strn(lin_range); % MAKE SURE THIS IS IN THE RANGE OF
lregress_strs = strs(lin_range); % THE LINEAR REGION OF THE DATA!!
yfit = polyfit(lregress_strn,lregress_strs,1); % Finds E of data set
mod_E = yfit(:,1) % Sets E value
b = yfit(:,2) % For Yield calcs
yield_strs = mod_E * (strn - .2) + b; % Calculates the yield line data
UTS = max(strs); % Finds UTS. That makes things easy.
UTS_strn = strn(find(strs == UTS));
UTS_strn = UTS_strn(1); % Sometimes find returns multiple values
cutoff1 = 1;
for cutoff2 = 1:length(yield_strs) % Cuts off yield line at the right place
if yield_strs(cutoff2) < 0
cutoff1 = cutoff2; % For bottom
end
if yield_strs(cutoff2) > UTS % For top
break;
end
end
diff = [10000 0 0]; % Storage variable
figure;
hold on; % Plots the initial data
plot(strn, strs, strn(cutoff1:cutoff2), yield_strs(cutoff1:cutoff2));
ylabel(\'MPa\');
axis([0,strn(length(strn)),0,UTS + 20]);
if max(strn) > 5
legend(\'Engineering Stress vs. Strain\', \'Yield Line\', \'Location\', \'Best\');
title(\'2.002 Lab data: Tension Engineering Stress vs. Engineering Strain\'); % CHANGE THIS FOR NEW TITLE
xlabel(\'percent\');
else
legend(\'True Stress vs. Strain\', \'Yield Line\', \'Location\', \'Best\');
title(\'2.002 Lab data: Tension True Stress vs Trues Strain\'); % CHANGE THIS FOR NEW TITLE
xlabel(\'log scale\');
end
text(UTS_strn, (UTS - 30), strcat(\'\\uparrow \\sigma_T_S: \',num2str(UTS),\'MPa\'));
% ignore the man behind the curtain doing tricky functions
holder(500) = 0;
for pnt = 100:600 % REALLY simple least squares analysis, but works well
holder(pnt - 99) = (strs(pnt) - yield_strs(pnt))^2;
end
fgh = find(holder == min(holder));
diff(2) = strs(fgh(1) + 99);
diff(3) = strn(fgh(1) + 99);
plot(diff(3), diff(2), \'*\') % Puts a * on the yield point
text(diff(3), diff(2), strcat(\'\\leftarrow \\sigma_y:\', num2str(diff(2)), \'MPa\'));
ptr = lin_range(floor((length(lin_range) / 2)));
if (diff(2) / 2) > strs(ptr)
ypos = diff(2) / 2;
ptr = find(strn == diff(3));
else
ypos = strs(ptr);
end
text(strn(ptr(1)), ypos, strcat(\'\\leftarrow E:\', num2str(mod_E), \'MPa/%\'));
% More text stuff, labels sig_y and E
hold off;

