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
648 B
Matlab

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