using lsqnonlin function returns not a vector

5 次查看(过去 30 天)
I am trying to find 10 parameters value using lsqnonlin. My function returns a 10*10 matrix. each column is the set of data that has to be summed and squared and give one parameter value.Is it possible to do it with lsqnonlin? my function is as follows:
function r = calcResiduals(parVector, settingsStruct)
for i = 1 : size(settingsStruct.expConditions,1) % loop through all experiments
conc = getconc(settingsStruct.expConditions(i,:),parVector);
for j=1:10
r1 = conc(:,j)-settingsStruct.measurementData(:,i);
r(:,j)=r1;
end
end
end
i am calling lsqnonlin as follows:
settingStruct.expConditions=[5 5 50];
settingStruct.measurementData=[5;4;3;2;1;0;0.9;0.8;0.7;0.6];
parVector=[1 1 1 1 1 1 1 1 1 1];
lsqnonlin(@calcResiduals,parVector,[],[],[],settingStruct)
|* _i am gtting error as follows :_ *|
Warning: Failure at t=2.879119e+000. Unable to meet integration tolerances without
reducing the step size below the smallest value allowed (7.105427e-015) at time t.
> In ode45 at 309
In getconc at 21
In calcResiduals at 5
In snls at 333
In lsqncommon at 175
In lsqnonlin at 237
In ModelDiscrimination at 68
Error using horzcat
CAT arguments dimensions are not consistent.
Error in getconc (line 27)
conc=[cout1(:,1) cout2(:,1) cout3(:,1) cout4(:,1) cout5(:,1) cout6(:,1) cout7(:,1)
cout8(:,1) cout9(:,1) cout10(:,1)];
Error in calcResiduals (line 5)
conc = getconc(settingsStruct.expConditions(i,:),parVector);
Error in snls (line 333)
newfvec = feval(funfcn{3},xcurr,varargin{:});
Error in lsqncommon (line 175)
[xC,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msgData]=...
Error in lsqnonlin (line 237)
[xCurrent,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...

回答(1 个)

Matt J
Matt J 2014-10-19
编辑:Matt J 2014-10-19
lsqnonlin doesn't care what shape your residual array, r, has. It will always be internally columnized to r(:), see
As for the error, it is because the different column vectors cout?(:,i) are not all the same length in
conc=[cout1(:,1) cout2(:,1) cout3(:,1) cout4(:,1) cout5(:,1) cout6(:,1) cout7(:,1)
cout8(:,1) cout9(:,1) cout10(:,1)];
So, they cannot be concatenated.
  4 个评论
Devyani
Devyani 2014-10-19
i changed the tolerance for ode to 1e-2 then it is solving and showing results... thanks
Matt J
Matt J 2015-4-18
@PATHAN,
Your question looks to be completely unrelated to this thread, so you should probably start your own. However, a common reason why the initial point is a local min is because of quantization operations like round(), fix(), floor() in your objective function. There are rules about the kind of objective functions you can have.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by