Least Square Method adaptation

1 view (last 30 days)
Erik on 23 Apr 2014
Answered: Niklas Nylén on 23 Apr 2014
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 = [];
%------------------------------------------------------------------------------------------------------------------ % checking if the size of the matrix is correct for indata
if (size(x,2)=1)
if (size(y,2)=1)
% 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.
for i=0:n
X=[X x.^i];
vminus1 = diag(1./sigma.^2);
A = inv(X' * vminus1 * X) * (X' * vminus1 * y);
DeltaA = inv(X' * vminus1 * X);
Deltapar = sqrt(diag(DeltaA));
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

Accepted Answer

Niklas Nylén
Niklas Nylén on 23 Apr 2014
The code you provided seems to be in Octave, not MATLAB syntax.

More Answers (0)


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!