Error in lsqcurvefit with 3 unknown parameters involved

2 views (last 30 days)
lvenG on 20 Oct 2021
Commented: lvenG on 20 Oct 2021
Hi. Would like to ask for any enlightenment here. I am using lsqcurvefit as a curvefitting method.... However, I could't decipher how the error keeps on appearing on the parameters even if I changed the values. As you can see below, the resulting equation is:
but it should be . Hence the error regarding array.
Hoping for some help here. Thank you.
syms i_x
syms parameter [1 2 3]
YYHCl = 
obj=@(P4,I_x) arrayfun(@(i_x) fun4(P4,i_x), I_x);
Index exceeds the number of array elements. Index must not exceed 1.

Error in symengine>@(in1,i_HCl)exp(i_HCl.*in1(3)-in1(1)./in1(2))

Error in solution (line 14)
obj=@(P4,I_HCl) arrayfun(@(i_HCl) fun4(P4,i_HCl), I_HCl);

Error in solution (line 14)
obj=@(P4,I_HCl) arrayfun(@(i_HCl) fun4(P4,i_HCl), I_HCl);

Error in lsqcurvefit (line 225)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});

Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
plot(I_HCl, Y_HCl, 'k*', I_HCl, Y_HCl_calcc, 'g-o')
legend({'Y_HCl exp)', 'Y_HCl calc)'}, 'location', 'best')

Accepted Answer

Matt J
Matt J on 20 Oct 2021
If your model has 3 unknown parameters, then your initial guess P40 must be a vector of length 3.
  1 Comment
lvenG on 20 Oct 2021
Thank you so much that finally made sense, didn't realize it at first.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!