This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/regression/code/lsqGradient.m

18 lines
626 B
Matlab

function gradient = lsqGradient(x, y, parameter)
% The gradient of the least square error
%
% Arguments: x, the input values
% y, the corresponding measured output values
% parameter, vector containing slope and intercept
% as the 1st and 2nd element
%
% Returns: the gradient as a vector with two elements
h = 1e-6; % stepsize for derivatives
partial_m = (lsqError(x, y, [parameter(1)+h, parameter(2)]) - lsqError(x, y, parameter))/ h;
partial_n = (lsqError(x, y, [parameter(1), parameter(2)+h]) - lsqError(x, y, parameter))/ h;
gradient = [partial_m, partial_n];
end