Least Square Method adaptation

2 ビュー (過去 30 日間)
Erik
Erik 2014 年 4 月 23 日
回答済み: Niklas Nylén 2014 年 4 月 23 日
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

採用された回答

Niklas Nylén
Niklas Nylén 2014 年 4 月 23 日
The code you provided seems to be in Octave, not MATLAB syntax.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEncryption / Cryptography についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by