Creating a function to calculate yield strength of a metal?
Mostrar comentarios más antiguos
I am working on the following problem.

This is the code i have so far.
if true
% code
grain_size = 0.1;
strength_vector = zeros(1,20);
n = 1;
while (grain_size < 2.0)
A = HallPetch(12000, 9600, grain_size);
strength_vector(n) = A;
n = n + 1;
grain_size = grain_size + 0.1;
end
M = (0.1: 0.1: 2.0);
M = M';
strength_vector = strength_vector';
fprintf('Grain Size (mm) Yield Strength(psi) \n');
fprintf('%5.1f %25.3f \n', [M, strength_vector]');
function [yield_strength] = HallPetch(sigma_nought, k, d)
yield_strength = sigma_nought + k*(d^(-1/2));
end
end
It seems to work up until the grain size equals 2.0, then the result it gives me is zero. Any ideas why?
Respuestas (1)
Ameer Hamza
el 22 de Mayo de 2018
Editada: Ameer Hamza
el 22 de Mayo de 2018
Since you want to get the value up to 2 you need to increase the limit of while loop a little bit
while (grain_size < 2.01)
Now it will run for grain_size=2
Grain Size (mm) Yield Strength(psi)
0.1 42357.866
0.2 33466.253
0.3 29527.122
0.4 27178.933
0.5 25576.450
0.6 24393.547
0.7 23474.195
0.8 22733.126
0.9 22119.289
1.0 21600.000
1.1 21153.241
1.2 20763.561
1.3 20419.757
1.4 20113.481
1.5 19838.367
1.6 19589.466
1.7 19362.864
1.8 19155.418
1.9 18964.572
2.0 18788.225
Note you cannot use
while (grain_size <= 2)
because of finite precision of floating point.
Categorías
Más información sobre Introduction to Installation and Licensing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!