-
Notifications
You must be signed in to change notification settings - Fork 195
/
polymod.m
42 lines (42 loc) · 1.19 KB
/
polymod.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
function [lplus]=polymod(q0, qp0, lamc, qc, blow, bhigh, lamm, qm)
%
% C. T. Kelley, Dec 29, 1997
%
% This code comes with no guarantee or warranty of any kind.
%
% function [lambda]=polymod(q0, qp0, qc, blow, bhigh, qm)
%
% Cubic/quadratic polynomial linesearch
%
% Finds minimizer lambda of the cubic polynomial q on the interval
% [blow * lamc, bhigh * lamc] such that
%
% q(0) = q0, q'(0) = qp0, q(lamc) = qc, q(lamm) = qm
%
% if data for a cubic is not available (first stepsize reduction) then
% q is the quadratic such that
%
% q(0) = q0, q'(0) = qp0, q(lamc) = qc
%
lleft=lamc*blow; lright=lamc*bhigh;
if nargin == 6
%
% quadratic model (temp hedge in case lamc is not 1)
% Thanks to the Tulane grad students for fixing an error
% in Spring 2016!
%
% lplus = - qp0/(2 * lamc*(qc - q0 - qp0) );
lplus = - (qp0*lamc*lamc)/(2 * (qc - q0 - qp0*lamc) );
if lplus < lleft lplus = lleft; end
if lplus > lright lplus = lright; end
else
%
% cubic model
%
a=[lamc^2, lamc^3; lamm^2, lamm^3];
b=[qc; qm]-[q0 + qp0*lamc; q0 + qp0*lamm];
c=a\b;
lplus=(-c(1)+sqrt(c(1)*c(1) - 3 *c(2) *qp0))/(3*c(2));
if lplus < lleft lplus = lleft; end
if lplus > lright lplus = lright; end
end