Curve fitting for 4 independent variables

3 views (last 30 days)
Yogesh
Yogesh on 26 Sep 2023
Edited: Matt J on 26 Sep 2023
I have the following experimental data (attached xlsx file). I am trying to fit the experimental stress data, which are denoted by predicted_experimentalstress, to the analytical equivalent (Gent model) with four independent variables to be evaluated based on the experimental stretch data. However, the following code using Fmincon doesn't work for more than two variables. Could you please suggest me a way to modify the code to evaluate the four variables from the curve fitting?
data = xlsread('Roundtissuedata.xlsx');
strain_extensometer= data((2:454),2);
time_DIC= data((2:454),1);
experimentalstress_original= data((2:755),9);
time_utm= data((2:755),6);
[F,TF] = fillmissing(strain_extensometer,'linear','SamplePoints',time_DIC);
Filled_stretchextensometer= F+1;
hold on
predicted_experimentalstress= interp1(time_utm,experimentalstress_original,time_DIC,"linear","extrap");
J = @(x,Filled_stretchextensometer) exp((((-x(1)./2).*(x(2)).*(log(x(2)-(Filled_stretchextensometer.^2+(2./Filled_stretchextensometer)-3))./x(2))).^x(3)).*((x(4)).^(-x(3)))).*((x(1).*x(2)*(Filled_stretchextensometer-(1./Filled_stretchextensometer.^2))).*(x(2)./(x(2)-(Filled_stretchextensometer.^2+(2./Filled_stretchextensometer)-3))));
residue_function = @(x) sum(((exp((((-x(1)./2).*(x(2)).*(log(x(2)-(Filled_stretchextensometer.^2+(2./Filled_stretchextensometer)-3))./x(2))).^x(3)).*(x(4)).^(-x(3))).*((x(1).*x(2)*(Filled_stretchextensometer-(1./Filled_stretchextensometer.^2))).*(x(2)./(x(2)-(Filled_stretchextensometer.^2+(2./Filled_stretchextensometer)-3)))) - predicted_experimentalstress).^2));
x0 = [49,2,10,12];
gs = GlobalSearch;
problem = createOptimProblem('fmincon', 'x0', x0, 'objective', residue_function, 'lb', [-inf 0]);
[x, resnorm] = run(gs,problem)
Warning: Length of lower bounds is < length(x); filling in missing lower bounds with -Inf.
Error using barrier
Objective function is undefined at initial point. Fmincon cannot continue.

Error in fmincon (line 891)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...

Error in globaloptim.globalsearch.globalsearchnlp

Error in GlobalSearch/run (line 340)
globaloptim.globalsearch.globalsearchnlp(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON,options,localOptions);

Caused by:
Error in initial call to fmincon with supplied problem structure.
lb = [];
ub = [];
fprintf(['The value of x(1)%f.\n'],x(1));
fprintf([ 'The value of x(2)%f.\n'],x(2));
fprintf([ 'The value of x(3)%f.\n'],x(3));
fprintf([ 'The value of x(4)%f.\n'],x(4));
fprintf(['The value of resnorm %f.\n'], resnorm);
times = linspace(Filled_stretchextensometer(3),Filled_stretchextensometer(end));
plot(Filled_stretchextensometer, predicted_experimentalstress, times, J(x, times), 'r-');
legend('Experiment', 'Fitted curve(Gent Model)');
title('Fresh 5');
xlabel('Stretch');
ylabel('Engineering Stress (KPa)');

Answers (1)

Matt J
Matt J on 26 Sep 2023
Edited: Matt J on 26 Sep 2023
If you have four unknown variables, you need four lb(i). Upper bounds would also help.
Also, you should address the fact that your x0 evaluates to Inf.
>> residue_function([49,2,10,12])
ans =
Inf

Categories

Find more on Fit Postprocessing in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!