-
Notifications
You must be signed in to change notification settings - Fork 800
/
newtonsMethodMinQuad.m
50 lines (45 loc) · 1.82 KB
/
newtonsMethodMinQuad.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%% Illustration of a function g and its second order approximation.
%
%%
% This file is from pmtk3.googlecode.com
function newtonsMethodMinQuad
figure(); hold on;
xmin = -5; xmax = 0;
ymin = -20; ymax = 150;
domain = xmin:0.01:xmax;
f = @(x) -x.^3;
Xk = -4;
f1 = @(x) -3*x.^2;
f2 = @(x) -6*x;
t = @(x) f(Xk) + f1(Xk)*(x - Xk) + (1/2)*f2(Xk)*(x - Xk).^2;
[val, minNDX] = min(t(domain));
minimum = domain(minNDX);
h1 = plot(domain, f(domain), '-r' , 'LineWidth', 3);
h2 = plot(domain, t(domain), '--b', 'LineWidth', 2.5);
%legend([h1, h2], {'f(x)', 'f_{quad}(x)'}, 'Location', 'NorthEast');
%legend([h1, h2], {'C(\theta)', 'C_{quad}(\theta)'}, 'Location', 'NorthEast');
plot(Xk, f(Xk), '.k', 'MarkerSize', 25);
plot([Xk, Xk], [ymin, f(Xk)], ':k');
plot(minimum, t(minimum), '.k', 'MarkerSize', 25);
plot([minimum, minimum], [ymin, t(minimum)], ':k');
% x^(k)
annotation(gcf,'textbox' , [0.25 0 0.09946 0.11] , ...
'String' , {'\theta_{k}'} , ...
'FontSize' , 18 , ...
'FitBoxToText' , 'off' , ...
'LineStyle' , 'none' );
% x^(k) + v^(k)
annotation(gcf,'textbox' ,[0.515 0 0.09946 0.11] , ...
'String' ,{'\theta_{k}+d_{k}'} , ...
'FontSize' ,18 , ...
'FitBoxToText' ,'off' , ...
'LineStyle' ,'none' );
axis([xmin, xmax, ymin, ymax]);
set(gca, 'XTick' , [Xk, minimum], ...
'XTickLabel' , {'', ''} , ...
'YTick' , [] , ...
'FontSize' , 16 , ...
'Box' , 'on' , ...
'LineWidth' , 2 );
printPmtkFigure('newtonsMethodMinQuadTheta');
end