Last active
August 29, 2015 14:00
-
-
Save hmurraydavis/11300320 to your computer and use it in GitHub Desktop.
Calculate the elastic modulus from raw CSV separated data from instron tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateElasticModulusInstron(x,y) | |
%%%% Compute the elastic modulus from experamental data. | |
%%%% INPUT VARIABLE DEF: x=load of sample from experamental data, | |
%%%% y=elongation of sample from experamental data. | |
%%prep matlab environment: | |
clc; clf; | |
%% Define length of the slope which you want to calculate Elastic Modulus for: | |
lengths1 = 300:1800; | |
%% Select input data: | |
x = x(lengths1); | |
y = y(lengths1); | |
%Best fit line math: | |
p = polyfit(x,y,1); % p returns 2 coefficients fitting r = a_1 * x + a_2 | |
r = p(1) .* x + p(2); % compute a new vector r that has matching datapoints in x | |
%% now plot both the points in y and the curve fit in r | |
plot(x, y, 'x'); % raw data | |
hold on; | |
plot(x, r, 'r-','LineWidth',4.3); % calculated line of best fit | |
hold off; | |
ElasticModulus=p(1) %print elastic modulus (slope) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment