TheKojent

Stress-Strain Script

Nov 2nd, 2018
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.61 KB | None | 0 0
  1. %Script to create stress-strain curves from a CSV file
  2. %Author: Victor Kojenov, [email protected]
  3.  
  4. %Define material geometry (mm) and data file
  5. datafile = 'sargentd_2_t3.csv';
  6. l_initial = 25.4;
  7. w_initial = 6.41;
  8. t_initial = 1.25;
  9.  
  10. %Loading CSV files with columns [Time (min), Force (N), Position (mm)] into
  11. %individual row vectors
  12. data = csvread(datafile, 1, 0);   %Row offset is necessary for column labels
  13. time = data(:,1)'./60;  %Convert to seconds
  14. force = data(:,2)';
  15. position = data(:,3)';
  16.  
  17. %Normalizing the force and position data into stress and strain
  18. stress = force ./ (t_initial * w_initial);
  19. strain = position ./ (position + l_initial);
  20.  
  21. %Plotting force and position
  22. plot(strain, stress, '.')  
  23. grid('on')
  24. title('Stress-strain')
  25. xlabel('Strain')
  26. ylabel('Stress (MPa)')
  27.  
  28. %Have user select two values of the linear portion of the plot
  29. [X, ~] = ginput(2);
  30.  
  31. %Find indices of the linear range based on the inputted x values
  32. if X(1) > X(2)
  33.     lin_index = find((strain < X(1)) & (strain > X(2)));
  34. else
  35.     lin_index = find((strain > X(1)) & (strain < X(2)));
  36. end
  37.  
  38. %Simple linear fit of linear range based on max and min x values (effectively calculating modulus of elasticity)
  39. lin_min = [strain(min(lin_index)), stress(min(lin_index))];
  40. lin_max = [strain(max(lin_index)), stress(max(lin_index))];
  41. elastic_modulus = (lin_max(2)-lin_min(2))/(lin_max(1)-lin_min(1));
  42.  
  43. %Finding x-intercept assuming perfect linear behavior to determine the offset due to jaw slippage
  44. jaw_offset = lin_min(1)-(lin_min(2)/elastic_modulus);
  45.  
  46. %Correcting data for jaw slippage
  47. strain = strain - jaw_offset;
  48. new_origin = find(strain >= 0, 1, 'first');
  49. time = time(1,new_origin:size(time,2));
  50. stress = stress(1,new_origin:size(stress,2));
  51. strain = strain(1,new_origin:size(strain,2));
  52.  
  53. %Plot force and position again to correct for sharp dropoff at the end
  54. plot(strain, stress, '.')  
  55. grid('on')
  56. title('Stress-strain')
  57. xlabel('Strain')
  58. ylabel('Stress (MPa)')
  59.  
  60. %Have user select just above the first point that drops off sharply, and thereby find fracture strength
  61. [X, Y] = ginput(1);
  62. if X > max(strain)
  63.     fracture_index = find(stress > Y, 1, 'last');
  64.     sigma_fracture = stress(fracture_index);
  65.     fracture_strain = strain(fracture_index);
  66. else
  67.     fracture_index = find((stress < Y) & (strain > X), 1, 'first') - 1;
  68.     sigma_fracture = stress(fracture_index);
  69.     fracture_strain = strain(fracture_index);
  70. end
  71.  
  72. %Correct for dropoff
  73. time = time(1:fracture_index);
  74. stress = stress(1:fracture_index);
  75. strain = strain(1:fracture_index);
  76.  
  77. %Calculating 0.2% offset line by minimizing error between linear line and actual data
  78. lin_data = (strain - .002) .* elastic_modulus;
  79. [err, sigma_y_index] = min(abs(lin_data - stress)); %find index with least error
  80. sigma_y = stress(sigma_y_index);
  81.  
  82. %Calculating ultimate tensile strength and reduction of area
  83. sigma_uts = max(stress);
  84. reduction_area_fracture = 1/(1+fracture_strain); %using conservation of volume
  85.  
  86. %Report all crucial values
  87. fprintf('0.2 percent offset yield strength: %.2f MPa\n', sigma_y)
  88. fprintf('Ultimate tensile strength: %.2f MPa\n', sigma_uts)
  89. fprintf('Percent elongation at fracture: %.2f\n', fracture_strain*100)
  90. fprintf('Percent reduction of area at fracture: %.2f\n', reduction_area_fracture*100)
  91. fprintf('Breaking stress: %.2f MPa\n', sigma_fracture)
  92.  
  93. %Final plot with line at 0.2% yield
  94. yield_line_range = strain(1:sigma_y_index)-.002;
  95. yield_line = elastic_modulus.*(yield_line_range-.002);
  96. plot(strain, stress, '.', yield_line_range, yield_line)
  97. title('Stress-strain')
  98. xlabel('Strain')
  99. ylabel('Stress (MPa)')
  100. grid('on')
  101. xlim([0 inf])
  102. ylim([0 inf])
Advertisement