开发者

Matlab lsqcurvefit works for some iterations and then stops on an error

开发者 https://www.devze.com 2023-01-27 21:21 出处:网络
I\'m trying to find optimized parameters for a model defined by an implicit function to fit a dataset using fsolve and lsqcurvefit. I have defined 3 functions in separate m-files: first one is a defin

I'm trying to find optimized parameters for a model defined by an implicit function to fit a dataset using fsolve and lsqcurvefit. I have defined 3 functions in separate m-files: first one is a definition for the implicit function i开发者_开发技巧n 4 parameters to be defined, second one uses fsolve to find the roots of the implicit function defined and the third one uses lsqcurvefit to find optimized values for the four parameters. I naturally need to define good enough initial values for the parameters, but having tried various reasonable combinations, lsqcurvefit always runs for some 20-30 iterations (matlab prints out the vector values calculated with the solution found by fsolve after each iteration) and then prints

No solution found.

fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
default value of the function tolerance.

<stopping criteria details>

??? Error using ==> lsqcurvefit at 253
Function value and YDATA sizes are incommensurate.

Error in ==> optimointi at 5
z = lsqcurvefit('laske_i',parametrit,V_vektori,I_vektori_mitattu,[],[],options);

I can't see how "Function value and YDATA sizes are incommensurate." suddenly, as the iteration first runs for 20-30 times. The values printed after each iteration are pretty much full of zeros (good fit), but the last few 'explode' from 0 to 1 (with a coefficient of several powers of ten). Any help on the error appreciated!


The error lies in how fsolve works. What actually worked was fsolve, but I had to add a for-loop to make the result of fsolve for each element of the domain vector also a vector. This is why Function value and YDATA really were incommensurate.


In my case, the error in lsqcurvefit that said "Function value and YDATA sizes are incommensurate" was due to the vector I was using as Ydata, it was quite a silly thing actually. The vector must be in column form y=[1;2;3], not like y=[1 2 3].That was causing the problem in lsqcurvefit, because the xdata were like columns too

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号