How to perform non linear least square regression of eigenvalues of a matrix (matrix elements being some function of independent variable and parameters to be optimized)?

1 次查看(过去 30 天)
Hi, I am a beginner in MATLAB and struggling with this one code. I have a (4x4) matrix whose elements are function of independent variable and parameters (say a,b,c are parameters) and x is independent variable. e.g. M= [a+b*exp(x*b),c*b*exp(x*c)....;c+a*exp(x*b)....] the eigenvalues of this matrix are y(dependent variables) I want to fit my data to.
I have the data set Xexp=[x1,x2,x3......] and Yexp=[y1,y2....]
I am trying to fit the data set (X,Y) to the eigenvalue "y" (say 2nd eigenvalue) of the matrix (M) using "lsqnonlin" where at the end of the function program I calculate "Y-y" so as to be minimized by the lsqnonlin e.g.
phiLSQ= lsqnonlin(@(phi) lambdafn(phi), initial_param); %command to start regression in main program
function LErr = lambdafn(phi) %start of the function
I am providing the data set (X,Y) in function program itself.
when I run the script I get following error
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in lambdafn (line 31)
Q=[a+b*exp(x*b),c*b*exp(x*c)....;c+a*exp(x*b)....] ; %the complete matrix
Error in @(phi)lambdafn(phi)
Error in lsqnonlin (line 194)
initVals.F = feval(funfcn{3},xCurrent,varargin{:});
Error in lambda (line 32)
phiLSQ= lsqnonlin(@(phi) lambdafn(phi), initial_param);
Caused by:
Failure in initial user-supplied objective function evaluation. LSQNONLIN cannot continue.
Thanks

采纳的回答

Matt J
Matt J 2017-1-12
编辑:Matt J 2017-1-12
You should test lambdafn(phi) before you feed it to lsqnonlin to make sure it works, i.e., that it always runs without error messages and returns a finite, real value. LSQNONLIN is complaining that it doesn't.
  7 个评论
Vipultomar
Vipultomar 2017-1-13
As I am giving as input the entire row of xdata, the program is trying to calculate the matrix elements first, and then eigenvalues to be given as output (y) for minimization. The problem I think is that the code is taking the entire row of xdata at once and then processing according to..
Q=[a+b*exp(x*b),c*b*exp(x*c)....;c+a*exp(x*b)....]
after which I calculate my eigencalues. because each element of matrix is being generated for each xdata value, there is problem with concatenation. On the other hand if I try to take just one element of matrix as my function operator (just to check) or just one value of xdata, it works fine.
Vipultomar
Vipultomar 2017-1-13
编辑:Vipultomar 2017-1-13
As I mentioned the program was not taking complete xdata row, I have started a for loop in the function itself. In this way the function calculates the value of y from the model (function) and keeps putting them in a row vector. Finally the entire row vector is output of the function (for lsqcurvefit). And so its working now. Although there is no change in parameter values with each step (which I think should be unrelated to it) so trying to correct that.
Thanks

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Least Squares 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by