TomSym Least squares example
From TomWiki
Jump to navigationJump to search
This page is part of the TomSym Manual. See TomSym Manual. |
% Data from Yalmip example
x = [1 2 3 4 5 6]';
t = (0:0.02:2*pi)';
a = [sin(t) sin(2*t) sin(3*t) sin(4*t) sin(5*t) sin(6*t)];
e = (-4+8*rand(length(a),1));
e(100:115) = 30;
y = a*x+e;
% Define the decision variable
toms 6x1 x_hat
% x_hat and the regressors a define the residuals with y
residuals = y-a*x_hat;
%The L2 problem is solved as a QP problem without any constraints.
options = struct;
options.norm = 'L2';
solution = ezsolve(residuals,[],[],options);
plot(t,subs(a*x_hat,solution),'-',t,y,'.')
Problem type appears to be: cls clsAssign: WARNING - empty y, e.g. solver NLSSOL will not work Time for symbolic processing: 0.037954 seconds Starting numeric solver The problem has 6 variables (Columns), slsSolve adds unbounded variables (Columns) 7 to 321 These extra variables is the objective residual values The problem has 0 linear constraints (Rows) The problem has 0 nonlinear constraints (Rows) The problem has 315 residuals, by slsSolve defined as constraint (Row) 1 to 315 ===== * * * =================================================================== * * * TOMLAB - TOMLAB Development license 999007. Valid to 2011-12-31 ===================================================================================== Problem: --- 1: Problem 1 f_k 6110.439351709240300000 sum(|constr|) 0.000000000000353162 f(x_k) + sum(|constr|) 6110.439351709240300000 f(x_0) 15056.768801840182000000 Solver: snopt. EXIT=0. INFORM=1. SNOPT 7.2-5 NLP code Optimality conditions satisfied ResEv 4 JacEv 4 Iter 3 MinorIter 10 CPU time: 0.015600 sec. Elapsed time: 0.006000 sec.