% Least squares fit programme for uni-directional CFRP % the programme will find the estimated elastic constants to produce a % curve which is as close as can be to the experimental curve. % Method 1 % A table will be produced in which guessed elastic constants will be determined along with value of % estimated elastic constants and the miniized value (the smaller the value associated with elastic constant choice) % Method 2 % The value of elastic constants is determined at once. No table is produced, only the elastic constants and the minimized value. % No hardwiring of values is needed % Customize everything to meet your requirements (A,B,C etc. used for % variabls that need to be customized % Copyright David Paterson, University of Strathclyde, Glasgow, UK. % Reuse or reuse with editing is permitted but must cite the author of this work. % David A.P. Paterson, "Life Cycle and Ultrasonic Based Non-Destructive Analysis of Recycled and Remanufactured Carbon Fibre Reinforced Plastic Composite", % Doctoral Thesis, Univeristy of Strathclyde, Glasgow, 2018 % Equations for transverse isotropic calculated constants may be found from % Castellano, A., Foti, P., Fraddosio, A., Marzano, S., Piccioni, M.D., 2014. % Mechanical characterization of CFRP composites by ultrasonic immersion tests: Experimental and numerical approaches. % Composites Part B Engineering. 66, 299–310. doi:10.1016/j.compositesb.2014.04.024 %======================== Counters ================================================================================ counter = 1; % sets up a counter variable for later on in the programme counter2 = 1; % sets up counter variable for creating velocities array_counter1 = 1; % sets up counter variable for storing the minimum elastic constant values Minimizeloop = 0; % sets up counter variable for while loop %======================== Counters ================================================================================ %======================== Arrays ================================================================================= sindrefract = zeros(1,A); %sets up an array of sin(refraction angles) required to allow refraction angle to be created Refract = zeros(1,A); %sets up an array of refraction angles needed later on for minimizing sum sindrefractL = zeros(1,A);%sets up an array of sinde of refraction angles needed later on for minimization sum RefractL = zeros(1,A); %sets up an array of refraction angles needed later on for minimizing sum c_min_array = zeros(50,12);%sets up an array which can store the c_min values %======================== Arrays ================================================================================== %======================== Inital elastic constants guess ========================================================== %========== hardwired, iteration and array method (MEHTOD 1 - COMMENT OUT IF USING METHOD 2) ====================== c_guess = [A, B, C]; c11 = D; % this value is hardwired into the least squares procedure - taken from experiment c33 = c_guess(1); % least squares technique will give this answer to user c44 = c_guess(2); % least squares technique will give this answer to user c13 = E; % this value is variable which changes throughout the programme iteration processes c66 = c_guess(3); %========== hardwired, iteration and array method (METHOD 1 - COMMENT OUT IF USING METHOD 2) ====================== %======================== All elastic constants guess (METHOD 2 - COMMENT OUT IF USING METHOD 1)================================= % c_guess = [A, B, C, D, E]; % method to determine all the elastic constants at once %======================== All elastic constants guess (METHOD 2 - COMMENT OUT IF USING METHOD 1)================================= %======================== Velocities ====================================================================================================== %This part of the programme will allow the user to select which sample velocities to use or even the average of all samples %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sample 1 %%%%%%%%%%%%%%% Sample1_1_2_VL = [A B C D E F G H etc]; % 1-2 plane for sample 1 and longitudinal velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] Sample1_1_2_VT = [I J K L M N O P etc]; % 1-2 plane for sample 1 and transverse velocities from experiment %Incident Angle = [9,10,11,12,13,14,15,16 etc...] Sample1_1_3_VL = [A B C D E F G H etc]; % 1-3 plane for sample 3 and longitudinal velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] Sample1_1_3_VT = [I J K L M N O P etc]; % 1-3 plane for sample 3 and and transverse velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sample 1 %%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sample 2 %%%%%%%%%%%%%%% Sample2_1_2_VL = [A B C D E F G H etc]; % 1-2 plane for sample 1 and longitudinal velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] Sample2_1_2_VT = [I J K L M N O P etc]; % 1-2 plane for sample 1 and transverse velocities from experiment %Incident Angle = [9,10,11,12,13,14,15,16 etc...] Sample2_1_3_VL = [A B C D E F G H etc]; % 1-3 plane for sample 3 and longitudinal velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] Sample2_1_3_VT = [I J K L M N O P etc]; % 1-3 plane for sample 3 and and transverse velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sample 2 %%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sample 3 %%%%%%%%%%%%%%% Sample3_1_2_VL = [A B C D E F G H etc]; % 1-2 plane for sample 1 and longitudinal velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] Sample3_1_2_VT = [I J K L M N O P etc]; % 1-2 plane for sample 1 and transverse velocities from experiment %Incident Angle = [9,10,11,12,13,14,15,16 etc...] Sample3_1_3_VL = [A B C D E F G H etc]; % 1-3 plane for sample 3 and longitudinal velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] Sample3_1_3_VT = [I J K L M N O P etc]; % 1-3 plane for sample 3 and and transverse velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sample 3 %%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sample 4 %%%%%%%%%%%%%%% Sample4_1_2_VL = [A B C D E F G H etc]; % 1-2 plane for sample 1 and longitudinal velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] Sample4_1_2_VT = [I J K L M N O P etc]; % 1-2 plane for sample 1 and transverse velocities from experiment %Incident Angle = [9,10,11,12,13,14,15,16 etc...] Sample4_1_3_VL = [A B C D E F G H etc]; % 1-3 plane for sample 3 and longitudinal velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] Sample4_1_3_VT = [I J K L M N O P etc]; % 1-3 plane for sample 3 and and transverse velocities from experiment %Incident Angle = [0,1,2,3,4,5,6,7,8 etc...] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sample 4 %%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Average velocities %%%%%%%%%%% Exp_VL_1_2 = ((Sample1_1_2_VL + Sample2_1_2_VL + Sample3_1_2_VL + Sample4_1_2_VL)/4); %Average velocites from all sample measurements Exp_VT_1_2 = ((Sample1_1_2_VT + Sample2_1_2_VT + Sample3_1_2_VT + Sample4_1_2_VT)/4); %Average velocites from all sample measurements Exp_VL_1_3 = ((Sample1_1_3_VL + Sample2_1_3_VL + Sample3_1_3_VL + Sample4_1_3_VL)/4); %Average velocites from all sample measurements Exp_VT_1_3 = ((Sample1_1_3_VT + Sample2_1_3_VT + Sample3_1_3_VT + Sample4_1_3_VT)/4); %Average velocites from all sample measurements %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Average velocities %%%%%%%%%%%% %======================== End of Velocities ====================================================================================================== %======================== Material Density and reference velocity ============================================================================================ P = ((A/((B))*1000)+(A/((B))*1000)+(A/((B))*1000)+(A/((B))*1000))/4; % density equations (Mass/Volume)) for each samples then divide by total number of samples SampleV_in_water = (A+B+C+D)/4; %======================== Material Density and reference velocity============================================================================================ %=================================== Refraction angles transverse =========================================================================== while counter == 1 Incident = [A B C D E F G H I J K etc]; % sets up the Incident angles sindrefract(counter2) = ((sind(Incident(counter2)))*Exp_VT_1_3(counter2))/(SampleV_in_water); % calculates the sinde of refraction angle Refract(counter2) = asind(sindrefract(counter2)); % calcualtes the refraction anlge (this is the anlge the way travels through sample in) counter2 = counter2+1; % increases counter2 variable to allow for moves to create new refraction angle. if counter2 == A % (limited here by number of incident angles) counter = 0; % sets the while loop counter value and exists while loop else counter = 1; % sets the while loop counter value end % end of if else statement end % end of while loop %=================================== Refraction angles transverse =========================================================================== %==================================== Refraction angles longitudinal ====================================================================== counter = 1; % resets the counter counter2 = 1; % resets the counter while counter == 1 IncidentL = [A B C D E F G H I J K etc]; % sets up the Incident angles sindrefractL(counter2) = ((sind(IncidentL(counter2)))*Exp_VL_1_3(counter2))/(SampleV_in_water); % calculates the sinde of refraction angle RefractL(counter2) = asind(sindrefractL(counter2)); % calcualtes the refraction anlge (this is the anlge the way travels through sample in) counter2 = counter2+1; % increases counter2 variable to allow for moves to create new refraction angle. if counter2 == 6 %(limited here by number of incident angles) counter = 0; % sets the while loop counter value and exists while loop else counter = 1; % sets the while loop counter value end % end of if else statement end % end of while loop % ==================================== Refraction angles longitudinal ====================================================================== counter = 1; % resets the variable to allow it to be used later on counter2 = 1; % resets the variable to allow it to be used later on % %============================================================================================================================================== % % LEAST SQUARES MINIMIZATION STAGE (METHOD 1 - COMMENT OUT IF USING METHOD 2) % %============================================================================================================================================== % this sections uses all the information given before it. The size of arrays etc have to match in order for this to execute successfully. This section needs edited. while Minimizeloop < 1 % %%%%%%%%%%%%%%%%%%%%%%%%%%% elastic constants Hardwired C11 and iteration c13 % %Rewritten with c33 = c1, c44 = c2, c66 = c3, D = choice of C11 from earlier Vtest = @(c) ( (((Exp_VT_1_3(1)) - (sqrt((((D*(cosd(Refract(1))^2))+(c(1)*(sind(Refract(1))^2))+c(2)) - sqrt((((D*(cosd(Refract(1))^2))+(c(1)*(sind(Refract(1))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(1))^2))+(c(2)*(sind(Refract(1))^2)))*((c(2)*(cosd(Refract(1))^2))+(c(1)*(sind(Refract(1))^2)))-(((c13+c(2))^2)*(sind(Refract(1))^2)*(cosd(Refract(1))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(2)) - (sqrt((((D*(cosd(Refract(2))^2))+(c(1)*(sind(Refract(2))^2))+c(2)) - sqrt((((D*(cosd(Refract(2))^2))+(c(1)*(sind(Refract(2))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(2))^2))+(c(2)*(sind(Refract(2))^2)))*((c(2)*(cosd(Refract(2))^2))+(c(1)*(sind(Refract(2))^2)))-(((c13+c(2))^2)*(sind(Refract(2))^2)*(cosd(Refract(2))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(3)) - (sqrt((((D*(cosd(Refract(3))^2))+(c(1)*(sind(Refract(3))^2))+c(2)) - sqrt((((D*(cosd(Refract(3))^2))+(c(1)*(sind(Refract(3))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(3))^2))+(c(2)*(sind(Refract(3))^2)))*((c(2)*(cosd(Refract(3))^2))+(c(1)*(sind(Refract(3))^2)))-(((c13+c(2))^2)*(sind(Refract(3))^2)*(cosd(Refract(3))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(4)) - (sqrt((((D*(cosd(Refract(4))^2))+(c(1)*(sind(Refract(4))^2))+c(2)) - sqrt((((D*(cosd(Refract(4))^2))+(c(1)*(sind(Refract(4))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(4))^2))+(c(2)*(sind(Refract(4))^2)))*((c(2)*(cosd(Refract(4))^2))+(c(1)*(sind(Refract(4))^2)))-(((c13+c(2))^2)*(sind(Refract(4))^2)*(cosd(Refract(4))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(5)) - (sqrt((((D*(cosd(Refract(5))^2))+(c(1)*(sind(Refract(5))^2))+c(2)) - sqrt((((D*(cosd(Refract(5))^2))+(c(1)*(sind(Refract(5))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(5))^2))+(c(2)*(sind(Refract(5))^2)))*((c(2)*(cosd(Refract(5))^2))+(c(1)*(sind(Refract(5))^2)))-(((c13+c(2))^2)*(sind(Refract(5))^2)*(cosd(Refract(5))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(6)) - (sqrt((((D*(cosd(Refract(6))^2))+(c(1)*(sind(Refract(6))^2))+c(2)) - sqrt((((D*(cosd(Refract(6))^2))+(c(1)*(sind(Refract(6))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(6))^2))+(c(2)*(sind(Refract(6))^2)))*((c(2)*(cosd(Refract(6))^2))+(c(1)*(sind(Refract(6))^2)))-(((c13+c(2))^2)*(sind(Refract(6))^2)*(cosd(Refract(6))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(7)) - (sqrt((((D*(cosd(Refract(7))^2))+(c(1)*(sind(Refract(7))^2))+c(2)) - sqrt((((D*(cosd(Refract(7))^2))+(c(1)*(sind(Refract(7))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(7))^2))+(c(2)*(sind(Refract(7))^2)))*((c(2)*(cosd(Refract(7))^2))+(c(1)*(sind(Refract(7))^2)))-(((c13+c(2))^2)*(sind(Refract(7))^2)*(cosd(Refract(7))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(8)) - (sqrt((((D*(cosd(Refract(8))^2))+(c(1)*(sind(Refract(8))^2))+c(2)) - sqrt((((D*(cosd(Refract(8))^2))+(c(1)*(sind(Refract(8))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(8))^2))+(c(2)*(sind(Refract(8))^2)))*((c(2)*(cosd(Refract(8))^2))+(c(1)*(sind(Refract(8))^2)))-(((c13+c(2))^2)*(sind(Refract(8))^2)*(cosd(Refract(8))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(9)) - (sqrt((((D*(cosd(Refract(9))^2))+(c(1)*(sind(Refract(9))^2))+c(2)) - sqrt((((D*(cosd(Refract(9))^2))+(c(1)*(sind(Refract(9))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(9))^2))+(c(2)*(sind(Refract(9))^2)))*((c(2)*(cosd(Refract(9))^2))+(c(1)*(sind(Refract(9))^2)))-(((c13+c(2))^2)*(sind(Refract(9))^2)*(cosd(Refract(9))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(10)) - (sqrt((((D*(cosd(Refract(10))^2))+(c(1)*(sind(Refract(10))^2))+c(2)) - sqrt((((D*(cosd(Refract(10))^2))+(c(1)*(sind(Refract(10))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(10))^2))+(c(2)*(sind(Refract(10))^2)))*((c(2)*(cosd(Refract(10))^2))+(c(1)*(sind(Refract(10))^2)))-(((c13+c(2))^2)*(sind(Refract(10))^2)*(cosd(Refract(10))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(11)) - (sqrt((((D*(cosd(Refract(11))^2))+(c(1)*(sind(Refract(11))^2))+c(2)) - sqrt((((D*(cosd(Refract(11))^2))+(c(1)*(sind(Refract(11))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(11))^2))+(c(2)*(sind(Refract(11))^2)))*((c(2)*(cosd(Refract(11))^2))+(c(1)*(sind(Refract(11))^2)))-(((c13+c(2))^2)*(sind(Refract(11))^2)*(cosd(Refract(11))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(12)) - (sqrt((((D*(cosd(Refract(12))^2))+(c(1)*(sind(Refract(12))^2))+c(2)) - sqrt((((D*(cosd(Refract(12))^2))+(c(1)*(sind(Refract(12))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(12))^2))+(c(2)*(sind(Refract(12))^2)))*((c(2)*(cosd(Refract(12))^2))+(c(1)*(sind(Refract(12))^2)))-(((c13+c(2))^2)*(sind(Refract(12))^2)*(cosd(Refract(12))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(13)) - (sqrt((((D*(cosd(Refract(13))^2))+(c(1)*(sind(Refract(13))^2))+c(2)) - sqrt((((D*(cosd(Refract(13))^2))+(c(1)*(sind(Refract(13))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(13))^2))+(c(2)*(sind(Refract(13))^2)))*((c(2)*(cosd(Refract(13))^2))+(c(1)*(sind(Refract(13))^2)))-(((c13+c(2))^2)*(sind(Refract(13))^2)*(cosd(Refract(13))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(14)) - (sqrt((((D*(cosd(Refract(14))^2))+(c(1)*(sind(Refract(14))^2))+c(2)) - sqrt((((D*(cosd(Refract(14))^2))+(c(1)*(sind(Refract(14))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(14))^2))+(c(2)*(sind(Refract(14))^2)))*((c(2)*(cosd(Refract(14))^2))+(c(1)*(sind(Refract(14))^2)))-(((c13+c(2))^2)*(sind(Refract(14))^2)*(cosd(Refract(14))^2))))))/(2*P))... ))^2)... + (((Exp_VT_1_3(15)) - (sqrt((((D*(cosd(Refract(15))^2))+(c(1)*(sind(Refract(15))^2))+c(2)) - sqrt((((D*(cosd(Refract(15))^2))+(c(1)*(sind(Refract(15))^2))+c(2))^2)... -(4*(((D*(cosd(Refract(15))^2))+(c(2)*(sind(Refract(15))^2)))*((c(2)*(cosd(Refract(15))^2))+(c(1)*(sind(Refract(15))^2)))-(((c13+c(2))^2)*(sind(Refract(15))^2)*(cosd(Refract(15))^2))))))/(2*P))... ))^2)... + (((Exp_VL_1_2(1))-(sqrt(D/P)))^2)... + (((Exp_VL_1_2(2))-(sqrt(D/P)))^2)... + (((Exp_VL_1_2(3))-(sqrt(D/P)))^2)... + (((Exp_VL_1_2(4))-(sqrt(D/P)))^2)... + (((Exp_VL_1_2(5))-(sqrt(D/P)))^2)... + (((Exp_VL_1_2(6))-(sqrt(D/P)))^2)... + (((Exp_VL_1_2(7))-(sqrt(D/P)))^2)... + (((Exp_VT_1_2(1))-(sqrt(c(3)/P)))^2)... + (((Exp_VT_1_2(2))-(sqrt(c(3)/P)))^2)... + (((Exp_VT_1_2(3))-(sqrt(c(3)/P)))^2)... + (((Exp_VT_1_2(4))-(sqrt(c(3)/P)))^2)... + (((Exp_VT_1_2(5))-(sqrt(c(3)/P)))^2)... + (((Exp_VT_1_2(6))-(sqrt(c(3)/P)))^2)... + (((Exp_VT_1_2(7))-(sqrt(c(3)/P)))^2)... + (((Exp_VT_1_2(8))-(sqrt(c(3)/P)))^2)... + (((Exp_VT_1_2(9))-(sqrt(c(3)/P)))^2)... + (((Exp_VT_1_2(10))-(sqrt(c(3)/P)))^2)... + (((Exp_VT_1_2(11))-(sqrt(c(3)/P)))^2)... + (((Exp_VL_1_3(1)) - (sqrt((((D*(cosd(RefractL(1))^2))+(c(1)*(sind(RefractL(1))^2))+c(2)) + sqrt((((D*(cosd(RefractL(1))^2))+(c(1)*(sind(RefractL(1))^2))+c(2))^2)... -(4*(((D*(cosd(RefractL(1))^2))+(c(2)*(sind(RefractL(1))^2)))*((c(2)*(cosd(RefractL(1))^2))+(c(1)*(sind(RefractL(1))^2)))-(((c13+c(2))^2)*(sind(RefractL(1))^2)*(cosd(RefractL(1))^2))))))/(2*P))... ))^2)... + (((Exp_VL_1_3(2)) - (sqrt((((D*(cosd(RefractL(2))^2))+(c(1)*(sind(RefractL(2))^2))+c(2)) + sqrt((((D*(cosd(RefractL(2))^2))+(c(1)*(sind(RefractL(2))^2))+c(2))^2)... -(4*(((D*(cosd(RefractL(2))^2))+(c(2)*(sind(RefractL(2))^2)))*((c(2)*(cosd(RefractL(2))^2))+(c(1)*(sind(RefractL(2))^2)))-(((c13+c(2))^2)*(sind(RefractL(2))^2)*(cosd(RefractL(2))^2))))))/(2*P))... ))^2)... ); % + (((Exp_VL_1_3(3)) - (sqrt((((D*(cosd(RefractL(3))^2))+(c(1)*(sind(RefractL(3))^2))+c(2)) + sqrt((((D*(cosd(RefractL(3))^2))+(c(1)*(sind(RefractL(3))^2))+c(2))^2)... % -(4*(((D*(cosd(RefractL(3))^2))+(c(2)*(sind(RefractL(3))^2)))*((c(2)*(cosd(RefractL(3))^2))+(c(1)*(sind(RefractL(3))^2)))-(((c13+c(2))^2)*(sind(RefractL(3))^2)*(cosd(RefractL(3))^2))))))/(2*P))... % ))^2)... % + (((Exp_VL_1_3(4)) - (sqrt((((D*(cosd(RefractL(4))^2))+(c(1)*(sind(RefractL(4))^2))+c(2)) + sqrt((((D*(cosd(RefractL(4))^2))+(c(1)*(sind(RefractL(4))^2))+c(2))^2)... % -(4*(((D*(cosd(RefractL(4))^2))+(c(2)*(sind(RefractL(4))^2)))*((c(2)*(cosd(RefractL(4))^2))+(c(1)*(sind(RefractL(4))^2)))-(((c13+c(2))^2)*(sind(RefractL(4))^2)*(cosd(RefractL(4))^2))))))/(2*P))... % ))^2)... % ); %================== Fminsearch function ======================================================================================== options = optimset('MaxFunEvals',1000000000000000000000000,'MaxIter',100000); % sets up some options for the fminsearch function [c_min,fval,exitflag,options] = fminsearch(Vtest, c_guess,options);% calls the fminsearch function for function vtest and uses c_guess as the initial test paramenters %================== End of Fminsearch function ================================================================================= c_min_array(counter2,1) = c11; % c11 guess c_min_array(counter2,2) = c33; % c33 guess c_min_array(counter2,3) = c44; % c44 guess c_min_array(counter2,4) = c13; % c13 guess c_min_array(counter2,5) = c66; % c66 guess c_min_array(counter2,6) = c11; % c11 value from least squares technique c_min_array(counter2,7) = c_min(1); % c33 value from least squares technique c_min_array(counter2,8) = c_min(2); % c44 value from least squares technique c_min_array(counter2,9) = c13; % c11 value from least squares technique c_min_array(counter2,10) = c_min(3); % c66 value from least squares technique c_min_array(counter2,11) = fval*(1e+5); %least squares minimized value c_min_array(counter2,12) = counter2*(1e+11); c13=c13+0.2e+9; % increases the value of c13 by a small amount each time - needed to watch how the function converges to minimum value and gives the associated constants counter2 = counter2+1; % increments counter2 by 1 each time, to allow the c_min_array to populate correctly counter = counter+1; % increase the counter by 1 each time, to allow the c if counter < 51 Minimizeloop = 0; % sets the while loop counter value else Minimizeloop = 2; % sets the while loop counter value and exits while loop end % end of if else statement end % end for the while loop c_min_array % %============================================================================================================================================== %END OF LEAST SQUARES MINIMIZATION STAGE (METHOD 1 - COMMENT OUT IF USING METHOD 2) %============================================================================================================================================== % %============================================================================================================================================== % % LEAST SQUARES MINIMIZATION STAGE (METHOD 2 - COMMENT OUT IF USING METHOD 1) % %============================================================================================================================================== % this sections uses all the information given before it. The size of arrays etc have to match in order for this to execute successfully. This section needs edited. % %%%%%%%%%%%%%%%%%%%%%%%% all elastic constants together %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % %Rewritten with c11 = c1, c33 = c2, c44 = c3, c13 = c4, c66 = c5 % % Vtest = @(c) ( (((Exp_VT_1_3(1)) - (sqrt((((c(1)*(cosd(Refract(1))^2))+(c(2)*(sind(Refract(1))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(1))^2))+(c(2)*(sind(Refract(1))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(1))^2))+(c(3)*(sind(Refract(1))^2)))*((c(3)*(cosd(Refract(1))^2))+(c(2)*(sind(Refract(1))^2)))-(((c(4)+c(3))^2)*(sind(Refract(1))^2)*(cosd(Refract(1))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(2)) - (sqrt((((c(1)*(cosd(Refract(2))^2))+(c(2)*(sind(Refract(2))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(2))^2))+(c(2)*(sind(Refract(2))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(2))^2))+(c(3)*(sind(Refract(2))^2)))*((c(3)*(cosd(Refract(2))^2))+(c(2)*(sind(Refract(2))^2)))-(((c(4)+c(3))^2)*(sind(Refract(2))^2)*(cosd(Refract(2))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(3)) - (sqrt((((c(1)*(cosd(Refract(3))^2))+(c(2)*(sind(Refract(3))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(3))^2))+(c(2)*(sind(Refract(3))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(3))^2))+(c(3)*(sind(Refract(3))^2)))*((c(3)*(cosd(Refract(3))^2))+(c(2)*(sind(Refract(3))^2)))-(((c(4)+c(3))^2)*(sind(Refract(3))^2)*(cosd(Refract(3))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(4)) - (sqrt((((c(1)*(cosd(Refract(4))^2))+(c(2)*(sind(Refract(4))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(4))^2))+(c(2)*(sind(Refract(4))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(4))^2))+(c(3)*(sind(Refract(4))^2)))*((c(3)*(cosd(Refract(4))^2))+(c(2)*(sind(Refract(4))^2)))-(((c(4)+c(3))^2)*(sind(Refract(4))^2)*(cosd(Refract(4))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(5)) - (sqrt((((c(1)*(cosd(Refract(5))^2))+(c(2)*(sind(Refract(5))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(5))^2))+(c(2)*(sind(Refract(5))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(5))^2))+(c(3)*(sind(Refract(5))^2)))*((c(3)*(cosd(Refract(5))^2))+(c(2)*(sind(Refract(5))^2)))-(((c(4)+c(3))^2)*(sind(Refract(5))^2)*(cosd(Refract(5))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(6)) - (sqrt((((c(1)*(cosd(Refract(6))^2))+(c(2)*(sind(Refract(6))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(6))^2))+(c(2)*(sind(Refract(6))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(6))^2))+(c(3)*(sind(Refract(6))^2)))*((c(3)*(cosd(Refract(6))^2))+(c(2)*(sind(Refract(6))^2)))-(((c(4)+c(3))^2)*(sind(Refract(6))^2)*(cosd(Refract(6))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(7)) - (sqrt((((c(1)*(cosd(Refract(7))^2))+(c(2)*(sind(Refract(7))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(7))^2))+(c(2)*(sind(Refract(7))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(7))^2))+(c(3)*(sind(Refract(7))^2)))*((c(3)*(cosd(Refract(7))^2))+(c(2)*(sind(Refract(7))^2)))-(((c(4)+c(3))^2)*(sind(Refract(7))^2)*(cosd(Refract(7))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(8)) - (sqrt((((c(1)*(cosd(Refract(8))^2))+(c(2)*(sind(Refract(8))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(8))^2))+(c(2)*(sind(Refract(8))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(8))^2))+(c(3)*(sind(Refract(8))^2)))*((c(3)*(cosd(Refract(8))^2))+(c(2)*(sind(Refract(8))^2)))-(((c(4)+c(3))^2)*(sind(Refract(8))^2)*(cosd(Refract(8))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(9)) - (sqrt((((c(1)*(cosd(Refract(9))^2))+(c(2)*(sind(Refract(9))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(9))^2))+(c(2)*(sind(Refract(9))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(9))^2))+(c(3)*(sind(Refract(9))^2)))*((c(3)*(cosd(Refract(9))^2))+(c(2)*(sind(Refract(9))^2)))-(((c(4)+c(3))^2)*(sind(Refract(9))^2)*(cosd(Refract(9))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(10)) - (sqrt((((c(1)*(cosd(Refract(10))^2))+(c(2)*(sind(Refract(10))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(10))^2))+(c(2)*(sind(Refract(10))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(10))^2))+(c(3)*(sind(Refract(10))^2)))*((c(3)*(cosd(Refract(10))^2))+(c(2)*(sind(Refract(10))^2)))-(((c(4)+c(3))^2)*(sind(Refract(10))^2)*(cosd(Refract(10))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(11)) - (sqrt((((c(1)*(cosd(Refract(11))^2))+(c(2)*(sind(Refract(11))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(11))^2))+(c(2)*(sind(Refract(11))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(11))^2))+(c(3)*(sind(Refract(11))^2)))*((c(3)*(cosd(Refract(11))^2))+(c(2)*(sind(Refract(11))^2)))-(((c(4)+c(3))^2)*(sind(Refract(11))^2)*(cosd(Refract(11))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(12)) - (sqrt((((c(1)*(cosd(Refract(12))^2))+(c(2)*(sind(Refract(12))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(12))^2))+(c(2)*(sind(Refract(12))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(12))^2))+(c(3)*(sind(Refract(12))^2)))*((c(3)*(cosd(Refract(12))^2))+(c(2)*(sind(Refract(12))^2)))-(((c(4)+c(3))^2)*(sind(Refract(12))^2)*(cosd(Refract(12))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(13)) - (sqrt((((c(1)*(cosd(Refract(13))^2))+(c(2)*(sind(Refract(13))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(13))^2))+(c(2)*(sind(Refract(13))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(13))^2))+(c(3)*(sind(Refract(13))^2)))*((c(3)*(cosd(Refract(13))^2))+(c(2)*(sind(Refract(13))^2)))-(((c(4)+c(3))^2)*(sind(Refract(13))^2)*(cosd(Refract(13))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(14)) - (sqrt((((c(1)*(cosd(Refract(14))^2))+(c(2)*(sind(Refract(14))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(14))^2))+(c(2)*(sind(Refract(14))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(14))^2))+(c(3)*(sind(Refract(14))^2)))*((c(3)*(cosd(Refract(14))^2))+(c(2)*(sind(Refract(14))^2)))-(((c(4)+c(3))^2)*(sind(Refract(14))^2)*(cosd(Refract(14))^2))))))/(2*P))... % ))^2)... % + (((Exp_VT_1_3(15)) - (sqrt((((c(1)*(cosd(Refract(15))^2))+(c(2)*(sind(Refract(15))^2))+c(3)) - sqrt((((c(1)*(cosd(Refract(15))^2))+(c(2)*(sind(Refract(15))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(Refract(15))^2))+(c(3)*(sind(Refract(15))^2)))*((c(3)*(cosd(Refract(15))^2))+(c(2)*(sind(Refract(15))^2)))-(((c(4)+c(3))^2)*(sind(Refract(15))^2)*(cosd(Refract(15))^2))))))/(2*P))... % ))^2)... % + (((Exp_VL_1_3(1)) - (sqrt((((c(1)*(cosd(RefractL(1))^2))+(c(2)*(sind(RefractL(1))^2))+c(3)) + sqrt((((c(1)*(cosd(RefractL(1))^2))+(c(2)*(sind(RefractL(1))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(RefractL(1))^2))+(c(3)*(sind(RefractL(1))^2)))*((c(3)*(cosd(RefractL(1))^2))+(c(2)*(sind(RefractL(1))^2)))-(((c(4)+c(3))^2)*(sind(RefractL(1))^2)*(cosd(RefractL(1))^2))))))/(2*P))... % ))^2)... % + (((Exp_VL_1_3(2)) - (sqrt((((c(1)*(cosd(RefractL(2))^2))+(c(2)*(sind(RefractL(2))^2))+c(3)) + sqrt((((c(1)*(cosd(RefractL(2))^2))+(c(2)*(sind(RefractL(2))^2))+c(3))^2)... % -(4*(((c(1)*(cosd(RefractL(2))^2))+(c(3)*(sind(RefractL(2))^2)))*((c(3)*(cosd(RefractL(2))^2))+(c(2)*(sind(RefractL(2))^2)))-(((c(4)+c(3))^2)*(sind(RefractL(2))^2)*(cosd(RefractL(2))^2))))))/(2*P))... % ))^2)... % + (((Exp_VL_1_2(1))-(sqrt(c(1)/P)))^2)... % + (((Exp_VL_1_2(2))-(sqrt(c(1)/P)))^2)... % + (((Exp_VL_1_2(3))-(sqrt(c(1)/P)))^2)... % + (((Exp_VL_1_2(4))-(sqrt(c(1)/P)))^2)... % + (((Exp_VL_1_2(5))-(sqrt(c(1)/P)))^2)... % + (((Exp_VL_1_2(6))-(sqrt(c(1)/P)))^2)... % + (((Exp_VT_1_2(1))-(sqrt(c(5)/P)))^2)... % + (((Exp_VT_1_2(2))-(sqrt(c(5)/P)))^2)... % + (((Exp_VT_1_2(3))-(sqrt(c(5)/P)))^2)... % + (((Exp_VT_1_2(4))-(sqrt(c(5)/P)))^2)... % + (((Exp_VT_1_2(5))-(sqrt(c(5)/P)))^2)... % + (((Exp_VT_1_2(6))-(sqrt(c(5)/P)))^2)... % + (((Exp_VT_1_2(7))-(sqrt(c(5)/P)))^2)... % + (((Exp_VT_1_2(8))-(sqrt(c(5)/P)))^2)... % + (((Exp_VT_1_2(9))-(sqrt(c(5)/P)))^2)... % + (((Exp_VT_1_2(10))-(sqrt(c(5)/P)))^2)... % + (((Exp_VT_1_2(11))-(sqrt(c(5)/P)))^2)... % ); % %+ (((Exp_VL_1_3(3)) - (sqrt((((c(1)*(cosd(RefractL(3))^2))+(c(2)*(sind(RefractL(3))^2))+c(3)) + sqrt((((c(1)*(cosd(RefractL(3))^2))+(c(2)*(sind(RefractL(3))^2))+c(3))^2)... % % -(4*(((c(1)*(cosd(RefractL(3))^2))+(c(3)*(sind(RefractL(3))^2)))*((c(3)*(cosd(RefractL(3))^2))+(c(2)*(sind(RefractL(3))^2)))-(((c(4)+c(3))^2)*(sind(RefractL(3))^2)*(cosd(RefractL(3))^2))))))/(2*P))... % %))^2)... % %); % % + (((Exp_VL_1_3(4)) - (sqrt((((c(1)*(cosd(RefractL(4))^2))+(c(2)*(sind(RefractL(4))^2))+c(3)) + sqrt((((c(1)*(cosd(RefractL(4))^2))+(c(2)*(sind(RefractL(4))^2))+c(3))^2)... % % -(4*(((c(1)*(cosd(RefractL(4))^2))+(c(3)*(sind(RefractL(4))^2)))*((c(3)*(cosd(RefractL(4))^2))+(c(1)*(sind(RefractL(4))^2)))-(((c(4)+c(3))^2)*(sind(RefractL(4))^2)*(cosd(RefractL(4))^2))))))/(2*P))... % % ))^2)... % % ); % %================== Fminsearch function ======================================================================================== % options = optimset('MaxFunEvals',1000000000000000000000000,'MaxIter',1000000); % sets up some options for the fminsearch function % [c_min,fval,exitflag,options] = fminsearch(Vtest, c_guess,options)% calls the fminsearch function for function vtest and uses c_guess as the initial test paramenters % %================== End of Fminsearch function ================================================================================= % %%%%%%%%%%%%%%%%%%%%%%%% all elastic constants together %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %============================================================================================================================================== %END OF LEAST SQUARES MINIMIZATION STAGE (METHOD 2 - COMMENT OUT IF USING METHOD 1) %==============================================================================================================================================