Least Square Method adaptation
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi i seem to have difficulties to understand how least square method works. I would appreciate if i could get help understanding what is wrong with this code, and suggestion on how to change it. I have tried to change it a lot of times but it never seem to work.
Note: its been a while since I have used matlab and it worked a year ago, som my guess is the language have changed.
thanks in advance.
function[A Deltapar] = MKA(x,y,deltay,n)
A = [];
Deltapar = [];
X=[];
%------------------------------------------------------------------------------------------------------------------ % checking if the size of the matrix is correct for indata
if (size(x,2)=1)
x=x';
endif
if (size(y,2)=1)
y=y';
endif
if(size(deltay,2)=1)
deltay=deltay';
endif
%------------------------------------------------------------------------------------------------------------------
% Checking if the matrix x and y and delta y have the correct size and after that executing least square method adaptation f
if(size(x)(2)==1 && size(y)(2) ==1 && size(deltay)(2)==1)
%------------------------------------------------------------------------------------------------------------------ % Conducting weighted least squares fit on the matrices x and y have the same format.
% If not, a message is returned back an x and y are not the same length.
if(length(x)==length(y))
for i=0:n
X=[X x.^i];
endfor
sigma=deltay;
vminus1 = diag(1./sigma.^2);
A = inv(X' * vminus1 * X) * (X' * vminus1 * y);
DeltaA = inv(X' * vminus1 * X);
Deltapar = sqrt(diag(DeltaA));
endif
disp('x,y har inte samma langd');
end %------------------------------------------------------------------------------------------------------------------ % Print "you did not write the input data on the correct form"
endif disp('you have not written the input data on the correct form'); end
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!