How can I make a curve fitting using complex custom equation?

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.
Hi Torsten,
Thanks for your comments. Basically, "ST" and "theta_bar1" are my experimental data. I used "sigma" and "theta_bar" to create the independent variables' range. Please see the attachements to give more explanations. I would like to obtain the 2d and 3d figures at the end. Thanks. Hope I answer you correctly.
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 ?
Thanks for getting back to me. The second one is also my concerns about. I am not sure what is the best way using the custom function to fit my measurement data of "ST", "theta_bar1" and "f_exp". What I get from the above is like this using "sigma" and "calculated value". The bubble represents the "ST" vs "f_exp", which are my measurements.
If I use measurement data from "ST", "theta_bar1" and "f_exp", it gives me:
As explained here, I don't think you are plotting what you want to plot.
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.
Hey Cris, I believe you are right! I also agree with @Torsten said. I am think I just think too narrow and trying to get the 2D curve ranther than 3D. And I will look into it. Basically, your results are my goal. Thanks for correcting me and your larger effort on this!
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)
Many thanks Cris! This is really helpful! Like you said, once I have the fit parameters. The problem is these parameters are always assigned by the initial guess. And the code cannot output the optimized fit parameters. I am working on it!
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);
Thanks for this hint, Cris! I can obtain the surface and like this. I think fminsearch function cannot give us the final fit parameters and I believe this surface is generated by the parameters with the defined initial guess value. I need to work on this part. But I can see the hope!

Sign in to comment.

Answers (0)

Categories

Products

Release

R2023a

Asked:

LM
on 18 Apr 2023

Edited:

LM
on 20 Apr 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!