How can I make a curve fitting using complex custom equation?
Show older comments
Hello guys,
I am trying to fit the data using a complex custom equation as shown below.
owever, I need your help on error (should be less than 5% == good fit, right?) and please help me with writing the error functions. Here is my code and please correct me how to do a good fit and output the "model parameters are b0,gamma,a,c,n" Thanks!!!
% Load experimental data
data2fit2 = xlsread('data2fit2.xlsx');
ST = data2fit2(:,1);
theta_bar1 = data2fit2(:,2);
f_exp = data2fit2(:,3);
sigma = [linspace(-0.5,2,100)];
theta_bar = [linspace(-1,1,100)];
% Define the initial guess for the parameters to be optimized
params0 = [0.417257,0.04132,0.001177,0.00961,1.946234];
% Define the objective function to be minimized
objective_func = @(params) norm(f_exp - fitfun(params, sigma, theta_bar));
% Call the lsqcurvefit function to optimize the parameters
params_fit = lsqcurvefit(objective_func, params0, ST, theta_bar1);
% Evaluate the fitted function using the optimized parameters
y_fit = fitfun(params_fit, ST, theta_bar1);
% Plot fracture criterion
figure;
plot(ST, f_exp, 'o', sigma, hosford_coloumb_f, '-')
xlabel('Stress Triaxiality [-]')
% ylabel('Lode Angle Parameter [-]')
ylabel('Equivalent Plastic Strain at Fracture [-]')
% Define the custom function to be fit
function hosford_coloumb_f = fitfun(params, sigma, theta_bar)
epsilon_p = 100;
epsilon_0 = 0.0005;
b0 = params(1);
gamma = params(2);
c = params(3);
n = params(4);
a = params(5);
if epsilon_p < epsilon_0
b = b0;
else
b = b0*(1 +gamma*log(epsilon_p/epsilon_0));
end
% Define Lode-dependent functions
f1 = (2/3)*cos((pi/6)*(1-theta_bar));
f2 = (2/3)*cos((pi/6)*(3+theta_bar));
f3 = -(2/3)*cos((pi/6)*(1+theta_bar));
% Define the Hosford-Coloumb fracture model equation
Strain_rate_term = b*(1+c).^(1./n);
Lode_dependent_term = ((1/2).*((f1-f2).^a+(f2-f3).^a+(f1-f3).^a)).^(1./a);
Triaxiality_term = c.*(2*sigma+f1+f3);
hosford_coloumb_f = Strain_rate_term.* (Lode_dependent_term + Triaxiality_term).^(-1./n);
end
10 Comments
I don't understand why you use "sigma" and "theta_bar" as the input arguments to "fitfun" and not "ST" and "theta_bar1" which seem to be the correct independent variables that lead to the f_exp measurements.
And I don't understand how you want to use the measurement data for fitting that have the same inputs for "ST" and "theta_bar1", but different outputs for f_exp.
LM
on 18 Apr 2023
But you can't use arbitrary variables for sigma and theta_bar for the fitting. You must use those values for sigma and theta_bar from which f_exp resulted, and these are the data from the Excel file, I guess. And the second problem I mentionned remains: how do you want to treat measurement data with the same input values for sigma and theta_bar, but different output values for f_exp, especially if you have so many of them ?
Cris LaPierre
on 19 Apr 2023
Edited: Cris LaPierre
on 19 Apr 2023
Once I correct fminsearch, this is the result I get.

It doesn't have the shape you want, but the resulting parameters do create a good fit to the few datapoints you do have.

However, if I now plot the same data used to calculate the line in the first figure and superimpose it on this surface, it is just a diagonal running from one corner to the other (red line below).

So I believe the equations you have shared so far are correct, but for creating this surface. You still haven't explained how to create the Effect of Strain Rate on Failure Strain plot. However, this is not my area of expertise, so you will need to tell us how they are created.
LM
on 19 Apr 2023
Cris LaPierre
on 19 Apr 2023
You've got this conversation spread across 2 questions. Since the other one already has an accepted answer, I propose keeping the conversation about the open question here.
Once you have your fit parameters, creating the surface would look like this. Note that you do not need any of these variables to perform your fit.
sigma = [linspace(-0.5,2,20)]; % you don't need 100
theta_bar = [linspace(-1,1,20)];
[Sx,TBy] = meshgrid(sigma,theta_bar);
EFz = epsilon_f_of_sigma(Sx,TBy,par);
surf(Sx,TBy,EFz)
LM
on 19 Apr 2023
Cris LaPierre
on 19 Apr 2023
Perhaps a hint then. Here is how I set up fminsearch. Note that this approach uses the current parameter guess to compute the Z values with epsilon_f_of_sigma. I did simplifly err_fcn for testing purposes.
par = fminsearch(@(par) err_fcn(par,f_exp,epsilon_f_of_sigma(ST,theta_bar1,par)),par0);
Answers (0)
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



