I implemented a constitutive model for the bovine pericardium to be fit with experimental data to derive four model parameters. The code runs, but I have doubts about the correct implementation of the error function. Showing the iterations on the screen, I notice that at certain points the objective function returns nan or inf. I have checked the experimental data and in some cases there are values close to zero, but I don't think this justifies the fact that the function converges, thus giving me the 4 parameters I am looking for, but without obtaining a decent fitting with the experimental data. Moreover, optimized parameters number 2 and 3 are assigned to lower bounds, while the first optimized parameter is very high. Below is the main and the error function.
Main:
clc; clear all;close all;
p_initial=[0.5 0.5 0.5 0.5];
options = optimoptions('lsqnonlin', 'Display', 'iter', 'Algorithm','levenberg-marquardt');
[p_opt, resnorm] = lsqnonlin(@(p) error_function(p,strain,stress,a0), p_initial,lb,ub,options);
I4 = sum(sum(C .* prod));
sigma = 2 * f * (c / 2 * I + k1 * (1 - zeta)^2 * (I4 - 1) * (exp(k2 * ((1 - zeta) * (I4 - 1))^2))) * prod .* f';
sigma_calculated(i)= sigma(1,1);
plot(strain, sigma_calculated,'r');
legend ('experimental', 'model','Location', 'northwest');
Error function:
function error = error_function(p,strain,stress,a0,k)
sigma_calculated = zeros(length(strain), 1);
sigma = 2 * f * (p(1) / 2 * I + p(2) * (1 - p(4))^2 * (I4 - 1) * (exp(p(3) * ((1 - p(4)) * (I4 - 1))^2)) * prod) .* f';
sigma_calculated(i)= sigma(1,1);
error= sum((sigma_calculated(i) - stress(i))^2);