我正在尝试为隐式函数定义的模型找到优化参数,以使用fsolve和lsqcurvefit来拟合数据集。我在单独的m文件中定义了3个函数:第一个是要定义的4个参数中隐式函数的定义,第二个使用fsolve查找定义的隐式函数的根,第三个使用lsqcurvefit查找优化值对于四个参数。我自然需要为参数定义足够好的初始值,但尝试了各种合理的组合,lsqcurvefit总是运行大约20-30次迭代(matlab打印出每次迭代后用fsolve找到的解决方案计算出的矢量值)然后打印
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);
我看不出“功能值和YDATA尺寸是如何不相称的”。突然,迭代首次运行20-30次。每次迭代后打印的值几乎都是零(良好拟合),但最后几个“爆炸”从0到1(系数为10的几个幂)。任何有关错误的帮助表示赞赏!
答案 0 :(得分:0)
错误在于fsolve的工作原理。实际工作的是fsolve,但是我必须添加一个for循环来使域向量的每个元素的fsolve结果也成为一个向量。这就是为什么功能值和YDATA真的不相称的原因。
答案 1 :(得分:0)
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