-
Notifications
You must be signed in to change notification settings - Fork 0
/
stress.m
108 lines (91 loc) · 2.79 KB
/
stress.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
% vim: tabstop=2 shiftwidth=2 expandtab
%
% Stress–strain Curve
%
% @author Damien Bezborodov <dbezborodov@gmail.com>
%
% sudo apt install octave-statistics octave-matgeom
%
% https://mechcontent.com/modulus-of-resilience/#What_is_resilience
pkg load statistics
pkg load matgeom
function [E, yield, tensileStrength, resilience, toughness, resilienceByArea, resilienceByYield] = ssplot(csvfile, outfile, subject)
hold off;
data = csvread(csvfile);
% Stress/strain plot
stress = data(15:end, 5);
strain = data(15:end, 4);
plot(strain, stress);
% Decorate plot.
hold on;
title(subject);
ylabel('Stress \sigma (MPa)');
xlabel('Strain \epsilon (mm/mm)');
grid on;
grid minor on;
% Find linear region and elastic modulus.
for i = 15:rows(data)
[b, bint, r, rint, stats] = regress(stress(1:i), strain(1:i));
R2 = stats(1);
if R2 < 0.95
break
end
end
E = b * 10^6;
linearx = strain(1:end) + 0.002;
lineary = b*strain(1:end);
plot(linearx(1:i), lineary(1:i));
% Yield strength (intersection.)
sspolyline = cat(2, strain, stress);
yield = intersectPolylines(cat(2, linearx, lineary), sspolyline);
plot(yield(1), yield(2), 'k*');
label = strcat(' \sigma_y = ', num2str(yield(2), 4));
text(yield(1), yield(2), label);
% Resilience.
intersectIdx = findClosestPoint(yield, sspolyline);
resilienceByArea = trapz(strain(1:intersectIdx), 10^6 * stress(1:intersectIdx));
% Tensile strength (maximum.)
[ymax, xmax_idx] = max(stress);
xmax = strain(xmax_idx);
tensileStrength = ymax;
plot(xmax, ymax, 'k*');
label = strcat(num2str(ymax, 4));
text(xmax, ymax, label, 'verticalalignment', 'top');
% Toughness.
toughness = trapz(strain(1:end), 10^6 * stress(1:end));
% Save stress/strain plot.
saveas(1, strcat(outfile, '.svg'));
print(strcat(outfile, '.png'), '-dpng', '-r300');
% Other calculations.
sigma_y = yield(2) * 10^6;
epsilon_y = yield(1);
resilienceByYield = 1/2 * sigma_y * epsilon_y;
resilience = sigma_y^2 / (2*E);
% Plot for linear region only.
hold off
plot(strain(1:intersectIdx), stress(1:intersectIdx));
hold on
plot(linearx(1:i), lineary(1:i));
plot(yield(1), yield(2), 'k*');
label = num2str(yield(2), 4);
text(yield(1), yield(2), label);
title(strcat(subject, ' Linear Region'));
ylabel('Stress \sigma (MPa)');
xlabel('Strain \epsilon (mm/mm)');
grid on;
grid minor on;
saveas(1, strcat(outfile, '_1.svg'));
print(strcat(outfile, '_1.png'), '-dpng', '-r300');
% Residual case order plot.
%hold off;
%plot(r, rint);
%saveas(1, strcat(outfile, '_2.svg'));
%print(strcat(outfile, '_2.png'), '-dpng', '-r300');
end
format short eng
arg_list = argv();
file = arg_list{1};
[filepath, name, ext] = fileparts(file);
disp(name);
[E, y, UTS, Ur, Ut, UrA, Ury] = ssplot(
file, name, name)