RESU = [
//1,0;
0.99,-0.021732882;
0.98,-0.033976269;
0.97,-0.036566652;
0.96,-0.06467633;
0.95,-0.072344532;
0.94,-0.101610874;
0.93,-0.169098626;
0.92,-0.220626222;
0.91,-0.288628719;
0.9,-0.34254837;
0.89,-0.420396144;
0.88,-0.479622221;
0.87,-0.53212632;
0.86,-0.572882097;
0.85,-0.630563936;
0.84,-0.686731816;
0.83,-0.728819877;
0.8,-0.859928729;
0.79,-0.908981002;
0.78,-0.956519316;
0.77,-0.979228701;
0.76,-1.024041888;
0.75,-1.067341117;
0.74,-1.103524737;
0.73,-1.118452373;
0.72,-1.152183381;
0.71,-1.225398439;
0.7,-1.239932446;
0.69,-1.295343347;
0.68,-1.297160097;
0.67,-1.359232418;
0.66,-1.398898144;
0.65,-1.456428587;
0.64,-1.492158021;
0.63,-1.506994819;
0.62,-1.605099364;
0.61,-1.653091866;
0.6,-1.67141077;
0.59,-1.741809865;
0.58,-1.76672963;
0.57,-1.829468093;
0.56,-1.890632037;
0.55,-1.931811723;
0.54,-2.060195449;
0.53,-2.094259527;
0.52,-2.141343653;
0.51,-2.246866597;
0.5,-2.308787522;
];
[Line_number,columne_number]=size(RESU);

// Function to fit with 2 parameters C10 & C01
function sigma = mooney_rivlin(lambda,parameters)
  C10 = parameters(1)
  C01 = parameters(2)
  sigma  = 2 * ( lambda^2 - (1 / lambda) ) * ( C10 + (C01 / lambda) )
endfunction  


// function descriptor
function e = G(parameters,measured)
  lambda_measured = measured(1)
  sigma_measured = measured(2)
  e = sigma_measured - mooney_rivlin(lambda_measured,parameters) 
endfunction

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// measured(2) = measured sigma
// measured(1) = measured lambda
// deff = (measured SIGMA - calculated SIGMA)
// deff('[e]=G(param,measured)','e=measured(2)- 2*(measured(1)^2 - 1/measured(1))*(param(1) + param(2)/measured(1))')


// Solve the problem
parameters_init = [1 ; 0]
[parameters_opti,err] = datafit(G,RESU',parameters_init)


// Drawing of the experimental data & the fitted curve
sigma_calc = zeros(Line_number,1);
for i = 1 : Line_number
  sigma_calc(i,1) = mooney_rivlin(RESU(i,1),parameters_opti);
end;

clf(0)
plot2d(RESU(:,1),RESU(:,2),style=-2)          // attention bien le placer apr�s sinon la l�gende n'apparait pas
plot2d(RESU(:,1), sigma_calc, style = 2)
legend(["Experimental data", "fitted curve"],2);
xtitle("Mooney-Rivlin fitted curve")
