function f = fnctnls(xtest); % This is the function modeled on fitdemo: % a nonlinear least squares problem % The model is % % y_model = c(1)*exp(-lam(1)*t) + c(2)*exp(-lam(2)*t) % + ... c(my_n/2) exp(-lam(my_n/2)*t) % % The data is given as (t, y(t)) in the array my_Data, % and the vector xtest contains lam as the first my_n/2 % components and c as the last my_n/2. % The residual is the vector my_Data(:,2)-y_model, and % the function value is the norm of this vector. global my_Data my_n f = norm(my_Data(:,2) - ... exp(-my_Data(:,1)*xtest(1:my_n/2,1)')*xtest(my_n/2+1:my_n,1), 2)^2;