source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/demos/nonlinex.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 1.7 KB
Line 
1clc
2echo on
3
4% Starting from YALMIP version 3, polynomial expressions are supported.
5%
6% These nonlinear expressions can be used for, e.g.
7% SDPs with BMI constraints, or to solve sum-of-squares problems
8%
9% The nonlinear expressions are built up from sdpvar objects,
10% and are manipulated in same way
11pause % Strike any key to continue.
12yalmip('clear')
13clc
14
15% To begin with, define a scalar variable
16x = sdpvar(1,1);
17pause % Strike any key to continue.
18
19% Nonlinear expressions are easily built
20p = 1+x+x^2+x^3;
21pause % Strike any key to continue.
22
23% Matrices can also be nonlinear
24Y = sdpvar(3,3);
25Z = Y*Y+Y.*Y;
26pause
27
28% Polynomials are displayed without any symbolic information...
29y = sdpvar(1,1);
30p = x*x+y^4+x*y
31pause
32
33% But can be displayed better with the command sdisplay
34% (this only works if the involved variables are explictely
35% defined as scalars)
36sdisplay(p)
37pause
38
39% Polynomials can be diffrentiated
40dp = jacobian(p);
41sdisplay(dp)
42pause
43
44% ...w.r.t a specific variable
45dp = jacobian(p,y);
46sdisplay(dp)
47pause
48
49
50% ...why not twice
51sdisplay(jacobian(jacobian(p)'))
52pause
53
54% ...or
55sdisplay(hessian(p))
56pause
57
58% Of course, all standard linear operators applies
59% to the nonlinear objects
60x = sdpvar(3,1);
61p = trace(x*x') + sum(x.^2)
62pause
63
64clc
65% Finally, a word of caution. Use yalmip('clear')
66% while working with polynomial expressions.
67%
68% The reason is that every time a nonlinear variable is
69% defined, a description on how it is created is
70% saved inside YALMIP. With many nonlinear terms
71% this list grows fast, making YALMIP slower and slower
72% since the list has to be searched in when polynomial
73% expressions are manipulated.
74%
75% (after this short session, there are already 27 nonlinear terms)
76pause
77echo off
Note: See TracBrowser for help on using the repository browser.