Curve fitting toolbox error "NaN computed by model function, fitting cannot continue"

Hello,
I have a set of experimental data on which i am trying to fit 5 analytical functions (Hyperelastic models) using Levenberg-Marquardt algorithm. The models are as follows:
1) Neo-Hookean: y=2*c1*(x^2-1/x)
2) Yeoh: y=2*(x^2-1/x)*(c1+2*c2*(x^2+2/x-3)+3*c3*(x^2+2/x-3)^2)
3) Mooney-Rivlin: y=2*(x^2-1/x)*(c1+c2/x)
4) Ogden-N3: y=c1*(x^c2-2^(-1+c2)*x^(-c2/2))+c3*(x^c4-2^(-1+c4)*x^(-c4/2))+c5*(x^c6-2^(-1+c6)*x^(-c6/2))
5) Humphrey: y=2*(x^2-1/x)*c1*c2*exp(c2*(x^2+2/x-3))
The data file is attached so you can simply use the custom equation, use the above analytical functions, in the curve fitting toolbox.
clc; clear all; close all;
A = readmatrix('Specimen_mean.csv');
Xdata = A(:,1); % stretch [mm/mm]
Ydata = A(:,2); % Stress [Pa]
The 1,2 and 3 fit very well, though 4 and 5 cannot be fit to the data. The 4 gives the error "NaN computed by model function, fitting cannot continue" and the 5 gives the message "Fit computation did not converge". I have no idea how to deal with the mentioned problems. Any help would be highly appreciated.
Sincerely
Masoud

6 commentaires

Hi, It is very likely that it is caused by your unreasonable guessing of initial start values for each parameter, refering to the results below:
4) Ogden-N3:
Root of Mean Square Error (RMSE): 1423.18186169142
Sum of Squared Residual: 364580390.060542
Correlation Coef. (R): 0.999946452632523
R-Square: 0.999892908132366
Parameter Best Estimate
---------- -------------
c1 -61049.116009665
c2 3.59112566549972
c3 65238.8770597832
c4 3.56032628280848
c5 48597.4475162964
c6 0.325066948373278
5) Humphrey
Root of Mean Square Error (RMSE): 4036.17249012034
Sum of Squared Residual: 2932323906.60076
Correlation Coef. (R): 0.999573161635061
R-Square: 0.999146505461111
Parameter Best Estimate
---------- -------------
c1 -1519375.72696327
c2 -0.0058933760536844
Dear Alex, thank you so much for the help. By the initial values, you mean the "StartPoint" of the coefficients? Then Could you please tell me the initial values you chose for them? And what is the criteria of choosing the initial values? I mean for a model with 6 coefficients, how should i change the initial values of the coefficients to hit the correct ones?
Hi, manually guessing of startpoints is always an extreamly hard task, unfortunatly, most of fitting tools (including Matlab) heavely depend on the goodness of guessing.
The results shown above are obtained by one another package other than Matlab, the step for guessing startpoints is no longer required anymore, all are done by package itself.
You may try the global optimization toolbox in Matlab, theorically,the tools with global optimization algorithms are not need to provide start-values.
Thank you so much Alex! I used the Multistart command in global optimization toolbox and solved the issue. However, it again needs some experience in defining the initial values, lower and upper bounds.
What i did was to use the multistart to find the X0 values and then used those X0 in curve fitting toolbox to fit the hyperelastic models using the levenberg algorithm. I know the global optimization calcualtes the models coefficients but i wanted to use the levenberg algorithm. that's why i used both global optimization and curve fitting tool boxes. Do you think the way i did it is ok? I mean if it is scientifically ok?
%% Humphrey
model = @(c,x) 2*(x.^2-x.^(-1))*c(1)*c(2).*exp(c(2)*(x.^2+2*x.^(-1)-3))
problem = createOptimProblem('lsqcurvefit',...
'objective',model,'xdata',xData','ydata',yData','x0',[-1e6 -1e-3],'lb',[-1e7 -1],...
'ub',[1e7 1])
b = lsqcurvefit (problem)
ms = MultiStart
[b,fval,exitflag,output,solutions] = run (ms,problem,50)
I am not sure why you didn't use the Levenberg-Marquardt algorithm in lsqcurvefit when running MultiStart. That might save a step (no curve fitting toolbox needed).
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt');
problem = createOptimProblem('lsqcurvefit',...
'objective',model,'xdata',xData','ydata',yData','x0',[-1e6 -1e-3],'lb',[-1e7 -1],...
'ub',[1e7 1],'options',options);
Alan Weiss
MATLAB mathematical toolbox documentation
Oh! Thanks Alan. You saved my time. I made it hard for myself.
It is now working very well. I appreciate your help.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange

Produits

Version

R2021a

Commenté :

le 16 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by