|
| 1 | +\begin{tikzpicture} |
| 2 | + %axes |
| 3 | + \begin{scope}[->,>=latex] |
| 4 | + \draw (-1,0) -- (6,0) node[below] {$x_1$}; |
| 5 | + \draw (0,-0.5) -- (0,4) node[left] {$x_2$}; |
| 6 | + \end{scope} |
| 7 | + \coordinate (xu) at (2.5,2); %unconstrained optimum |
| 8 | + \coordinate (xc) at (2.837,1.0427); %constrained optimum |
| 9 | + \coordinate (g) at (2.837+0.3527,1.0427-1); |
| 10 | + \begin{scope}[shift={(xu)},rotate=-45] |
| 11 | + %unconstrained optimum |
| 12 | + \filldraw (xu) circle (1pt) node[above] {$\vect{x}_u$}; |
| 13 | + %constrained optimum |
| 14 | + \filldraw (xc) circle (1pt) node[above] {$\vect{x}_c$}; |
| 15 | + %contours of the cost function |
| 16 | + \draw (0,0) circle (2) node[shift={(-1.75,1.75)}] {$f(\vect{x})$}; |
| 17 | + \draw (0,0) circle (1.0148); |
| 18 | + \end{scope} |
| 19 | + %constraint |
| 20 | + \draw[domain=0.5:6,samples=100] plot (\x,{ln(\x)}) node[below] {$h(\vect{x})$}; |
| 21 | + %gradients |
| 22 | + \begin{scope}[->,>=stealth,every node/.style={fill=white,inner sep=1pt}] |
| 23 | + \draw (xc) -- (g) node[below,yshift=-1mm] {$\vect{\nabla}f(\vect{x}_c)$}; |
| 24 | + \draw (xc) -- ($(xc)+0.6*(g)-0.6*(xc)$) node[right,xshift=1mm] {$\vect{\nabla}h(\vect{x}_c)$}; |
| 25 | + \end{scope} |
| 26 | + % filter values |
| 27 | +\end{tikzpicture} |
| 28 | + |
| 29 | +%matlab |
| 30 | +%find yi so that f=0 |
| 31 | +%y=linspace(1,5,10000);x1=2.5;x2=2;f=y.^2-x1*y-x2+log(y);plot(y,f) |
| 32 | +%then find the length from constraint to xo |
| 33 | +%norm([x1,x2]-[yi,log(yi)]) |
| 34 | +%the end coordinate of the gradient is |
| 35 | +% xc + [1/yi,-1] |
0 commit comments