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

9 views (last 30 days)
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
Cris LaPierre
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);
LM
LM on 20 Apr 2023
Edited: LM on 20 Apr 2023
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)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!