How can I make a curve fitting using complex custom equation?
    4 次查看(过去 30 天)
  
       显示 更早的评论
    
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 个评论
  Cris LaPierre
    
      
 2023-4-19
				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);
回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!










