필터 지우기
필터 지우기

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)?

조회 수: 2 (최근 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