%% Gauss-Newton: ejemplo clear clc close all f = @(t,x1,x2) x1*exp(x2*t); t = [0;1;2;3]; y = [2; 0.7; 0.3; 0.1]; tol = 1e-6; k = 0; x = [1; 0]; d = inf; while norm(d)>tol && k < 10 r = y - f(t, x(1), x(2)); A = [exp(x(2)*t) x(1).*t.*exp(x(2)*t)]; % cond(A'*A) d = (A'*A)\(A'*r); % ya me fije que el sistema queda bien condicionado!! x = x + d k = k+1; end vec = linspace(0,4); plot(t,y,'ok','LineWidth',2); hold on plot(vec,f(vec, x(1), x(2)), '-b', 'LineWidth',2); grid on xlabel('t', 'FontSize',14) ylabel('y', 'FontSize',14)