using lsqnonlin function returns not a vector

1 回表示 (過去 30 日間)
Devyani
Devyani 2014 年 10 月 19 日
コメント済み: Matt J 2015 年 4 月 18 日
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 Center および File ExchangeSparse Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by