TomSym Least squares example

From TomWiki
Revision as of 17:01, 2 November 2011 by Mbot (talk | contribs) (Created page with "{{Part Of Manual|title=the TomSym Manual|link=TomSym Manual}} <source lang="matlab"> % Data from Yalmip example x = [1 2 3 4 5 6]'; t = (0:0.02:2*pi)'; a = [sin(t) si...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Notice.png

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.071521 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    5961.234750551501700000
                                       sum(|constr|)      0.000000000000379391
                              f(x_k) + sum(|constr|)   5961.234750551501700000
                                              f(x_0)  14525.935903875441000000

Solver: snopt.  EXIT=0.  INFORM=1.
SNOPT 7.2-5 NLP code
Optimality conditions satisfied

ResEv     4 JacEv     4 Iter    3 MinorIter   10
Elapsed time: 0.025000 sec. 

Tomsym curvefit 01.png