diff --git a/.gitignore b/.gitignore
index e5c7c54b2c2b1f2fcbc165e68a54eb4196dd27bd..eb21d6ad7ee8a100ad90859dc3a6eb78d63d508b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,6 +27,7 @@ coco_log*.txt
 coco_scr*.txt
 *.mat
 matlab_development/uq/examples/**/data
+matlab_development/uq/toolbox/no_comment_for_thesis
 
 # Some Mac file
 .DS_Store
diff --git a/archive/demo.m b/archive/demo.m
deleted file mode 100644
index 28629ff152b05bfa1d0415bad0661b387f290323..0000000000000000000000000000000000000000
--- a/archive/demo.m
+++ /dev/null
@@ -1,44 +0,0 @@
-% Parameter values
-% p(1) = Period, T
-% p(2) = Forcing Amplitude, A
-% p(3) = Linear Stiffness, k
-% p(4) = Damping, d
-% p(5) = Cubic Stiffness, eps
-p0 = [2*pi; 0.3; 1; 2*0.1; 5];
-u0 = [0; 1; 0];
-
-% Forward Simulation for Starting Guess for Periodic Orbit
-f = @(t,u) duff(u,p0);
-% Long Run Simulation to let transients die out
-[~, u0] = ode45(f, [0, 100*pi], u0);
-% Estimate for steady state solution
-[t0, u0] = ode45(f, [0, p0(1)], u0(end,:));
-
-%%
-% Initialize Boundary Conditions
-data = struct();
-data.fhan = @duff;
-data = per_bc_update(data, [], u0(1,:)', [], p0);
-
-funcs = { @duff @duff_DU @duff_DP };
-pnames = {'T' 'A' 'k' 'd' 'eps'};
-coll_args = {funcs{:} t0 u0 p0};
-bvp_args = { @per_bc, @per_Jbc, data, @per_bc_update };
-
-%%
-prob = coco_prob();
-prob = coco_set(prob, 'coll', 'NTST', 15, 'var', true);
-% prob = coco_set(prob, 'cont', 'NAdapt', 1);
-prob = ode_isol2bvp(prob, '', coll_args{:}, pnames, bvp_args{:});
-
-%%
-[data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
-
-maps = data.coll_seg.maps;
-
-prob = coco_add_glue(prob, 'glue', uidx(maps.T_idx), uidx(maps.p_idx(1)));
-prob = coco_add_pars(prob, 'x_max', uidx(maps.x0_idx(1)), {'x_max'});
-
-%%
-bd = coco(prob, 'optim', [], 1, {'T','bvp.seg1.coll.T0','x_max'}, [2*pi/1.3, 2*pi/0.7]);
-
diff --git a/archive/demo_coll.m b/archive/demo_coll.m
deleted file mode 100644
index 5cda55ee5184416842c9f954607d88f7114e096e..0000000000000000000000000000000000000000
--- a/archive/demo_coll.m
+++ /dev/null
@@ -1,48 +0,0 @@
-% Parameter values
-% p(1) = frequency of oscillation, w
-% p(2) = Forcing Amplitude, A
-% p(3) = Linear Stiffness, k
-% p(4) = Damping, d
-% p(5) = Cubic Stiffness, eps
-% p0 = [2*pi; 0.3; 1; 2*0.1; 5];
-p0 = [1; 0; 1; 0; 0];
-% u0 = [0; 1; 0; 1];
-
-t0 = linspace(0,1,200)';
-u0 = [cos(t0), -sin(t0), sin(t0), cos(t0)];
-
-% % Forward Simulation for Starting Guess for Periodic Orbit
-% f = @(t,u) duff(u,p0);
-% % Long Run Simulation to let transients die out
-% [t0, u0] = ode45(f, [0, 2*pi], u0);
-
-% Estimate for steady state solution
-% [t0, u0] = ode45(f, [0, 2*pi/p0(1)], u0(end,:));
-data = struct();
-data.fhan = @duff;
-data = per_bc_update(data, [], u0(1,:)', [], p0);
-
-prob = coco_prob();
-funcs = { @duff @duff_DU @duff_DP };
-pnames = {'w' 'A' 'k' 'd' 'eps'};
-
-coll_args = {funcs{:}, t0, u0, p0};
-
-bvp_args  = {@per_bc, @per_Jbc, data, @per_bc_update};
-prob = ode_isol2bvp(prob, '', coll_args{:}, pnames, bvp_args{:});
-
-[data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
-maps = data.coll_seg.maps;
-
-prob = coco_add_glue(prob, 'glue', uidx(maps.T_idx), uidx(maps.p_idx(1)));
-prob = coco_add_glue(prob, 'glue2', uidx(maps.T0_idx), uidx(maps.x0_idx(3)));
-prob = coco_add_pars(prob, 'v0', uidx(maps.x0_idx(2)), 'v0', 'active');
-prob = coco_add_pars(prob, 'x_max', uidx(maps.x0_idx(1)), 'x_max', 'active');
-
-% Start continuation of periodic orbits with updates to the Poincare
-% section before each continuation step.
-
-prob = coco_set(prob, 'cont', 'NAdapt', 10);
-cont_args = { 0, {'w', }};
-
-coco(prob, 'optim', [], cont_args{:});
\ No newline at end of file
diff --git a/archive/demo_po.m b/archive/demo_po.m
deleted file mode 100644
index 3e2f65b8978eb2985eb2d504be3e2ecd13ce80c8..0000000000000000000000000000000000000000
--- a/archive/demo_po.m
+++ /dev/null
@@ -1,43 +0,0 @@
-% Parameter values
-% p(1) = Period, T
-% p(2) = Forcing Amplitude, A
-% p(3) = Linear Stiffness, k
-% p(4) = Damping, d
-% p(5) = Cubic Stiffness, eps
-p0 = [2*pi; 0.3; 1; 2*0.1; 5];
-u0 = [0; 1];
-
-% Forward Simulation for Starting Guess for Periodic Orbit
-f = @(t,u) duffna(t,u,p0);
-
-% Long Run Simulation to let transients die out
-[~, u0] = ode45(f, [0, 100*pi], u0);
-
-% Estimate for steady state solution
-[t0, u0] = ode45(f, [0, p0(1)], u0(end,:)');
-
-funcs = { @duffna @duffna_DU @duffna_DP @duffna_DT};
-pnames = {'T' 'A' 'k' 'd' 'eps'};
-coll_args = {funcs{:} t0 u0 pnames p0};
-prob = coco_prob();
-prob = coco_set(prob, 'ode', 'autonomous', false);
-prob = coco_set(prob, 'coll', 'NTST', 15);
-prob = ode_isol2po(prob, '', coll_args{:});
-
-% Adaptive discretization before each continuation step
-prob = coco_set(prob, 'cont', 'NAdapt', 1);
-
-[data, uidx] = coco_get_func_data(prob, 'po.orb.coll', 'data', 'uidx');
-maps = data.coll_seg.maps;
-
-prob = coco_add_glue(prob, 'glue', uidx(maps.T_idx), uidx(maps.p_idx(1)));
-prob = coco_add_pars(prob, 'v0', uidx(maps.x0_idx(2)), 'v0', 'active');
-
-
-prob = coco_add_pars(prob, 'x_max', uidx(maps.x0_idx(1)), {'x_max'});
-
-bd = coco(prob, 'optim', [], 1, {'po.period', 'T', 'x_max'}, [pi, 4*pi]);
-bd2 = coco_bd_read('optim');
-u = coco_bd_col(bd2, {'T', '||po.orb.x||'});
-plot(2*pi./u(1,:),u(2,:))
-
diff --git a/archive/demo_po_a.m b/archive/demo_po_a.m
deleted file mode 100644
index 9abbfc67f5f2d788afedd4f0961ff8dc8ec1e96c..0000000000000000000000000000000000000000
--- a/archive/demo_po_a.m
+++ /dev/null
@@ -1,42 +0,0 @@
-% Parameter values
-% p(1) = Period, T
-% p(2) = Forcing Amplitude, A
-% p(3) = Linear Stiffness, k
-% p(4) = Damping, d
-% p(5) = Cubic Stiffness, eps
-p0 = [2*pi; 0.3; 1; 2*0.1; 5];
-u0 = [0; 1; 0];
-
-% Forward Simulation for Starting Guess for Periodic Orbit
-f = @(t,u) duff(u,p0);
-
-% Long Run Simulation to let transients die out
-[~, u0] = ode45(f, [0, 20*pi], u0);
-
-% Estimate for steady state solution
-[t0, u0] = ode45(f, [0, p0(1)], u0(end,:)');
-
-funcs = {@duff @duff_DU @duff_DP};
-pnames = {'T' 'A' 'k' 'd' 'eps'};
-coll_args = {funcs{:} t0 u0 pnames p0};
-
-prob = ode_isol2po(coco_prob(), '', coll_args{:});
-prob = coco_set(prob, 'coll', 'NTST', 15);
-
-% Adaptive discretization before each continuation step
-prob = coco_set(prob, 'cont', 'NAdapt', 1);
-
-[data, uidx] = coco_get_func_data(prob, 'po.orb.coll', 'data', 'uidx');
-maps = data.coll_seg.maps;
-
-prob = coco_add_glue(prob, 'glue', uidx(maps.T_idx), uidx(maps.p_idx(1)));
-prob = coco_add_pars(prob, 'v0', uidx(maps.x0_idx(2)), 'v0', 'active');
-
-
-prob = coco_add_pars(prob, 'x_max', uidx(maps.x0_idx(1)), {'x_max'});
-
-bd = coco(prob, 'optim', [], 1, {'po.period', 'T', 'x_max'}, [pi, 4*pi]);
-bd2 = coco_bd_read('optim');
-u = coco_bd_col(bd2, {'T', '||po.orb.x||'});
-plot(2*pi./u(1,:),u(2,:))
-
diff --git a/archive/duff.m b/archive/duff.m
deleted file mode 100644
index 00a53c62138e717016da92d309c4d7a2cdca8df9..0000000000000000000000000000000000000000
--- a/archive/duff.m
+++ /dev/null
@@ -1,30 +0,0 @@
-function y = duff(u,p)
-
-% Autonomous, Vectorized encoding of the Duffing oscillator
-% x'' + d*x' + k*x + eps*x^3 = A*cos(2*pi*t/T)
-% u1 = x
-% u2 = x'
-% u3 = sin(wt)
-% u4 = cos(wt)
-
-w = p(1,:);
-A = p(2,:);
-k = p(3,:);
-d = p(4,:);
-eps = p(5,:);
-
-u1 = u(1,:); % Position
-u2 = u(2,:); % Velocity
-u3 = u(3,:); % sin(wt)
-u4 = u(4,:); % cos(wt)
-
-y(1,:) = u2;
-y(2,:) = A.*u4 - d.*u2- k.*u1 - eps.*u1.^3;
-% Solution to u3 and u4 is u3 = sin(wt), u4 = cos(wt)
-% Therefore, this is an autonomous way to encode the non-autonomous forcing
-% function.  See Mehdi RSPA paper, reference ~47 (the one about
-% continuation in a finite element model)
-y(3,:) = u3 + w.*u4 - u3.*(u3.^2 + u4.^2);
-y(4,:) = u4 - w.*u3 - u4.*(u3.^2 + u4.^2);
-
-end
\ No newline at end of file
diff --git a/archive/duff_DP.m b/archive/duff_DP.m
deleted file mode 100644
index beb4e213a08579bf5597b15dd9ed5ac6939d3f46..0000000000000000000000000000000000000000
--- a/archive/duff_DP.m
+++ /dev/null
@@ -1,17 +0,0 @@
-function J = duff_DP(u,p)
-
-u1 = u(1,:);
-u2 = u(2,:);
-u3 = u(3,:);
-u4 = u(4,:);
-
-J = zeros(4,size(p,1),size(u,2));
-
-J(2,2,:) = u4;
-J(2,3,:) = -u1;
-J(2,4,:) = -u2;
-J(2,5,:) = -u1.^3;
-J(3,1,:) = u4;
-J(4,1,:) = -u3;
-
-end
\ No newline at end of file
diff --git a/archive/duff_DU.m b/archive/duff_DU.m
deleted file mode 100644
index 1c4b275dfbc495df54865452b21f81a339239a40..0000000000000000000000000000000000000000
--- a/archive/duff_DU.m
+++ /dev/null
@@ -1,23 +0,0 @@
-function J = duff_DU(u,p)
-
-u1 = u(1,:);
-u3 = u(3,:);
-u4 = u(4,:);
-w = p(1,:);
-A = p(2,:);
-k = p(3,:);
-d = p(4,:);
-eps = p(5,:);
-
-J = zeros(4,4,numel(u1));
-
-J(1,2,:) = 1;
-J(2,1,:) = -k - 3*eps.*u1.^2;
-J(2,2,:) = -d;
-J(2,4,:) = A;
-J(3,3,:) = 1 - 3*u3.^2 - u4.^2;
-J(3,4,:) = w - 2*u3.*u4;
-J(4,3,:) = -w - 2*u3.*u4;
-J(4,4,:) = 1 - u3.^2 - 3*u4.^2;
-
-end
\ No newline at end of file
diff --git a/archive/duffna.m b/archive/duffna.m
deleted file mode 100644
index 77170c92b877ded9e901a9ef8f4d758e290db6a8..0000000000000000000000000000000000000000
--- a/archive/duffna.m
+++ /dev/null
@@ -1,20 +0,0 @@
-function y = duffna(t,u,p)
-
-% non-Autonomous, Vectorized encoding of the Duffing oscillator
-% x'' + d*x' + k*x + eps*x^3 = A*cos(2*pi*t/T)
-% u1 = x
-% u2 = x'
-
-T = p(1,:);
-A = p(2,:);
-k = p(3,:);
-d = p(4,:);
-eps = p(5,:);
-
-u1 = u(1,:); % Position
-u2 = u(2,:); % Velocity
-
-y(1,:) = u2;
-y(2,:) = A.*cos((2*pi./T).*t) - d.*u2- k.*u1 - eps.*u1.^3;
-
-end
\ No newline at end of file
diff --git a/archive/duffna_DP.m b/archive/duffna_DP.m
deleted file mode 100644
index 56d268049f8551d6027ab1699f4f12eedf930095..0000000000000000000000000000000000000000
--- a/archive/duffna_DP.m
+++ /dev/null
@@ -1,17 +0,0 @@
-function J = duffna_DP(t,u,p)
-
-T = p(1,:);
-A = p(2,:);
-
-u1 = u(1,:);
-u2 = u(2,:);
-
-J = zeros(2,numel(p(:,1)),numel(u1));
-
-J(2,1,:) = (2*pi*A.*t./(T.^2)).*sin((2*pi./T).*t);
-J(2,2,:) = cos(2*pi./T.*t);
-J(2,3,:) = -u1;
-J(2,4,:) = -u2;
-J(2,5,:) = -u1.^3;
-
-end
\ No newline at end of file
diff --git a/archive/duffna_DT.m b/archive/duffna_DT.m
deleted file mode 100644
index 31a0281b9befd35ef952cbfa830bbd40e056da7a..0000000000000000000000000000000000000000
--- a/archive/duffna_DT.m
+++ /dev/null
@@ -1,9 +0,0 @@
-function Jt = duffna_DT(t,u,p)
-
-T = p(1,:);
-A = p(2,:);
-
-Jt = zeros(2,numel(t));
-Jt(2,:) = -(2*pi./T).*A.*sin((2*pi./T).*t);
-
-end
\ No newline at end of file
diff --git a/archive/duffna_DU.m b/archive/duffna_DU.m
deleted file mode 100644
index e37ae3dd434e1647c85e0b5d91b33e18b3ec3b1d..0000000000000000000000000000000000000000
--- a/archive/duffna_DU.m
+++ /dev/null
@@ -1,16 +0,0 @@
-function J = duffna_DU(t,u,p)
-
-u1 = u(1,:);
-T = p(1,:);
-A = p(2,:);
-k = p(3,:);
-d = p(4,:);
-eps = p(5,:);
-
-J = zeros(2,2,numel(u1));
-
-J(1,2,:) = 1;
-J(2,1,:) = -k - 3*eps.*u1.^2;
-J(2,2,:) = -d;
-
-end
\ No newline at end of file
diff --git a/archive/lin_ode_adjoint_old_n_wrong.nb b/archive/lin_ode_adjoint_old_n_wrong.nb
deleted file mode 100644
index 0565e6316d6f72e4ccfe2ba5e75172156988ab06..0000000000000000000000000000000000000000
--- a/archive/lin_ode_adjoint_old_n_wrong.nb
+++ /dev/null
@@ -1,1765 +0,0 @@
-(* Content-type: application/vnd.wolfram.mathematica *)
-
-(*** Wolfram Notebook File ***)
-(* http://www.wolfram.com/nb *)
-
-(* CreatedBy='Mathematica 11.0' *)
-
-(*CacheID: 234*)
-(* Internal cache information:
-NotebookFileLineBreakTest
-NotebookFileLineBreakTest
-NotebookDataPosition[       158,          7]
-NotebookDataLength[     60383,       1757]
-NotebookOptionsPosition[     57939,       1671]
-NotebookOutlinePosition[     58312,       1687]
-CellTagsIndexPosition[     58269,       1684]
-WindowFrame->Normal*)
-
-(* Beginning of Notebook Content *)
-Notebook[{
-Cell[BoxData["Quit"], "Input",
- CellChangeTimes->{{3.6983400489382863`*^9, 3.6983400503332863`*^9}, {
-  3.698340193264286*^9, 3.698340193874286*^9}, {3.698340985538786*^9, 
-  3.698341008166786*^9}, {3.6983414223452864`*^9, 3.6983414241952863`*^9}, {
-  3.698341811770286*^9, 3.6983418123502865`*^9}, {3.6983420924822865`*^9, 
-  3.6983420944522862`*^9}, {3.698353157342383*^9, 3.698353158372383*^9}, {
-  3.698355149652383*^9, 3.698355150195383*^9}}],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[{
- RowBox[{
-  RowBox[{"x", " ", "=", " ", 
-   RowBox[{"{", 
-    RowBox[{
-     RowBox[{"x1", "[", "t", "]"}], ",", " ", 
-     RowBox[{"x2", "[", "t", "]"}]}], "}"}]}], ";"}], "\[IndentingNewLine]", 
- RowBox[{
-  RowBox[{"p", " ", "=", " ", 
-   RowBox[{"{", 
-    RowBox[{"k", ",", "\[Phi]"}], "}"}]}], ";"}], "\[IndentingNewLine]", 
- RowBox[{
-  RowBox[{"f", " ", "=", " ", 
-   RowBox[{"{", 
-    RowBox[{
-     RowBox[{"x2", "[", "t", "]"}], ",", 
-     RowBox[{
-      RowBox[{"Cos", "[", 
-       RowBox[{"t", "+", "\[Phi]"}], "]"}], " ", "-", " ", 
-      RowBox[{"x2", "[", "t", "]"}], " ", "-", " ", 
-      RowBox[{"k", "*", 
-       RowBox[{"x1", "[", "t", "]"}]}]}]}], "}"}]}], 
-  ";"}], "\[IndentingNewLine]", 
- RowBox[{
-  RowBox[{"fx", " ", "=", " ", 
-   RowBox[{"D", "[", 
-    RowBox[{"f", ",", 
-     RowBox[{"{", "x", "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", 
- RowBox[{
-  RowBox[{"fp", " ", "=", " ", 
-   RowBox[{"D", "[", 
-    RowBox[{"f", ",", 
-     RowBox[{"{", "p", "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", 
- RowBox[{
-  RowBox[{"linodesys", " ", "=", " ", 
-   RowBox[{
-    RowBox[{
-     RowBox[{"D", "[", 
-      RowBox[{"x", ",", "t"}], "]"}], " ", "-", " ", "f"}], " ", "\[Equal]", 
-    " ", 
-    RowBox[{"{", 
-     RowBox[{"0", ",", "0"}], "}"}]}]}], ";"}], "\[IndentingNewLine]", 
- RowBox[{
-  RowBox[{"\[Lambda]", " ", "=", " ", 
-   RowBox[{"{", 
-    RowBox[{"\[Lambda]1", ",", " ", "\[Lambda]2"}], "}"}]}], 
-  ";"}], "\[IndentingNewLine]", 
- RowBox[{
-  RowBox[{"\[Eta]", " ", "=", " ", 
-   RowBox[{"{", 
-    RowBox[{"\[Eta]2", ",", " ", "\[Eta]3"}], "}"}]}], 
-  ";"}], "\[IndentingNewLine]", 
- RowBox[{"\[Lambda]", ".", "fp"}], "\[IndentingNewLine]"}], "Input",
- CellChangeTimes->{{3.698348711497286*^9, 3.698348713387286*^9}, {
-  3.698348748497286*^9, 3.698348759377286*^9}, {3.698348795257286*^9, 
-  3.698348822217286*^9}, {3.698349514394286*^9, 3.6983495445702863`*^9}, {
-  3.6983524541638827`*^9, 3.6983524799728827`*^9}, {3.698352561371883*^9, 
-  3.6983526772448826`*^9}, {3.6983527339468827`*^9, 3.6983527799148827`*^9}, {
-  3.701700469312645*^9, 3.701700516809026*^9}}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   RowBox[{
-    RowBox[{"-", "\[Lambda]2"}], " ", 
-    RowBox[{"x1", "[", "t", "]"}]}], ",", 
-   RowBox[{
-    RowBox[{"-", "\[Lambda]2"}], " ", 
-    RowBox[{"Sin", "[", 
-     RowBox[{"t", "+", "\[Phi]"}], "]"}]}]}], "}"}]], "Output",
- CellChangeTimes->{
-  3.701700495119866*^9, 3.7024697629624147`*^9, {3.702471138880827*^9, 
-   3.702471146771477*^9}, 3.7024714246192627`*^9}]
-}, Open  ]],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{
-  RowBox[{"(*", " ", 
-   RowBox[{"Solve", " ", "Linear", " ", "ODE"}], " ", "*)"}], 
-  "\[IndentingNewLine]", 
-  RowBox[{"xsol", "=", 
-   RowBox[{"FullSimplify", "[", 
-    RowBox[{"Assuming", "[", 
-     RowBox[{
-      RowBox[{
-       RowBox[{"k", "\[Element]", "Reals"}], "&&", 
-       RowBox[{"k", ">", 
-        RowBox[{"1", "/", "4"}]}], " ", "&&", " ", 
-       RowBox[{"\[Phi]", " ", "\[Element]", "Reals"}]}], ",", 
-      RowBox[{"DSolve", "[", 
-       RowBox[{"linodesys", ",", 
-        RowBox[{"{", 
-         RowBox[{
-          RowBox[{"x1", "[", "t", "]"}], ",", 
-          RowBox[{"x2", "[", "t", "]"}]}], "}"}], ",", "t"}], "]"}]}], "]"}], 
-    "]"}]}]}]], "Input",
- CellChangeTimes->{{3.698336278775286*^9, 3.698336314065286*^9}, {
-   3.698336379057786*^9, 3.698336406337786*^9}, {3.6983364689822865`*^9, 
-   3.698336508122286*^9}, {3.6983366125372863`*^9, 3.6983367348897862`*^9}, {
-   3.698336766809786*^9, 3.698336767529786*^9}, {3.698337732514286*^9, 
-   3.6983377937872863`*^9}, {3.6983378556262865`*^9, 
-   3.6983378654162865`*^9}, {3.6983379639052863`*^9, 3.698337977257286*^9}, {
-   3.698338061612286*^9, 3.698338104089286*^9}, {3.698338168549286*^9, 
-   3.698338176000286*^9}, {3.6983389156577864`*^9, 3.6983389440897865`*^9}, {
-   3.698340934243286*^9, 3.698340939065286*^9}, {3.6983409717897863`*^9, 
-   3.698340972529786*^9}, {3.6983414052272863`*^9, 3.698341411497286*^9}, {
-   3.698341543726286*^9, 3.698341561176286*^9}, {3.698348703657286*^9, 
-   3.698348707757286*^9}, {3.6983487730372863`*^9, 3.698348788007286*^9}, {
-   3.6983488847872863`*^9, 3.698348888407286*^9}, {3.698349085087286*^9, 
-   3.6983491010902863`*^9}, 3.6983494665742865`*^9, {3.6983500865502863`*^9, 
-   3.6983500928572865`*^9}, {3.6983515378518925`*^9, 3.698351588902926*^9}, {
-   3.6983525007568827`*^9, 3.698352518812883*^9}}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{"{", 
-   RowBox[{
-    RowBox[{
-     RowBox[{"x1", "[", "t", "]"}], "\[Rule]", 
-     RowBox[{
-      FractionBox["1", 
-       RowBox[{"2", " ", 
-        SqrtBox[
-         RowBox[{
-          RowBox[{"-", "1"}], "+", 
-          RowBox[{"4", " ", "k"}]}]], " ", 
-        RowBox[{"(", 
-         RowBox[{"2", "+", 
-          RowBox[{
-           RowBox[{"(", 
-            RowBox[{
-             RowBox[{"-", "2"}], "+", "k"}], ")"}], " ", "k"}]}], ")"}]}]], 
-      RowBox[{
-       SuperscriptBox["\[ExponentialE]", 
-        RowBox[{
-         RowBox[{"-", 
-          FractionBox["1", "2"]}], " ", "\[ImaginaryI]", " ", 
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{"-", "\[ImaginaryI]"}], "+", 
-           SqrtBox[
-            RowBox[{
-             RowBox[{"-", "1"}], "+", 
-             RowBox[{"4", " ", "k"}]}]]}], ")"}], " ", "t"}]], " ", 
-       RowBox[{"(", 
-        RowBox[{
-         RowBox[{
-          RowBox[{"(", 
-           RowBox[{"2", "+", 
-            RowBox[{
-             RowBox[{"(", 
-              RowBox[{
-               RowBox[{"-", "2"}], "+", "k"}], ")"}], " ", "k"}]}], ")"}], 
-          " ", 
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{
-             RowBox[{"(", 
-              RowBox[{"\[ImaginaryI]", "+", 
-               SqrtBox[
-                RowBox[{
-                 RowBox[{"-", "1"}], "+", 
-                 RowBox[{"4", " ", "k"}]}]], "+", 
-               RowBox[{
-                SuperscriptBox["\[ExponentialE]", 
-                 RowBox[{"\[ImaginaryI]", " ", 
-                  SqrtBox[
-                   RowBox[{
-                    RowBox[{"-", "1"}], "+", 
-                    RowBox[{"4", " ", "k"}]}]], " ", "t"}]], " ", 
-                RowBox[{"(", 
-                 RowBox[{
-                  RowBox[{"-", "\[ImaginaryI]"}], "+", 
-                  SqrtBox[
-                   RowBox[{
-                    RowBox[{"-", "1"}], "+", 
-                    RowBox[{"4", " ", "k"}]}]]}], ")"}]}]}], ")"}], " ", 
-             RowBox[{"C", "[", "1", "]"}]}], "-", 
-            RowBox[{"2", " ", "\[ImaginaryI]", " ", 
-             RowBox[{"(", 
-              RowBox[{
-               RowBox[{"-", "1"}], "+", 
-               SuperscriptBox["\[ExponentialE]", 
-                RowBox[{"\[ImaginaryI]", " ", 
-                 SqrtBox[
-                  RowBox[{
-                   RowBox[{"-", "1"}], "+", 
-                   RowBox[{"4", " ", "k"}]}]], " ", "t"}]]}], ")"}], " ", 
-             RowBox[{"C", "[", "2", "]"}]}]}], ")"}]}], "+", 
-         RowBox[{"2", " ", 
-          SuperscriptBox["\[ExponentialE]", 
-           RowBox[{
-            FractionBox["1", "2"], " ", 
-            RowBox[{"(", 
-             RowBox[{"1", "+", 
-              RowBox[{"\[ImaginaryI]", " ", 
-               SqrtBox[
-                RowBox[{
-                 RowBox[{"-", "1"}], "+", 
-                 RowBox[{"4", " ", "k"}]}]]}]}], ")"}], " ", "t"}]], " ", 
-          SqrtBox[
-           RowBox[{
-            RowBox[{"-", "1"}], "+", 
-            RowBox[{"4", " ", "k"}]}]], " ", 
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{
-             RowBox[{"(", 
-              RowBox[{
-               RowBox[{"-", "1"}], "+", "k"}], ")"}], " ", 
-             RowBox[{"Cos", "[", 
-              RowBox[{"t", "+", "\[Phi]"}], "]"}]}], "+", 
-            RowBox[{"Sin", "[", 
-             RowBox[{"t", "+", "\[Phi]"}], "]"}]}], ")"}]}]}], ")"}]}]}]}], 
-    ",", 
-    RowBox[{
-     RowBox[{"x2", "[", "t", "]"}], "\[Rule]", 
-     RowBox[{
-      FractionBox["1", 
-       RowBox[{"2", " ", 
-        SqrtBox[
-         RowBox[{
-          RowBox[{"-", "1"}], "+", 
-          RowBox[{"4", " ", "k"}]}]], " ", 
-        RowBox[{"(", 
-         RowBox[{"2", "+", 
-          RowBox[{
-           RowBox[{"(", 
-            RowBox[{
-             RowBox[{"-", "2"}], "+", "k"}], ")"}], " ", "k"}]}], ")"}]}]], 
-      RowBox[{
-       SuperscriptBox["\[ExponentialE]", 
-        RowBox[{
-         RowBox[{"-", 
-          FractionBox["1", "2"]}], " ", "\[ImaginaryI]", " ", 
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{"-", "\[ImaginaryI]"}], "+", 
-           SqrtBox[
-            RowBox[{
-             RowBox[{"-", "1"}], "+", 
-             RowBox[{"4", " ", "k"}]}]]}], ")"}], " ", "t"}]], " ", 
-       RowBox[{"(", 
-        RowBox[{
-         RowBox[{
-          RowBox[{"(", 
-           RowBox[{"2", "+", 
-            RowBox[{
-             RowBox[{"(", 
-              RowBox[{
-               RowBox[{"-", "2"}], "+", "k"}], ")"}], " ", "k"}]}], ")"}], 
-          " ", 
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{"2", " ", "\[ImaginaryI]", " ", 
-             RowBox[{"(", 
-              RowBox[{
-               RowBox[{"-", "1"}], "+", 
-               SuperscriptBox["\[ExponentialE]", 
-                RowBox[{"\[ImaginaryI]", " ", 
-                 SqrtBox[
-                  RowBox[{
-                   RowBox[{"-", "1"}], "+", 
-                   RowBox[{"4", " ", "k"}]}]], " ", "t"}]]}], ")"}], " ", "k",
-              " ", 
-             RowBox[{"C", "[", "1", "]"}]}], "+", 
-            RowBox[{
-             RowBox[{"(", 
-              RowBox[{
-               RowBox[{"-", "\[ImaginaryI]"}], "+", 
-               SqrtBox[
-                RowBox[{
-                 RowBox[{"-", "1"}], "+", 
-                 RowBox[{"4", " ", "k"}]}]], "+", 
-               RowBox[{
-                SuperscriptBox["\[ExponentialE]", 
-                 RowBox[{"\[ImaginaryI]", " ", 
-                  SqrtBox[
-                   RowBox[{
-                    RowBox[{"-", "1"}], "+", 
-                    RowBox[{"4", " ", "k"}]}]], " ", "t"}]], " ", 
-                RowBox[{"(", 
-                 RowBox[{"\[ImaginaryI]", "+", 
-                  SqrtBox[
-                   RowBox[{
-                    RowBox[{"-", "1"}], "+", 
-                    RowBox[{"4", " ", "k"}]}]]}], ")"}]}]}], ")"}], " ", 
-             RowBox[{"C", "[", "2", "]"}]}]}], ")"}]}], "-", 
-         RowBox[{"2", " ", 
-          SuperscriptBox["\[ExponentialE]", 
-           RowBox[{
-            FractionBox["1", "2"], " ", 
-            RowBox[{"(", 
-             RowBox[{"1", "+", 
-              RowBox[{"\[ImaginaryI]", " ", 
-               SqrtBox[
-                RowBox[{
-                 RowBox[{"-", "1"}], "+", 
-                 RowBox[{"4", " ", "k"}]}]]}]}], ")"}], " ", "t"}]], " ", 
-          SqrtBox[
-           RowBox[{
-            RowBox[{"-", "1"}], "+", 
-            RowBox[{"4", " ", "k"}]}]], " ", 
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{"-", 
-             RowBox[{"Cos", "[", 
-              RowBox[{"t", "+", "\[Phi]"}], "]"}]}], "+", 
-            RowBox[{
-             RowBox[{"(", 
-              RowBox[{
-               RowBox[{"-", "1"}], "+", "k"}], ")"}], " ", 
-             RowBox[{"Sin", "[", 
-              RowBox[{"t", "+", "\[Phi]"}], "]"}]}]}], ")"}]}]}], 
-        ")"}]}]}]}]}], "}"}], "}"}]], "Output",
- CellChangeTimes->{
-  3.698340973429786*^9, 3.698341012557786*^9, 3.698341561745286*^9, 
-   3.698341596054286*^9, {3.698348876347286*^9, 3.698348890507286*^9}, 
-   3.6983491090412865`*^9, 3.6983491778312864`*^9, 3.6983499416592865`*^9, {
-   3.698350087582286*^9, 3.698350099047286*^9}, 3.698350276160286*^9, {
-   3.698351566212466*^9, 3.698351594225033*^9}, 3.698352059759883*^9, 
-   3.698352359320883*^9, 3.698353085277383*^9, 3.6983531687293825`*^9, 
-   3.698353535633383*^9, 3.698353691382383*^9, 3.6983538618313828`*^9, 
-   3.6983539348773828`*^9, 3.6983551619043827`*^9, 3.698355372520383*^9, 
-   3.6984828297921457`*^9, 3.6984857319372244`*^9, 3.698487315135665*^9, 
-   3.6984915937902374`*^9, 3.702469787291259*^9, 3.702471167365323*^9, 
-   3.702471443900601*^9}]
-}, Open  ]],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{
-  RowBox[{"(*", " ", 
-   RowBox[{"Separate", " ", "out", " ", "SS", " ", "Solution"}], " ", "*)"}], 
-  "\[IndentingNewLine]", 
-  RowBox[{
-   RowBox[{"x1", "[", "t_", "]"}], "=", " ", 
-   RowBox[{"FullSimplify", "[", 
-    FractionBox[
-     RowBox[{
-      RowBox[{"-", "4"}], " ", 
-      RowBox[{"(", 
-       RowBox[{
-        RowBox[{"-", 
-         RowBox[{"Cos", "[", 
-          RowBox[{"t", "+", "\[Phi]"}], "]"}]}], "+", 
-        RowBox[{"k", " ", 
-         RowBox[{"Cos", "[", 
-          RowBox[{"t", "+", "\[Phi]"}], "]"}]}], "+", 
-        RowBox[{"Sin", "[", 
-         RowBox[{"t", "+", "\[Phi]"}], "]"}]}], ")"}]}], 
-     RowBox[{
-      RowBox[{"(", 
-       RowBox[{"3", "+", 
-        SqrtBox[
-         RowBox[{"1", "-", 
-          RowBox[{"4", " ", "k"}]}]], "-", 
-        RowBox[{"2", " ", "k"}]}], ")"}], " ", 
-      RowBox[{"(", 
-       RowBox[{
-        RowBox[{"-", "3"}], "+", 
-        SqrtBox[
-         RowBox[{"1", "-", 
-          RowBox[{"4", " ", "k"}]}]], "+", 
-        RowBox[{"2", " ", "k"}]}], ")"}]}]], "]"}]}]}]], "Input",
- CellChangeTimes->{{3.698336563742286*^9, 3.698336596362286*^9}, {
-   3.698337682722286*^9, 3.698337692763286*^9}, {3.6983381491872864`*^9, 
-   3.698338153098286*^9}, {3.698338185913286*^9, 3.698338272962786*^9}, {
-   3.6983384714927864`*^9, 3.698338475002786*^9}, {3.698339233022786*^9, 
-   3.698339238146786*^9}, {3.698351746398427*^9, 3.6983517495584593`*^9}, {
-   3.698352522714883*^9, 3.698352531590883*^9}, {3.6983536300173826`*^9, 
-   3.698353668955383*^9}, {3.6983537346043825`*^9, 3.698353770797383*^9}, 
-   3.6983538471943827`*^9, {3.6983539309983826`*^9, 3.698353931598383*^9}, 
-   3.698479997006968*^9, {3.698480255539981*^9, 3.6984803220404606`*^9}, {
-   3.6984803680251484`*^9, 3.698480371790805*^9}, {3.6984811597181177`*^9, 
-   3.69848117168695*^9}, 3.6984827889637547`*^9}],
-
-Cell[BoxData[
- FractionBox[
-  RowBox[{
-   RowBox[{
-    RowBox[{"(", 
-     RowBox[{
-      RowBox[{"-", "1"}], "+", "k"}], ")"}], " ", 
-    RowBox[{"Cos", "[", 
-     RowBox[{"t", "+", "\[Phi]"}], "]"}]}], "+", 
-   RowBox[{"Sin", "[", 
-    RowBox[{"t", "+", "\[Phi]"}], "]"}]}], 
-  RowBox[{"2", "+", 
-   RowBox[{
-    RowBox[{"(", 
-     RowBox[{
-      RowBox[{"-", "2"}], "+", "k"}], ")"}], " ", "k"}]}]]], "Output",
- CellChangeTimes->{{3.698480298196541*^9, 3.6984803226967096`*^9}, 
-   3.6984803725720515`*^9, 3.698480993451332*^9, {3.698481161171245*^9, 
-   3.6984811724369564`*^9}, 3.6984828304952927`*^9, 3.6984857322028475`*^9, 
-   3.6984873154325404`*^9, 3.698491594477742*^9, {3.7024697876506248`*^9, 
-   3.7024698117763352`*^9}, 3.702471167771572*^9, 3.702471444009979*^9}]
-}, Open  ]],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{
-  RowBox[{"(*", " ", 
-   RowBox[{"Explicitly", " ", "Calculate", " ", "SS", " ", 
-    RowBox[{"x2", "[", "t", "]"}]}], " ", "*)"}], "\[IndentingNewLine]", 
-  RowBox[{
-   RowBox[{"x2", "[", "t_", "]"}], " ", "=", 
-   RowBox[{"D", "[", 
-    RowBox[{
-     RowBox[{"x1", "[", "t", "]"}], ",", "t"}], "]"}]}]}]], "Input",
- CellChangeTimes->{
-  3.6984802948996553`*^9, {3.6984915748682337`*^9, 3.698491593165218*^9}}],
-
-Cell[BoxData[
- FractionBox[
-  RowBox[{
-   RowBox[{"Cos", "[", 
-    RowBox[{"t", "+", "\[Phi]"}], "]"}], "-", 
-   RowBox[{
-    RowBox[{"(", 
-     RowBox[{
-      RowBox[{"-", "1"}], "+", "k"}], ")"}], " ", 
-    RowBox[{"Sin", "[", 
-     RowBox[{"t", "+", "\[Phi]"}], "]"}]}]}], 
-  RowBox[{"2", "+", 
-   RowBox[{
-    RowBox[{"(", 
-     RowBox[{
-      RowBox[{"-", "2"}], "+", "k"}], ")"}], " ", "k"}]}]]], "Output",
- CellChangeTimes->{
-  3.6984799980694737`*^9, {3.69848027235261*^9, 3.69848030061843*^9}, 
-   3.6984811838120346`*^9, 3.698482830573416*^9, 3.6984857322809725`*^9, 
-   3.698487315479416*^9, 3.698491693259676*^9, {3.7024697876975017`*^9, 
-   3.7024698159483404`*^9}, 3.7024711678340592`*^9, 3.7024714440412216`*^9}]
-}, Open  ]],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{
-  RowBox[{"(*", " ", 
-   RowBox[{
-   "Solve", " ", "for", " ", "Phase", " ", "Angle", " ", "that", " ", 
-    "Satisfies", " ", "BC"}], " ", "*)"}], "\[IndentingNewLine]", 
-  RowBox[{"Assuming", "[", 
-   RowBox[{
-    RowBox[{
-     RowBox[{"k", "\[Element]", "Reals"}], "&&", 
-     RowBox[{"k", ">", 
-      RowBox[{"1", "/", "4"}]}], "&&", 
-     RowBox[{"\[Phi]", "\[Element]", "Reals"}]}], ",", 
-    RowBox[{"FullSimplify", "[", 
-     RowBox[{"Solve", "[", 
-      RowBox[{
-       RowBox[{
-        RowBox[{"x2", "[", 
-         RowBox[{"2", "\[Pi]"}], "]"}], "\[Equal]", "0"}], ",", "\[Phi]"}], 
-      "]"}], "]"}]}], "]"}]}]], "Input",
- CellChangeTimes->{{3.698338241631286*^9, 3.698338243921286*^9}, {
-   3.6983382836127863`*^9, 3.698338299831786*^9}, {3.6983384063757863`*^9, 
-   3.6983384296627865`*^9}, {3.698338503439786*^9, 3.6983385479927864`*^9}, {
-   3.698338594739786*^9, 3.698338637977786*^9}, {3.698338955614786*^9, 
-   3.698339051177786*^9}, {3.698339092838786*^9, 3.6983392160117865`*^9}, {
-   3.6983392462427864`*^9, 3.698339295784786*^9}, 3.6983395464752865`*^9, {
-   3.698339646377286*^9, 3.698339671021286*^9}, {3.698341581191286*^9, 
-   3.698341585962286*^9}, 3.698342134962286*^9, {3.698352536705883*^9, 
-   3.698352555896883*^9}, {3.6983528688583827`*^9, 3.698352869448383*^9}, {
-   3.698353673265383*^9, 3.6983536738353825`*^9}, {3.698353788954383*^9, 
-   3.698353799179383*^9}, 3.6983538679243827`*^9, {3.698488475815564*^9, 
-   3.698488482940625*^9}, {3.6984917098535585`*^9, 3.698491710072304*^9}, {
-   3.698492145403426*^9, 3.698492147559707*^9}, {3.698492184356821*^9, 
-   3.6984921892474804`*^9}, {3.6984924008114424`*^9, 3.6984924024051895`*^9}}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   RowBox[{"{", 
-    RowBox[{"\[Phi]", "\[Rule]", 
-     RowBox[{"ConditionalExpression", "[", 
-      RowBox[{
-       RowBox[{
-        RowBox[{"ArcTan", "[", 
-         RowBox[{
-          RowBox[{"1", "-", "k"}], ",", 
-          RowBox[{"-", "1"}]}], "]"}], "+", 
-        RowBox[{"2", " ", "\[Pi]", " ", 
-         RowBox[{"C", "[", "1", "]"}]}]}], ",", 
-       RowBox[{
-        RowBox[{"C", "[", "1", "]"}], "\[Element]", "Integers"}]}], "]"}]}], 
-    "}"}], ",", 
-   RowBox[{"{", 
-    RowBox[{"\[Phi]", "\[Rule]", 
-     RowBox[{"ConditionalExpression", "[", 
-      RowBox[{
-       RowBox[{
-        RowBox[{"ArcTan", "[", 
-         RowBox[{
-          RowBox[{
-           RowBox[{"-", "1"}], "+", "k"}], ",", "1"}], "]"}], "+", 
-        RowBox[{"2", " ", "\[Pi]", " ", 
-         RowBox[{"C", "[", "1", "]"}]}]}], ",", 
-       RowBox[{
-        RowBox[{"C", "[", "1", "]"}], "\[Element]", "Integers"}]}], "]"}]}], 
-    "}"}]}], "}"}]], "Output",
- CellChangeTimes->{
-  3.698339203521786*^9, {3.6983392496957865`*^9, 3.698339296528786*^9}, {
-   3.698339537908286*^9, 3.698339547205286*^9}, {3.698339656118286*^9, 
-   3.698339671271286*^9}, {3.6983415864422865`*^9, 3.698341600573286*^9}, 
-   3.698341849014286*^9, 3.698342144492286*^9, 3.6983447910587864`*^9, 
-   3.698352060811883*^9, 3.698352359510883*^9, 3.698353085447383*^9, 
-   3.698353168929383*^9, 3.698353535813383*^9, 3.6983537149763827`*^9, 
-   3.6983538053353825`*^9, 3.6983538685243826`*^9, 3.698353940098383*^9, 
-   3.698355162184383*^9, 3.6983553726603827`*^9, 3.6984828308390436`*^9, 
-   3.6984857325622244`*^9, 3.698487315713785*^9, 3.6984884845812473`*^9, 
-   3.698491710994173*^9, 3.6984921491065803`*^9, 3.702469818776538*^9, 
-   3.7024711680215654`*^9, 3.702471444166233*^9}]
-}, Open  ]],
-
-Cell[BoxData[
- RowBox[{
-  RowBox[{"(*", " ", 
-   RowBox[{"Pick", " ", "one", " ", "of", " ", "choices", " ", "above"}], " ",
-    "*)"}], "\[IndentingNewLine]", 
-  RowBox[{
-   RowBox[{"phi", "=", " ", 
-    RowBox[{"{", 
-     RowBox[{"\[Phi]", "\[Rule]", 
-      RowBox[{"ArcTan", "[", 
-       RowBox[{
-        RowBox[{
-         RowBox[{"-", "1"}], "+", "k"}], ",", "1"}], "]"}]}], "}"}]}], 
-   ";"}]}]], "Input",
- CellChangeTimes->{{3.6983399538832865`*^9, 3.698339955773286*^9}, {
-   3.6983399975932865`*^9, 3.698340034858286*^9}, {3.698340070573286*^9, 
-   3.698340075615286*^9}, 3.6983409303432865`*^9, 3.6983413510362864`*^9, 
-   3.6983420301802864`*^9, {3.6983528738283825`*^9, 3.698352886015383*^9}, {
-   3.698353949074383*^9, 3.698353949434383*^9}, {3.6984809705293655`*^9, 
-   3.6984809862794175`*^9}, 3.698482822495236*^9, {3.6984917280255413`*^9, 
-   3.6984917391506186`*^9}, {3.6984922399197197`*^9, 3.6984922573416986`*^9}}],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{
-  RowBox[{"(*", " ", 
-   RowBox[{
-   "Confirm", " ", "it", " ", "satisfies", " ", "the", " ", "equation"}], " ",
-    "*)"}], "\[IndentingNewLine]", 
-  RowBox[{
-   RowBox[{
-    RowBox[{"x2", "[", 
-     RowBox[{"2", "\[Pi]"}], "]"}], "/.", "phi"}], "//", 
-   "FullSimplify"}]}]], "Input",
- CellChangeTimes->{{3.698491761963279*^9, 3.6984918426357317`*^9}, {
-  3.698492107278162*^9, 3.698492163403551*^9}}],
-
-Cell[BoxData["0"], "Output",
- CellChangeTimes->{{3.698491802479151*^9, 3.698491811807376*^9}, {
-   3.6984921565597324`*^9, 3.698492164184806*^9}, 3.6984922457791023`*^9, 
-   3.7024698454804335`*^9, 3.7024711681778355`*^9, 3.7024714442599993`*^9}]
-}, Open  ]],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{
-  RowBox[{"(*", " ", 
-   RowBox[{"Set", " ", "up", " ", "Adjoint", " ", "ODE"}], " ", "*)"}], 
-  "\[IndentingNewLine]", 
-  RowBox[{
-   RowBox[{
-    RowBox[{"las", " ", "=", " ", 
-     RowBox[{"{", 
-      RowBox[{
-       RowBox[{"\[Lambda]1", "[", "t", "]"}], ",", " ", 
-       RowBox[{"\[Lambda]2", "[", "t", "]"}]}], "}"}]}], ";"}], 
-   "\[IndentingNewLine]", 
-   RowBox[{"adjode", " ", "=", " ", 
-    RowBox[{
-     RowBox[{
-      RowBox[{"-", 
-       RowBox[{"D", "[", 
-        RowBox[{"las", ",", "t"}], "]"}]}], " ", "-", " ", 
-      RowBox[{"las", ".", "fx"}]}], " ", "\[Equal]", 
-     RowBox[{"{", 
-      RowBox[{"0", ",", "0"}], "}"}]}]}]}]}]], "Input",
- CellChangeTimes->{{3.698344275370286*^9, 3.698344276240286*^9}, 
-   3.698344800983786*^9, {3.698350193880286*^9, 3.698350246098286*^9}, {
-   3.6983503350902863`*^9, 3.6983503410432863`*^9}, {3.6983503973032866`*^9, 
-   3.6983503974632864`*^9}, {3.6983505674733963`*^9, 3.698350626751192*^9}, {
-   3.6983506584852996`*^9, 3.6983507030847254`*^9}, {3.698350760121249*^9, 
-   3.6983507766418743`*^9}, {3.698351192731891*^9, 3.6983511977182407`*^9}, {
-   3.6983514496160755`*^9, 3.698351450279089*^9}, {3.6983540522993827`*^9, 
-   3.6983540530293827`*^9}, {3.6984827559947863`*^9, 3.69848276682298*^9}, {
-   3.6984922676386523`*^9, 3.6984922932481966`*^9}, 3.7024716355575647`*^9}],
-
-Cell[BoxData[
- RowBox[{
-  RowBox[{"{", 
-   RowBox[{
-    RowBox[{
-     RowBox[{"k", " ", 
-      RowBox[{"\[Lambda]2", "[", "t", "]"}]}], "-", 
-     RowBox[{
-      SuperscriptBox["\[Lambda]1", "\[Prime]",
-       MultilineFunction->None], "[", "t", "]"}]}], ",", 
-    RowBox[{
-     RowBox[{"-", 
-      RowBox[{"\[Lambda]1", "[", "t", "]"}]}], "+", 
-     RowBox[{"\[Lambda]2", "[", "t", "]"}], "-", 
-     RowBox[{
-      SuperscriptBox["\[Lambda]2", "\[Prime]",
-       MultilineFunction->None], "[", "t", "]"}]}]}], "}"}], "\[Equal]", 
-  RowBox[{"{", 
-   RowBox[{"0", ",", "0"}], "}"}]}]], "Output",
- CellChangeTimes->{3.7024716361356926`*^9}]
-}, Open  ]],
-
-Cell[BoxData[
- RowBox[{
-  RowBox[{"eta2", " ", "=", " ", 
-   RowBox[{"{", 
-    RowBox[{"\[Eta]2", ",", " ", "\[Eta]3"}], "}"}]}], ";"}]], "Input",
- CellChangeTimes->{3.6984827698855076`*^9}],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[{
- RowBox[{"labc1", " ", "=", " ", 
-  RowBox[{
-   RowBox[{"-", 
-    RowBox[{"{", 
-     RowBox[{
-      RowBox[{"\[Lambda]1", "[", "0", "]"}], ",", 
-      RowBox[{"\[Lambda]2", "[", "0", "]"}]}], "}"}]}], "+", 
-   RowBox[{
-    RowBox[{"{", 
-     RowBox[{"\[Lambda]3", ",", "\[Lambda]4", ",", "\[Lambda]5"}], "}"}], ".", 
-    RowBox[{"{", 
-     RowBox[{
-      RowBox[{"{", 
-       RowBox[{
-        RowBox[{"-", "1"}], ",", "0"}], "}"}], ",", 
-      RowBox[{"{", 
-       RowBox[{"0", ",", 
-        RowBox[{"-", "1"}]}], "}"}], ",", 
-      RowBox[{"{", 
-       RowBox[{"0", ",", "1"}], "}"}]}], "}"}]}], "+", 
-   RowBox[{"\[Eta]1", 
-    RowBox[{"{", 
-     RowBox[{"1", ",", "0"}], "}"}]}]}]}], "\[IndentingNewLine]", 
- RowBox[{"labc2", " ", "=", " ", 
-  RowBox[{
-   RowBox[{"{", 
-    RowBox[{
-     RowBox[{"\[Lambda]1", "[", 
-      RowBox[{"2", "\[Pi]"}], "]"}], ",", 
-     RowBox[{"\[Lambda]2", "[", 
-      RowBox[{"2", "\[Pi]"}], "]"}]}], "}"}], "+", 
-   RowBox[{
-    RowBox[{"{", 
-     RowBox[{"\[Lambda]3", ",", "\[Lambda]4", ",", "\[Lambda]5"}], "}"}], ".", 
-    RowBox[{"{", 
-     RowBox[{
-      RowBox[{"{", 
-       RowBox[{"1", ",", "0"}], "}"}], ",", 
-      RowBox[{"{", 
-       RowBox[{"0", ",", "1"}], "}"}], ",", 
-      RowBox[{"{", 
-       RowBox[{"0", ",", "0"}], "}"}]}], "}"}]}]}]}]}], "Input",
- CellChangeTimes->{{3.6983426313532863`*^9, 3.698342774848286*^9}, {
-   3.698342832052286*^9, 3.6983429412872863`*^9}, {3.6983434197547865`*^9, 
-   3.6983434217047863`*^9}, {3.6983511324316587`*^9, 3.698351135651884*^9}, {
-   3.6983521476898828`*^9, 3.6983521563508825`*^9}, {3.698354944716383*^9, 
-   3.698354953875383*^9}, {3.698355107882383*^9, 3.6983551100293827`*^9}, {
-   3.6983553876773825`*^9, 3.698355389584383*^9}, 3.698485656921091*^9, {
-   3.7024697043669877`*^9, 3.702469705398225*^9}, {3.702470371974768*^9, 
-   3.702470379959222*^9}}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   RowBox[{"\[Eta]1", "-", "\[Lambda]3", "-", 
-    RowBox[{"\[Lambda]1", "[", "0", "]"}]}], ",", 
-   RowBox[{
-    RowBox[{"-", "\[Lambda]4"}], "+", "\[Lambda]5", "-", 
-    RowBox[{"\[Lambda]2", "[", "0", "]"}]}]}], "}"}]], "Output",
- CellChangeTimes->{3.7024697080389476`*^9, 3.702469861059033*^9, 
-  3.7024711832716293`*^9, 3.702471444353758*^9, 3.7024715959636636`*^9, 
-  3.702471715885981*^9}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   RowBox[{"\[Lambda]3", "+", 
-    RowBox[{"\[Lambda]1", "[", 
-     RowBox[{"2", " ", "\[Pi]"}], "]"}]}], ",", 
-   RowBox[{"\[Lambda]4", "+", 
-    RowBox[{"\[Lambda]2", "[", 
-     RowBox[{"2", " ", "\[Pi]"}], "]"}]}]}], "}"}]], "Output",
- CellChangeTimes->{3.7024697080389476`*^9, 3.702469861059033*^9, 
-  3.7024711832716293`*^9, 3.702471444353758*^9, 3.7024715959636636`*^9, 
-  3.702471715901619*^9}]
-}, Open  ]],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[{
- RowBox[{
-  RowBox[{"labc1", " ", "=", 
-   RowBox[{"labc1", " ", "\[Equal]", " ", 
-    RowBox[{"{", 
-     RowBox[{"0", ",", "0"}], "}"}]}]}], ";"}], "\[IndentingNewLine]", 
- RowBox[{"lambdas", " ", "=", 
-  RowBox[{"Flatten", "[", 
-   RowBox[{"Assuming", "[", 
-    RowBox[{
-     RowBox[{
-      RowBox[{"k", "\[Element]", "Reals"}], "&&", 
-      RowBox[{"k", ">", 
-       RowBox[{"1", "/", "4"}]}], "&&", 
-      RowBox[{"\[Lambda]5", " ", "\[Element]", "Reals"}]}], ",", 
-     RowBox[{"FullSimplify", "[", 
-      RowBox[{"DSolve", "[", 
-       RowBox[{
-        RowBox[{"Flatten", "[", 
-         RowBox[{"{", 
-          RowBox[{"adjode", ",", " ", "labc1"}], "}"}], "]"}], ",", 
-        RowBox[{"{", 
-         RowBox[{
-          RowBox[{"\[Lambda]1", "[", "t", "]"}], ",", 
-          RowBox[{"\[Lambda]2", "[", "t", "]"}]}], "}"}], ",", "t"}], "]"}], 
-      "]"}]}], "]"}], "]"}]}]}], "Input",
- CellChangeTimes->{{3.698340108322286*^9, 3.6983403225292864`*^9}, {
-   3.698340363143286*^9, 3.698340368914286*^9}, {3.6983405236522865`*^9, 
-   3.698340525322286*^9}, {3.698340572759286*^9, 3.698340577710286*^9}, {
-   3.6983406768192863`*^9, 3.698340704422286*^9}, {3.698340765052286*^9, 
-   3.698340793099286*^9}, {3.698340840762286*^9, 3.6983408613432865`*^9}, {
-   3.698340919594286*^9, 3.6983409260952864`*^9}, 3.6983416427272863`*^9, {
-   3.6983425319452863`*^9, 3.698342550323286*^9}, {3.698342979676286*^9, 
-   3.698342985606286*^9}, {3.698344013694786*^9, 3.698344037722786*^9}, {
-   3.698344172441286*^9, 3.698344198429286*^9}, {3.6983442835862865`*^9, 
-   3.6983443142862864`*^9}, {3.698344482732786*^9, 3.698344490745786*^9}, {
-   3.6983445953817863`*^9, 3.698344595944786*^9}, {3.6983453044267864`*^9, 
-   3.698345330246786*^9}, {3.6983453606127863`*^9, 3.698345362916786*^9}, {
-   3.698345432811286*^9, 3.698345459779786*^9}, {3.698345540066286*^9, 
-   3.6983455568032866`*^9}, {3.6983456015862865`*^9, 3.698345609000286*^9}, {
-   3.6983512623487883`*^9, 3.698351314567459*^9}, {3.698351361110735*^9, 
-   3.6983513840997486`*^9}, 3.698352115819883*^9, {3.6983521881008825`*^9, 
-   3.698352188672883*^9}, 3.698492297154484*^9, {3.7024713916191454`*^9, 
-   3.7024714137754774`*^9}, {3.702471470244454*^9, 3.702471539322853*^9}, {
-   3.7024716069949646`*^9, 3.7024716103543835`*^9}, {3.702471652417016*^9, 
-   3.7024716796202345`*^9}}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   RowBox[{
-    RowBox[{"\[Lambda]1", "[", "t", "]"}], "\[Rule]", 
-    FractionBox[
-     RowBox[{
-      SuperscriptBox["\[ExponentialE]", 
-       RowBox[{"t", "/", "2"}]], " ", 
-      RowBox[{"(", 
-       RowBox[{
-        RowBox[{
-         SqrtBox[
-          RowBox[{
-           RowBox[{"-", "1"}], "+", 
-           RowBox[{"4", " ", "k"}]}]], " ", 
-         RowBox[{"(", 
-          RowBox[{"\[Eta]1", "-", "\[Lambda]3"}], ")"}], " ", 
-         RowBox[{"Cos", "[", 
-          RowBox[{
-           FractionBox["1", "2"], " ", 
-           SqrtBox[
-            RowBox[{
-             RowBox[{"-", "1"}], "+", 
-             RowBox[{"4", " ", "k"}]}]], " ", "t"}], "]"}]}], "+", 
-        RowBox[{
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{"-", "\[Eta]1"}], "+", "\[Lambda]3", "-", 
-           RowBox[{"2", " ", "k", " ", "\[Lambda]4"}], "+", 
-           RowBox[{"2", " ", "k", " ", "\[Lambda]5"}]}], ")"}], " ", 
-         RowBox[{"Sin", "[", 
-          RowBox[{
-           FractionBox["1", "2"], " ", 
-           SqrtBox[
-            RowBox[{
-             RowBox[{"-", "1"}], "+", 
-             RowBox[{"4", " ", "k"}]}]], " ", "t"}], "]"}]}]}], ")"}]}], 
-     SqrtBox[
-      RowBox[{
-       RowBox[{"-", "1"}], "+", 
-       RowBox[{"4", " ", "k"}]}]]]}], ",", 
-   RowBox[{
-    RowBox[{"\[Lambda]2", "[", "t", "]"}], "\[Rule]", 
-    FractionBox[
-     RowBox[{
-      SuperscriptBox["\[ExponentialE]", 
-       RowBox[{"t", "/", "2"}]], " ", 
-      RowBox[{"(", 
-       RowBox[{
-        RowBox[{
-         SqrtBox[
-          RowBox[{
-           RowBox[{"-", "1"}], "+", 
-           RowBox[{"4", " ", "k"}]}]], " ", 
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{"-", "\[Lambda]4"}], "+", "\[Lambda]5"}], ")"}], " ", 
-         RowBox[{"Cos", "[", 
-          RowBox[{
-           FractionBox["1", "2"], " ", 
-           SqrtBox[
-            RowBox[{
-             RowBox[{"-", "1"}], "+", 
-             RowBox[{"4", " ", "k"}]}]], " ", "t"}], "]"}]}], "+", 
-        RowBox[{
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{
-            RowBox[{"-", "2"}], " ", "\[Eta]1"}], "+", 
-           RowBox[{"2", " ", "\[Lambda]3"}], "-", "\[Lambda]4", "+", 
-           "\[Lambda]5"}], ")"}], " ", 
-         RowBox[{"Sin", "[", 
-          RowBox[{
-           FractionBox["1", "2"], " ", 
-           SqrtBox[
-            RowBox[{
-             RowBox[{"-", "1"}], "+", 
-             RowBox[{"4", " ", "k"}]}]], " ", "t"}], "]"}]}]}], ")"}]}], 
-     SqrtBox[
-      RowBox[{
-       RowBox[{"-", "1"}], "+", 
-       RowBox[{"4", " ", "k"}]}]]]}]}], "}"}]], "Output",
- CellChangeTimes->{
-  3.6983454608502865`*^9, {3.6983455449287863`*^9, 3.6983455571657863`*^9}, 
-   3.698345610492286*^9, {3.6983512638858967`*^9, 3.6983513148874817`*^9}, 
-   3.698351378896641*^9, {3.698352116585883*^9, 3.6983521285138826`*^9}, {
-   3.698352181165883*^9, 3.698352189715883*^9}, 3.6983523828148828`*^9, 
-   3.6983530862343826`*^9, 3.698353169699383*^9, 3.6983535365833826`*^9, 
-   3.6983539771743827`*^9, 3.698355163006383*^9, 3.6983552768193827`*^9, 
-   3.698355715561383*^9, 3.698484917853468*^9, 3.698485849563043*^9, 
-   3.698487318620067*^9, 3.702469867824837*^9, 3.702471189943551*^9, 
-   3.702471448056868*^9, {3.7024715141040363`*^9, 3.702471540150962*^9}, 
-   3.702471613010603*^9, 3.7024716945890236`*^9, 3.7024717585580463`*^9}]
-}, Open  ]],
-
-Cell[BoxData[{
- RowBox[{
-  RowBox[{
-   RowBox[{"\[Lambda]1", "[", "t_", "]"}], "=", 
-   RowBox[{
-    RowBox[{"\[Lambda]1", "[", "t", "]"}], "/.", "lambdas"}]}], 
-  ";"}], "\[IndentingNewLine]", 
- RowBox[{
-  RowBox[{
-   RowBox[{"\[Lambda]2", "[", "t_", "]"}], "=", 
-   RowBox[{
-    RowBox[{"\[Lambda]2", "[", "t", "]"}], "/.", "lambdas"}]}], 
-  ";"}]}], "Input",
- CellChangeTimes->{{3.698345491329286*^9, 3.698345527741786*^9}, {
-  3.698352328434883*^9, 3.6983523367708826`*^9}, {3.698352436820883*^9, 
-  3.6983524402898827`*^9}, {3.698353067567383*^9, 3.698353069547383*^9}, {
-  3.6983531081043825`*^9, 3.698353111464383*^9}, {3.698353141593383*^9, 
-  3.6983531514433827`*^9}}],
-
-Cell[BoxData[
- RowBox[{"la34", " ", "=", " ", 
-  RowBox[{
-   RowBox[{
-    RowBox[{"Solve", "[", 
-     RowBox[{
-      RowBox[{"labc2", " ", "\[Equal]", " ", 
-       RowBox[{"{", 
-        RowBox[{"0", ",", "0"}], "}"}]}], ",", " ", 
-      RowBox[{"{", 
-       RowBox[{"\[Lambda]3", ",", " ", "\[Lambda]4"}], "}"}]}], "]"}], "//", 
-    "Flatten"}], "//", "FullSimplify"}]}]], "Input",
- CellChangeTimes->{{3.7024720400903373`*^9, 3.7024721105124626`*^9}, {
-  3.7024723531227427`*^9, 3.702472371310302*^9}}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   RowBox[{"\[Lambda]3", "\[Rule]", 
-    RowBox[{"-", 
-     FractionBox[
-      RowBox[{
-       RowBox[{
-        SuperscriptBox["\[ExponentialE]", "\[Pi]"], " ", 
-        RowBox[{"(", 
-         RowBox[{
-          RowBox[{"-", "1"}], "+", 
-          RowBox[{"4", " ", "k"}]}], ")"}], " ", "\[Eta]1"}], "+", 
-       RowBox[{
-        RowBox[{"(", 
-         RowBox[{"\[Eta]1", "-", 
-          RowBox[{"4", " ", "k", " ", "\[Eta]1"}]}], ")"}], " ", 
-        RowBox[{"Cos", "[", 
-         RowBox[{
-          SqrtBox[
-           RowBox[{
-            RowBox[{"-", "1"}], "+", 
-            RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}]}], "+", 
-       RowBox[{
-        SqrtBox[
-         RowBox[{
-          RowBox[{"-", "1"}], "+", 
-          RowBox[{"4", " ", "k"}]}]], " ", 
-        RowBox[{"(", 
-         RowBox[{"\[Eta]1", "-", 
-          RowBox[{"2", " ", "k", " ", "\[Lambda]5"}]}], ")"}], " ", 
-        RowBox[{"Sin", "[", 
-         RowBox[{
-          SqrtBox[
-           RowBox[{
-            RowBox[{"-", "1"}], "+", 
-            RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}]}]}], 
-      RowBox[{"2", " ", 
-       RowBox[{"(", 
-        RowBox[{
-         RowBox[{"-", "1"}], "+", 
-         RowBox[{"4", " ", "k"}]}], ")"}], " ", 
-       RowBox[{"(", 
-        RowBox[{
-         RowBox[{"Cos", "[", 
-          RowBox[{
-           SqrtBox[
-            RowBox[{
-             RowBox[{"-", "1"}], "+", 
-             RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}], "-", 
-         RowBox[{"Cosh", "[", "\[Pi]", "]"}]}], ")"}]}]]}]}], ",", 
-   RowBox[{"\[Lambda]4", "\[Rule]", 
-    FractionBox[
-     RowBox[{
-      RowBox[{
-       RowBox[{"-", 
-        SuperscriptBox["\[ExponentialE]", "\[Pi]"]}], " ", 
-       RowBox[{"(", 
-        RowBox[{
-         RowBox[{"-", "1"}], "+", 
-         RowBox[{"4", " ", "k"}]}], ")"}], " ", "\[Lambda]5"}], "+", 
-      RowBox[{
-       RowBox[{"(", 
-        RowBox[{
-         RowBox[{"-", "1"}], "+", 
-         RowBox[{"4", " ", "k"}]}], ")"}], " ", "\[Lambda]5", " ", 
-       RowBox[{"Cos", "[", 
-        RowBox[{
-         SqrtBox[
-          RowBox[{
-           RowBox[{"-", "1"}], "+", 
-           RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}]}], "+", 
-      RowBox[{
-       SqrtBox[
-        RowBox[{
-         RowBox[{"-", "1"}], "+", 
-         RowBox[{"4", " ", "k"}]}]], " ", 
-       RowBox[{"(", 
-        RowBox[{
-         RowBox[{
-          RowBox[{"-", "2"}], " ", "\[Eta]1"}], "+", "\[Lambda]5"}], ")"}], 
-       " ", 
-       RowBox[{"Sin", "[", 
-        RowBox[{
-         SqrtBox[
-          RowBox[{
-           RowBox[{"-", "1"}], "+", 
-           RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}]}]}], 
-     RowBox[{"2", " ", 
-      RowBox[{"(", 
-       RowBox[{
-        RowBox[{"-", "1"}], "+", 
-        RowBox[{"4", " ", "k"}]}], ")"}], " ", 
-      RowBox[{"(", 
-       RowBox[{
-        RowBox[{"Cos", "[", 
-         RowBox[{
-          SqrtBox[
-           RowBox[{
-            RowBox[{"-", "1"}], "+", 
-            RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}], "-", 
-        RowBox[{"Cosh", "[", "\[Pi]", "]"}]}], ")"}]}]]}]}], "}"}]], "Output",
- CellChangeTimes->{{3.702472356279002*^9, 3.702472383482225*^9}}],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{"\[Lambda]", " ", "=", " ", 
-  RowBox[{"Flatten", "[", 
-   RowBox[{"FullSimplify", "[", 
-    RowBox[{
-     RowBox[{"{", 
-      RowBox[{
-       RowBox[{"\[Lambda]1", "[", "t", "]"}], ",", 
-       RowBox[{"\[Lambda]2", "[", "t", "]"}]}], "}"}], "/.", "la34"}], "]"}], 
-   "]"}]}]], "Input",
- CellChangeTimes->{{3.698353418791383*^9, 3.6983534452603827`*^9}, {
-   3.6983534754843826`*^9, 3.698353495940383*^9}, {3.698353586261383*^9, 
-   3.698353588284383*^9}, 3.698485913875984*^9, 3.698486040517479*^9, {
-   3.698489532697862*^9, 3.6984895347916336`*^9}, {3.702472315528845*^9, 
-   3.7024723202163672`*^9}}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   FractionBox[
-    RowBox[{
-     SuperscriptBox["\[ExponentialE]", 
-      RowBox[{
-       RowBox[{"-", "\[Pi]"}], "+", 
-       FractionBox["t", "2"]}]], " ", 
-     RowBox[{"(", 
-      RowBox[{
-       RowBox[{
-        SuperscriptBox["\[ExponentialE]", "\[Pi]"], " ", 
-        SqrtBox[
-         RowBox[{
-          RowBox[{"-", "1"}], "+", 
-          RowBox[{"4", " ", "k"}]}]], " ", "\[Eta]1", " ", 
-        RowBox[{"Cos", "[", 
-         RowBox[{
-          FractionBox["1", "2"], " ", 
-          SqrtBox[
-           RowBox[{
-            RowBox[{"-", "1"}], "+", 
-            RowBox[{"4", " ", "k"}]}]], " ", 
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{"2", " ", "\[Pi]"}], "-", "t"}], ")"}]}], "]"}]}], "-", 
-       RowBox[{
-        SqrtBox[
-         RowBox[{
-          RowBox[{"-", "1"}], "+", 
-          RowBox[{"4", " ", "k"}]}]], " ", "\[Eta]1", " ", 
-        RowBox[{"Cos", "[", 
-         RowBox[{
-          FractionBox["1", "2"], " ", 
-          SqrtBox[
-           RowBox[{
-            RowBox[{"-", "1"}], "+", 
-            RowBox[{"4", " ", "k"}]}]], " ", "t"}], "]"}]}], "+", 
-       RowBox[{
-        RowBox[{"(", 
-         RowBox[{"\[Eta]1", "-", 
-          RowBox[{"2", " ", "k", " ", "\[Lambda]5"}]}], ")"}], " ", 
-        RowBox[{"(", 
-         RowBox[{
-          RowBox[{
-           SuperscriptBox["\[ExponentialE]", "\[Pi]"], " ", 
-           RowBox[{"Sin", "[", 
-            RowBox[{
-             FractionBox["1", "2"], " ", 
-             SqrtBox[
-              RowBox[{
-               RowBox[{"-", "1"}], "+", 
-               RowBox[{"4", " ", "k"}]}]], " ", 
-             RowBox[{"(", 
-              RowBox[{
-               RowBox[{"2", " ", "\[Pi]"}], "-", "t"}], ")"}]}], "]"}]}], "+", 
-          RowBox[{"Sin", "[", 
-           RowBox[{
-            FractionBox["1", "2"], " ", 
-            SqrtBox[
-             RowBox[{
-              RowBox[{"-", "1"}], "+", 
-              RowBox[{"4", " ", "k"}]}]], " ", "t"}], "]"}]}], ")"}]}]}], 
-      ")"}]}], 
-    RowBox[{"2", " ", 
-     SqrtBox[
-      RowBox[{
-       RowBox[{"-", "1"}], "+", 
-       RowBox[{"4", " ", "k"}]}]], " ", 
-     RowBox[{"(", 
-      RowBox[{
-       RowBox[{"Cos", "[", 
-        RowBox[{
-         SqrtBox[
-          RowBox[{
-           RowBox[{"-", "1"}], "+", 
-           RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}], "-", 
-       RowBox[{"Cosh", "[", "\[Pi]", "]"}]}], ")"}]}]], ",", 
-   FractionBox[
-    RowBox[{
-     SuperscriptBox["\[ExponentialE]", 
-      RowBox[{
-       RowBox[{"-", "\[Pi]"}], "+", 
-       FractionBox["t", "2"]}]], " ", 
-     RowBox[{"(", 
-      RowBox[{
-       RowBox[{
-        SuperscriptBox["\[ExponentialE]", "\[Pi]"], " ", 
-        SqrtBox[
-         RowBox[{
-          RowBox[{"-", "1"}], "+", 
-          RowBox[{"4", " ", "k"}]}]], " ", "\[Lambda]5", " ", 
-        RowBox[{"Cos", "[", 
-         RowBox[{
-          FractionBox["1", "2"], " ", 
-          SqrtBox[
-           RowBox[{
-            RowBox[{"-", "1"}], "+", 
-            RowBox[{"4", " ", "k"}]}]], " ", 
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{"2", " ", "\[Pi]"}], "-", "t"}], ")"}]}], "]"}]}], "-", 
-       RowBox[{
-        SqrtBox[
-         RowBox[{
-          RowBox[{"-", "1"}], "+", 
-          RowBox[{"4", " ", "k"}]}]], " ", "\[Lambda]5", " ", 
-        RowBox[{"Cos", "[", 
-         RowBox[{
-          FractionBox["1", "2"], " ", 
-          SqrtBox[
-           RowBox[{
-            RowBox[{"-", "1"}], "+", 
-            RowBox[{"4", " ", "k"}]}]], " ", "t"}], "]"}]}], "+", 
-       RowBox[{
-        RowBox[{"(", 
-         RowBox[{
-          RowBox[{"2", " ", "\[Eta]1"}], "-", "\[Lambda]5"}], ")"}], " ", 
-        RowBox[{"(", 
-         RowBox[{
-          RowBox[{
-           SuperscriptBox["\[ExponentialE]", "\[Pi]"], " ", 
-           RowBox[{"Sin", "[", 
-            RowBox[{
-             FractionBox["1", "2"], " ", 
-             SqrtBox[
-              RowBox[{
-               RowBox[{"-", "1"}], "+", 
-               RowBox[{"4", " ", "k"}]}]], " ", 
-             RowBox[{"(", 
-              RowBox[{
-               RowBox[{"2", " ", "\[Pi]"}], "-", "t"}], ")"}]}], "]"}]}], "+", 
-          RowBox[{"Sin", "[", 
-           RowBox[{
-            FractionBox["1", "2"], " ", 
-            SqrtBox[
-             RowBox[{
-              RowBox[{"-", "1"}], "+", 
-              RowBox[{"4", " ", "k"}]}]], " ", "t"}], "]"}]}], ")"}]}]}], 
-      ")"}]}], 
-    RowBox[{"2", " ", 
-     SqrtBox[
-      RowBox[{
-       RowBox[{"-", "1"}], "+", 
-       RowBox[{"4", " ", "k"}]}]], " ", 
-     RowBox[{"(", 
-      RowBox[{
-       RowBox[{"Cos", "[", 
-        RowBox[{
-         SqrtBox[
-          RowBox[{
-           RowBox[{"-", "1"}], "+", 
-           RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}], "-", 
-       RowBox[{"Cosh", "[", "\[Pi]", "]"}]}], ")"}]}]]}], "}"}]], "Output",
- CellChangeTimes->{{3.6983534259913826`*^9, 3.698353449784383*^9}, {
-   3.698353486467383*^9, 3.698353496280383*^9}, 3.6983535605023828`*^9, 
-   3.698354009422383*^9, 3.6983557305903826`*^9, 3.698484941728634*^9, 
-   3.6984859473918486`*^9, 3.6984859811576667`*^9, 3.6984860461112547`*^9, {
-   3.6984873348701887`*^9, 3.698487335417054*^9}, 3.702469958233736*^9, 
-   3.7024723439039445`*^9, 3.7024724512480907`*^9}]
-}, Open  ]],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{"\[Lambda]", "/.", 
-  RowBox[{"k", "\[Rule]", "1"}]}]], "Input",
- CellChangeTimes->{{3.6984895389166503`*^9, 3.698489544494831*^9}}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   FractionBox[
-    RowBox[{
-     SuperscriptBox["\[ExponentialE]", 
-      RowBox[{
-       RowBox[{"-", "\[Pi]"}], "+", 
-       FractionBox["t", "2"]}]], " ", 
-     RowBox[{"(", 
-      RowBox[{"\[Eta]1", "-", "\[Lambda]5"}], ")"}], " ", 
-     RowBox[{"(", 
-      RowBox[{
-       RowBox[{
-        SuperscriptBox["\[ExponentialE]", "\[Pi]"], " ", 
-        RowBox[{"Sin", "[", 
-         RowBox[{
-          FractionBox["1", "2"], " ", 
-          SqrtBox["3"], " ", 
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{"2", " ", "\[Pi]"}], "-", "t"}], ")"}]}], "]"}]}], "+", 
-       RowBox[{"Sin", "[", 
-        FractionBox[
-         RowBox[{
-          SqrtBox["3"], " ", "t"}], "2"], "]"}]}], ")"}]}], 
-    RowBox[{
-     SqrtBox["3"], " ", 
-     RowBox[{"(", 
-      RowBox[{
-       RowBox[{"Cos", "[", 
-        RowBox[{
-         SqrtBox["3"], " ", "\[Pi]"}], "]"}], "-", 
-       RowBox[{"Cosh", "[", "\[Pi]", "]"}]}], ")"}]}]], ",", 
-   RowBox[{"-", 
-    FractionBox[
-     RowBox[{
-      SuperscriptBox["\[ExponentialE]", 
-       RowBox[{"t", "/", "2"}]], " ", 
-      RowBox[{"(", 
-       RowBox[{"\[Eta]1", "-", "\[Lambda]5"}], ")"}], " ", 
-      RowBox[{"(", 
-       RowBox[{
-        RowBox[{
-         RowBox[{"-", "3"}], " ", 
-         SuperscriptBox["\[ExponentialE]", "\[Pi]"], " ", 
-         RowBox[{"Cos", "[", 
-          RowBox[{
-           FractionBox["1", "2"], " ", 
-           SqrtBox["3"], " ", 
-           RowBox[{"(", 
-            RowBox[{
-             RowBox[{"2", " ", "\[Pi]"}], "-", "t"}], ")"}]}], "]"}]}], "+", 
-        RowBox[{"3", " ", 
-         RowBox[{"Cos", "[", 
-          FractionBox[
-           RowBox[{
-            SqrtBox["3"], " ", "t"}], "2"], "]"}]}], "+", 
-        RowBox[{
-         SqrtBox["3"], " ", 
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{
-            SuperscriptBox["\[ExponentialE]", "\[Pi]"], " ", 
-            RowBox[{"Sin", "[", 
-             RowBox[{
-              FractionBox["1", "2"], " ", 
-              SqrtBox["3"], " ", 
-              RowBox[{"(", 
-               RowBox[{
-                RowBox[{"2", " ", "\[Pi]"}], "-", "t"}], ")"}]}], "]"}]}], 
-           "+", 
-           RowBox[{"Sin", "[", 
-            FractionBox[
-             RowBox[{
-              SqrtBox["3"], " ", "t"}], "2"], "]"}]}], ")"}]}]}], ")"}]}], 
-     RowBox[{"3", " ", 
-      RowBox[{"(", 
-       RowBox[{"1", "+", 
-        SuperscriptBox["\[ExponentialE]", 
-         RowBox[{"2", " ", "\[Pi]"}]], "-", 
-        RowBox[{"2", " ", 
-         SuperscriptBox["\[ExponentialE]", "\[Pi]"], " ", 
-         RowBox[{"Cos", "[", 
-          RowBox[{
-           SqrtBox["3"], " ", "\[Pi]"}], "]"}]}]}], ")"}]}]]}]}], 
-  "}"}]], "Output",
- CellChangeTimes->{3.6984895450260773`*^9}]
-}, Open  ]],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{
-  RowBox[{"(*", " ", 
-   RowBox[{"Stationarity", " ", "Equation"}], " ", "*)"}], 
-  "\[IndentingNewLine]", 
-  RowBox[{"dp", " ", "=", " ", 
-   RowBox[{
-    RowBox[{"-", 
-     RowBox[{"Integrate", "[", 
-      RowBox[{
-       RowBox[{"\[Lambda]", ".", "fp"}], ",", 
-       RowBox[{"{", 
-        RowBox[{"t", ",", "0", ",", 
-         RowBox[{"2", "\[Pi]"}]}], "}"}]}], "]"}]}], "+", 
-    "eta2"}]}]}]], "Input",
- CellChangeTimes->{{3.6983540328053827`*^9, 3.698354067287383*^9}, 
-   3.6983542091733828`*^9, {3.702472476357566*^9, 3.702472485466975*^9}, 
-   3.704758338002981*^9}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   RowBox[{"\[Eta]2", "+", 
-    FractionBox[
-     RowBox[{
-      RowBox[{
-       RowBox[{"(", 
-        RowBox[{
-         RowBox[{
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{"-", "2"}], "+", "k"}], ")"}], " ", "k", " ", "\[Eta]1"}],
-          "+", 
-         RowBox[{"2", " ", 
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{"-", "1"}], "+", "k"}], ")"}], " ", "\[Lambda]5"}]}], 
-        ")"}], " ", 
-       RowBox[{"Cos", "[", "\[Phi]", "]"}]}], "+", 
-      RowBox[{
-       RowBox[{"(", 
-        RowBox[{
-         RowBox[{"2", " ", 
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{"-", "1"}], "+", "k"}], ")"}], " ", "\[Eta]1"}], "-", 
-         RowBox[{
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{"-", "2"}], "+", "k"}], ")"}], " ", "k", " ", 
-          "\[Lambda]5"}]}], ")"}], " ", 
-       RowBox[{"Sin", "[", "\[Phi]", "]"}]}]}], 
-     SuperscriptBox[
-      RowBox[{"(", 
-       RowBox[{"2", "+", 
-        RowBox[{
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{"-", "2"}], "+", "k"}], ")"}], " ", "k"}]}], ")"}], 
-      "2"]]}], ",", 
-   RowBox[{"\[Eta]3", "+", 
-    FractionBox[
-     RowBox[{
-      RowBox[{
-       RowBox[{"-", 
-        RowBox[{"(", 
-         RowBox[{"\[Eta]1", "+", "\[Lambda]5", "-", 
-          RowBox[{"k", " ", "\[Lambda]5"}]}], ")"}]}], " ", 
-       RowBox[{"Cos", "[", "\[Phi]", "]"}]}], "+", 
-      RowBox[{
-       RowBox[{"(", 
-        RowBox[{
-         RowBox[{
-          RowBox[{"(", 
-           RowBox[{
-            RowBox[{"-", "1"}], "+", "k"}], ")"}], " ", "\[Eta]1"}], "+", 
-         "\[Lambda]5"}], ")"}], " ", 
-       RowBox[{"Sin", "[", "\[Phi]", "]"}]}]}], 
-     RowBox[{"2", "-", 
-      RowBox[{"2", " ", "k"}], "+", 
-      SuperscriptBox["k", "2"]}]]}]}], "}"}]], "Output",
- CellChangeTimes->{3.698356864586383*^9, 3.698357053327383*^9, 
-  3.6984850016040473`*^9, 3.6984861043460493`*^9, 3.698487062149515*^9, 
-  3.698487404276907*^9, 3.702470019844537*^9, 3.7024725267952337`*^9}]
-}, Open  ]],
-
-Cell[BoxData[
- RowBox[{"etaeq", " ", "=", 
-  RowBox[{"Flatten", "[", 
-   RowBox[{"Solve", "[", 
-    RowBox[{
-     RowBox[{
-      RowBox[{"dp", "\[Equal]", 
-       RowBox[{"{", 
-        RowBox[{"0", ",", "0"}], "}"}]}], "/.", 
-      RowBox[{"{", 
-       RowBox[{
-        RowBox[{"\[Eta]2", "\[Rule]", "0"}], ",", 
-        RowBox[{"\[Eta]3", "\[Rule]", "0"}]}], "}"}]}], ",", 
-     RowBox[{"{", 
-      RowBox[{"k", ",", "\[Phi]"}], "}"}]}], "]"}], "]"}]}]], "Input",
- CellChangeTimes->{{3.6983543656353827`*^9, 3.698354410558383*^9}, {
-   3.6983544984633827`*^9, 3.698354501533383*^9}, 3.6983570467793827`*^9, {
-   3.698484966431931*^9, 3.6984849724475994`*^9}, {3.698486253487701*^9, 
-   3.6984862849879208`*^9}, {3.698486993914698*^9, 3.6984870002741175`*^9}, {
-   3.698487114228036*^9, 3.6984871548689365`*^9}, {3.698487242728925*^9, 
-   3.69848726276031*^9}},
- NumberMarks->False],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   RowBox[{"k", "\[Rule]", "1"}], ",", 
-   RowBox[{"\[Phi]", "\[Rule]", 
-    RowBox[{"ConditionalExpression", "[", 
-     RowBox[{
-      RowBox[{"2", " ", "\[Pi]", " ", 
-       RowBox[{"C", "[", "1", "]"}]}], ",", 
-      RowBox[{
-       RowBox[{"C", "[", "1", "]"}], "\[Element]", "Integers"}]}], "]"}]}], 
-   ",", 
-   RowBox[{"k", "\[Rule]", "1"}], ",", 
-   RowBox[{"\[Phi]", "\[Rule]", 
-    RowBox[{"ConditionalExpression", "[", 
-     RowBox[{
-      RowBox[{"\[Pi]", "+", 
-       RowBox[{"2", " ", "\[Pi]", " ", 
-        RowBox[{"C", "[", "1", "]"}]}]}], ",", 
-      RowBox[{
-       RowBox[{"C", "[", "1", "]"}], "\[Element]", "Integers"}]}], "]"}]}]}], 
-  "}"}]], "Input",
- CellChangeTimes->{{3.6984883611741533`*^9, 3.6984883627054076`*^9}}],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{"dp", "/.", 
-  RowBox[{"{", 
-   RowBox[{"k", "\[Rule]", "1"}], "}"}]}]], "Input",
- CellChangeTimes->{{3.698488365033531*^9, 3.6984883711117287`*^9}}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   RowBox[{"\[Eta]2", "-", 
-    RowBox[{
-     RowBox[{"(", 
-      RowBox[{"\[Eta]1", "-", "\[Lambda]5"}], ")"}], " ", 
-     RowBox[{"Sin", "[", "\[Phi]", "]"}]}]}], ",", 
-   RowBox[{"\[Eta]3", "-", 
-    RowBox[{
-     RowBox[{"(", 
-      RowBox[{"\[Eta]1", "-", "\[Lambda]5"}], ")"}], " ", 
-     RowBox[{"Sin", "[", "\[Phi]", "]"}]}]}]}], "}"}]], "Output",
- CellChangeTimes->{3.698488372205455*^9}]
-}, Open  ]],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{"Reverse", "[", 
-  RowBox[{"{", 
-   RowBox[{
-    RowBox[{"\[Eta]2", "-", 
-     RowBox[{
-      RowBox[{"(", 
-       RowBox[{"\[Eta]1", "-", "\[Lambda]5"}], ")"}], " ", 
-      RowBox[{"Sin", "[", "\[Phi]", "]"}]}]}], ",", 
-    RowBox[{"\[Eta]3", "-", 
-     RowBox[{
-      RowBox[{"(", 
-       RowBox[{"\[Eta]1", "-", "\[Lambda]5"}], ")"}], " ", 
-      RowBox[{"Sin", "[", "\[Phi]", "]"}]}]}]}], "}"}], "]"}]], "Input",
- NumberMarks->False],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   RowBox[{"\[Eta]3", "-", 
-    RowBox[{
-     RowBox[{"(", 
-      RowBox[{"\[Eta]1", "-", "\[Lambda]5"}], ")"}], " ", 
-     RowBox[{"Sin", "[", "\[Phi]", "]"}]}]}], ",", 
-   RowBox[{"\[Eta]2", "-", 
-    RowBox[{
-     RowBox[{"(", 
-      RowBox[{"\[Eta]1", "-", "\[Lambda]5"}], ")"}], " ", 
-     RowBox[{"Sin", "[", "\[Phi]", "]"}]}]}]}], "}"}]], "Output",
- CellChangeTimes->{3.6984902865312023`*^9}]
-}, Open  ]],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{"adjsys", " ", "=", " ", 
-  RowBox[{
-   RowBox[{"{", 
-    RowBox[{"labc1", ",", "labc2", ",", "dp"}], "}"}], "//", 
-   "Flatten"}]}]], "Input",
- CellChangeTimes->{{3.6984902775779943`*^9, 3.698490322093956*^9}, {
-  3.6984904577198987`*^9, 3.698490459329275*^9}, {3.6984905835176353`*^9, 
-  3.698490584455142*^9}}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{
-   RowBox[{
-    RowBox[{"-", "\[Lambda]3"}], "-", 
-    RowBox[{"C", "[", "1", "]"}]}], ",", 
-   RowBox[{
-    RowBox[{"-", "\[Lambda]4"}], "+", "\[Lambda]5", "-", 
-    RowBox[{"C", "[", "2", "]"}]}], ",", 
-   RowBox[{"\[Lambda]3", "+", 
-    FractionBox[
-     RowBox[{
-      SuperscriptBox["\[ExponentialE]", "\[Pi]"], " ", 
-      RowBox[{"(", 
-       RowBox[{
-        RowBox[{
-         SqrtBox[
-          RowBox[{
-           RowBox[{"-", "1"}], "+", 
-           RowBox[{"4", " ", "k"}]}]], " ", 
-         RowBox[{"C", "[", "1", "]"}], " ", 
-         RowBox[{"Cos", "[", 
-          RowBox[{
-           SqrtBox[
-            RowBox[{
-             RowBox[{"-", "1"}], "+", 
-             RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}]}], "-", 
-        RowBox[{
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{"C", "[", "1", "]"}], "-", 
-           RowBox[{"2", " ", "k", " ", 
-            RowBox[{"C", "[", "2", "]"}]}]}], ")"}], " ", 
-         RowBox[{"Sin", "[", 
-          RowBox[{
-           SqrtBox[
-            RowBox[{
-             RowBox[{"-", "1"}], "+", 
-             RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}]}]}], ")"}]}], 
-     SqrtBox[
-      RowBox[{
-       RowBox[{"-", "1"}], "+", 
-       RowBox[{"4", " ", "k"}]}]]]}], ",", 
-   RowBox[{
-    RowBox[{"-", "\[Eta]1"}], "+", "\[Lambda]4", "+", 
-    FractionBox[
-     RowBox[{
-      SuperscriptBox["\[ExponentialE]", "\[Pi]"], " ", 
-      RowBox[{"(", 
-       RowBox[{
-        RowBox[{
-         SqrtBox[
-          RowBox[{
-           RowBox[{"-", "1"}], "+", 
-           RowBox[{"4", " ", "k"}]}]], " ", 
-         RowBox[{"C", "[", "2", "]"}], " ", 
-         RowBox[{"Cos", "[", 
-          RowBox[{
-           SqrtBox[
-            RowBox[{
-             RowBox[{"-", "1"}], "+", 
-             RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}]}], "+", 
-        RowBox[{
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{
-            RowBox[{"-", "2"}], " ", 
-            RowBox[{"C", "[", "1", "]"}]}], "+", 
-           RowBox[{"C", "[", "2", "]"}]}], ")"}], " ", 
-         RowBox[{"Sin", "[", 
-          RowBox[{
-           SqrtBox[
-            RowBox[{
-             RowBox[{"-", "1"}], "+", 
-             RowBox[{"4", " ", "k"}]}]], " ", "\[Pi]"}], "]"}]}]}], ")"}]}], 
-     SqrtBox[
-      RowBox[{
-       RowBox[{"-", "1"}], "+", 
-       RowBox[{"4", " ", "k"}]}]]]}], ",", 
-   RowBox[{"\[Eta]2", "+", 
-    FractionBox[
-     RowBox[{
-      RowBox[{"(", 
-       RowBox[{"\[Eta]1", "-", "\[Lambda]5"}], ")"}], " ", 
-      RowBox[{"(", 
-       RowBox[{
-        RowBox[{
-         RowBox[{"-", "2"}], " ", 
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{"-", "1"}], "+", "k"}], ")"}], " ", 
-         RowBox[{"Cos", "[", "\[Phi]", "]"}]}], "+", 
-        RowBox[{
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{"-", "2"}], "+", "k"}], ")"}], " ", "k", " ", 
-         RowBox[{"Sin", "[", "\[Phi]", "]"}]}]}], ")"}]}], 
-     SuperscriptBox[
-      RowBox[{"(", 
-       RowBox[{"2", "-", 
-        RowBox[{"2", " ", "k"}], "+", 
-        SuperscriptBox["k", "2"]}], ")"}], "2"]]}], ",", 
-   RowBox[{"\[Eta]3", "-", 
-    FractionBox[
-     RowBox[{
-      RowBox[{"(", 
-       RowBox[{"\[Eta]1", "-", "\[Lambda]5"}], ")"}], " ", 
-      RowBox[{"(", 
-       RowBox[{
-        RowBox[{
-         RowBox[{"(", 
-          RowBox[{
-           RowBox[{"-", "1"}], "+", "k"}], ")"}], " ", 
-         RowBox[{"Cos", "[", "\[Phi]", "]"}]}], "+", 
-        RowBox[{"Sin", "[", "\[Phi]", "]"}]}], ")"}]}], 
-     RowBox[{"2", "-", 
-      RowBox[{"2", " ", "k"}], "+", 
-      SuperscriptBox["k", "2"]}]]}]}], "}"}]], "Output",
- CellChangeTimes->{3.6984903892975397`*^9, 3.698490459860525*^9, 
-  3.698490585517621*^9}]
-}, Open  ]],
-
-Cell[CellGroupData[{
-
-Cell[BoxData[
- RowBox[{
-  RowBox[{"Solve", "[", 
-   RowBox[{
-    RowBox[{
-     RowBox[{"adjsys", "\[Equal]", 
-      RowBox[{"{", 
-       RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0"}], 
-       "}"}]}], "/.", 
-     RowBox[{"{", 
-      RowBox[{
-       RowBox[{"\[Eta]2", "\[Rule]", "0"}], ",", 
-       RowBox[{"\[Eta]3", "\[Rule]", "0"}]}], "}"}]}], ",", 
-    RowBox[{"{", 
-     RowBox[{
-     "\[Lambda]3", ",", "\[Lambda]4", ",", "\[Lambda]5", ",", "\[Eta]1", ",", 
-      RowBox[{"C", "[", "1", "]"}], ",", 
-      RowBox[{"C", "[", "2", "]"}]}], "}"}]}], "]"}], "//", 
-  "Simplify"}]], "Input",
- CellChangeTimes->{{3.6984903288440094`*^9, 3.6984904836107035`*^9}, {
-  3.698490523735981*^9, 3.6984905269391127`*^9}, {3.6984906322836065`*^9, 
-  3.698490673799505*^9}, {3.698490727081131*^9, 3.6984907290342655`*^9}, {
-  3.6984907674564013`*^9, 3.6984907778470974`*^9}}],
-
-Cell[BoxData[
- RowBox[{"{", 
-  RowBox[{"{", 
-   RowBox[{
-    RowBox[{"\[Lambda]3", "\[Rule]", "0"}], ",", 
-    RowBox[{"\[Lambda]4", "\[Rule]", "\[Lambda]5"}], ",", 
-    RowBox[{"\[Eta]1", "\[Rule]", "\[Lambda]5"}], ",", 
-    RowBox[{
-     RowBox[{"C", "[", "1", "]"}], "\[Rule]", "0"}], ",", 
-    RowBox[{
-     RowBox[{"C", "[", "2", "]"}], "\[Rule]", "0"}]}], "}"}], "}"}]], "Output",
- CellChangeTimes->{{3.698490282015551*^9, 3.6984903229064546`*^9}, {
-   3.698490363328616*^9, 3.698490408735158*^9}, 3.6984904847200727`*^9, 
-   3.6984905288922358`*^9, 3.6984906758464007`*^9, {3.6984907704720526`*^9, 
-   3.6984907798002377`*^9}}]
-}, Open  ]]
-},
-WindowSize->{1280, 693},
-WindowMargins->{{-8, Automatic}, {Automatic, -8}},
-Magnification:>1.1 Inherited,
-FrontEndVersion->"11.0 for Microsoft Windows (64-bit) (July 28, 2016)",
-StyleDefinitions->"Default.nb"
-]
-(* End of Notebook Content *)
-
-(* Internal cache information *)
-(*CellTagsOutline
-CellTagsIndex->{}
-*)
-(*CellTagsIndex
-CellTagsIndex->{}
-*)
-(*NotebookFileOutline
-Notebook[{
-Cell[558, 20, 447, 6, 33, "Input"],
-Cell[CellGroupData[{
-Cell[1030, 30, 2112, 58, 232, "Input"],
-Cell[3145, 90, 416, 12, 33, "Output"]
-}, Open  ]],
-Cell[CellGroupData[{
-Cell[3598, 107, 1850, 36, 56, "Input"],
-Cell[5451, 145, 7713, 213, 182, "Output"]
-}, Open  ]],
-Cell[CellGroupData[{
-Cell[13201, 363, 1858, 45, 90, "Input"],
-Cell[15062, 410, 778, 20, 53, "Output"]
-}, Open  ]],
-Cell[CellGroupData[{
-Cell[15877, 435, 435, 11, 56, "Input"],
-Cell[16315, 448, 727, 20, 53, "Output"]
-}, Open  ]],
-Cell[CellGroupData[{
-Cell[17079, 473, 1697, 33, 56, "Input"],
-Cell[18779, 508, 1779, 42, 33, "Output"]
-}, Open  ]],
-Cell[20573, 553, 934, 20, 56, "Input"],
-Cell[CellGroupData[{
-Cell[21532, 577, 427, 12, 56, "Input"],
-Cell[21962, 591, 246, 3, 33, "Output"]
-}, Open  ]],
-Cell[CellGroupData[{
-Cell[22245, 599, 1363, 30, 78, "Input"],
-Cell[23611, 631, 638, 19, 33, "Output"]
-}, Open  ]],
-Cell[24264, 653, 190, 5, 33, "Input"],
-Cell[CellGroupData[{
-Cell[24479, 662, 1868, 50, 56, "Input"],
-Cell[26350, 714, 436, 10, 33, "Output"],
-Cell[26789, 726, 441, 11, 33, "Output"]
-}, Open  ]],
-Cell[CellGroupData[{
-Cell[27267, 742, 2353, 45, 56, "Input"],
-Cell[29623, 789, 3381, 93, 128, "Output"]
-}, Open  ]],
-Cell[33019, 885, 677, 17, 56, "Input"],
-Cell[33699, 904, 502, 13, 33, "Input"],
-Cell[34204, 919, 3204, 102, 132, "Output"],
-Cell[CellGroupData[{
-Cell[37433, 1025, 629, 14, 33, "Input"],
-Cell[38065, 1041, 5269, 160, 146, "Output"]
-}, Open  ]],
-Cell[CellGroupData[{
-Cell[43371, 1206, 155, 3, 33, "Input"],
-Cell[43529, 1211, 2765, 87, 77, "Output"]
-}, Open  ]],
-Cell[CellGroupData[{
-Cell[46331, 1303, 600, 17, 56, "Input"],
-Cell[46934, 1322, 2052, 64, 55, "Output"]
-}, Open  ]],
-Cell[49001, 1389, 882, 21, 33, "Input"],
-Cell[49886, 1412, 784, 22, 33, "Input"],
-Cell[CellGroupData[{
-Cell[50695, 1438, 172, 4, 33, "Input"],
-Cell[50870, 1444, 437, 13, 33, "Output"]
-}, Open  ]],
-Cell[CellGroupData[{
-Cell[51344, 1462, 460, 14, 33, "Input"],
-Cell[51807, 1478, 439, 13, 33, "Output"]
-}, Open  ]],
-Cell[CellGroupData[{
-Cell[52283, 1496, 336, 8, 33, "Input"],
-Cell[52622, 1506, 3744, 119, 172, "Output"]
-}, Open  ]],
-Cell[CellGroupData[{
-Cell[56403, 1630, 883, 22, 33, "Input"],
-Cell[57289, 1654, 634, 14, 33, "Output"]
-}, Open  ]]
-}
-]
-*)
-
diff --git a/archive/per_Jbc.m b/archive/per_Jbc.m
deleted file mode 100644
index 1739468a8d0e629ba77ae08dbb5f8add1a71db4f..0000000000000000000000000000000000000000
--- a/archive/per_Jbc.m
+++ /dev/null
@@ -1,6 +0,0 @@
-function  Jbc = per_Jbc(data, T, x0, x1, p)
-
-Jbc = data.J;
-
-
-end
\ No newline at end of file
diff --git a/archive/per_bc.m b/archive/per_bc.m
deleted file mode 100644
index 8877a3b14b4120f060553f53599c722f55bc8b6f..0000000000000000000000000000000000000000
--- a/archive/per_bc.m
+++ /dev/null
@@ -1,27 +0,0 @@
-function [data, y] = per_bc(T, u0, u1, p)
-
-% Boundary Conditions for the oscillator
-% 1. u1(0) - u1(T) = 0 -----| Initial Postion = Final Position
-% 2. u2(0) - u2(T) = 0 -----| Initial Velocity = Final Velocity
-% 3. u3(0) - u3(1) = 0 -----| 
-% 4. u4(0) - u4(1) = 0 -----|
-% 4. u2(0) = 0 -------------| Phase Condition: Start orbit where the Velocity 
-%                           |                  is zero (max Amplitude).
-
-u01 = u0(1,:); % Initial Position
-u02 = u0(2,:); % Initial Velocity
-u03 = u0(3,:);
-u04 = u0(4,:);
-
-u11 = u1(1,:); % Final Position
-u12 = u1(2,:); % Final Velocity
-u13 = u1(3,:); 
-u14 = u1(4,:); 
-
-y(1,:) = u01 - u11;       % Periodic Position BC
-y(2,:) = u02 - u12;       % Periodic Velocity BC
-y(3,:) = u03 - u13;
-y(4,:) = u04 - u14;
-y(5,:) = u02;             % Poincare Section
-
-end
\ No newline at end of file
diff --git a/archive/per_bc_update.m b/archive/per_bc_update.m
deleted file mode 100644
index 732e312abb3c959e0203cb5aedda7c74977d900c..0000000000000000000000000000000000000000
--- a/archive/per_bc_update.m
+++ /dev/null
@@ -1,15 +0,0 @@
-function data = per_bc_update(data, T, u0, u1, p)
-
-% Update Function for the boundary conditions
-
-n = numel(u0);
-q = numel(p);
-
-pmat = sparse(n,q);
-pmat(n,1) = 1;
-
-% Jacobian for Poincare Section at u2 = 0
-data.J = [ sparse(n,1), speye(n,n),                -speye(n,n),  pmat;
-           sparse(1,1), sparse([0 1 zeros(1,n-2)]), sparse(1,n), sparse(1,q)];
-
-end
\ No newline at end of file
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F.m
index e9e98c776fbcf72d1c08e83d3b1afa8d152e03c1..40b56301fc71f8595514ba415c0f981d6a7119b9 100644
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F.m
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F.m
@@ -1,6 +1,4 @@
 function y = adj_F(t, la, p)
-% Vectorized implementation of the adjoint ODE
-% compatible with 'coll' toolbox
 
 la1 = la(1,:);
 la2 = la(2,:);
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_bc.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_bc.m
index 2e1a84ca6b98728dff9a5740e6cb324e21f2f26b..4163715e2a16a7d749404db80442761bf4589402 100644
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_bc.m
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_bc.m
@@ -1,6 +1,4 @@
 function [data, y] = adj_F_bc(prob, data, u)
-% Boundary Conditions for Adjoint System in a coco
-% compatible zero function format.
 
 la0 = u(1:2);
 la1 = u(3:4);
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_bc_dU.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_bc_dU.m
index 9be120ed430abc688ac8e71cb8226be60065c760..13a65ef7cca5f207b79b896ccc6be97cfc1f2323 100644
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_bc_dU.m
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_bc_dU.m
@@ -1,6 +1,4 @@
-function [data, J] = adj_F_bc_dU(prob, data, u)
-% Jacobian of Boundary Conditions for Adjoint System in a
-% coco compatible zero function format.
+function [data, J] = adj_F_bc_du(prob, data, u)
 
 J = [-1,  0,  0,  0,  0,  0,  1,  0,  1;
       0, -1,  0,  0,  0,  0,  0,  1,  0;
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dP.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dP.m
index af34e8a6bda8cc7fc171b9d1a57e0bb8fa5db247..e3306675e42924d3c5a2481555f1d4e9c7941203 100644
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dP.m
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dP.m
@@ -1,7 +1,4 @@
-function J = adj_F_dP(t, la, p)
-% Vectorized implementation of Jacobian of adjoint ODE
-% w/r/t to problem parameters compatible with 'coll'
-% toolbox
+function J = adj_F_dp(t, la, p)
 
 la2 = la(2,:);
 
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dT.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dT.m
index 2b1e27b19dcf2fb74ea782bf228fc7547c2cf34c..509c0bd7964c953026859c52d9c1f4f2a6b4821b 100644
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dT.m
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dT.m
@@ -1,6 +1,4 @@
-function J = adj_F_dT(t, la, p)
-% Vectorized implementation of Jacobian of adjoint ODE
-% w/r/t to time compatible with 'coll' toolbox
+function J = adj_F_dt(t, la, p)
 
 la1 = la(1,:);
 
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dU.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dx.m
similarity index 53%
rename from coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dU.m
rename to coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dx.m
index 7586009422392017902c2632bc3b7281252e6922..159e8b3007f3622a3df4c5866fcde0bdf6bb9729 100644
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dU.m
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/adj_F_dx.m
@@ -1,6 +1,4 @@
 function J = adj_F_dU(t, la, p)
-% Vectorized implementation of Jacobian of adjoint ODE
-% w/r/t to lambdas compatible with 'coll' toolbox
 
 k = p(1,:);
 
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/demo2.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/demo2.m
new file mode 100644
index 0000000000000000000000000000000000000000..b222b56779d52af72d5666c1ebc22031d60a81e7
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/demo2.m
@@ -0,0 +1,64 @@
+clear variables
+%%
+% Initial parameter set for linear stifness, k, and phase
+% angle phi
+p0 = [4;0];
+% Let Transients die out
+[~, x0]   = ode45(@(t,x) f(t, x, p0), ...
+  [0 6*pi], [1; 0; 0; 0]);
+% Approximate periodic orbit
+[t0, x0]   = ode45(@(t,x) f(t, x, p0), ...
+  [0 2*pi], x0(end,:));
+
+% Initialize problem instance and set collocation options
+NTST = 15; NCOL = 4;
+prob = coco_prob();
+prob = coco_set(prob, 'ode', 'autonomous', false);
+prob = coco_set(prob, 'coll', 'NTST', NTST, ...
+  'NCOL', NCOL, 'NAdapt', 1);
+
+coll_args = {@f, @dfdx, ...
+  @dfdp, @dfdt, t0, x0, ...
+  {'k','phi'}, p0};
+prob = ode_isol2coll(prob, '', coll_args{:});
+
+[data, uidx] = coco_get_func_data(prob, 'coll', ...
+  'data', 'uidx');
+maps = data.coll_seg.maps;
+
+% Add Boundary Conditions
+prob = coco_add_func(prob, 'bc', @fbc, @fbc_du, data, 'zero', ...
+  'uidx', uidx([maps.x0_idx; maps.x1_idx; maps.T0_idx; maps.T_idx]), ...
+  'u0', [0;0;0]);
+
+bc_uidx = coco_get_func_data(prob, 'bc', ...
+  'uidx');
+prob = coco_add_pars(prob, 'la3', bc_uidx(11), ...
+  'la3', 'active');
+prob = coco_add_pars(prob, 'la4', bc_uidx(12), ...
+  'la4', 'active');
+prob = coco_add_pars(prob, 'd.x0', bc_uidx(13), ...
+  'd.x0', 'inactive');
+
+xbp = uidx(reshape(maps.xbp_idx, maps.xbp_shp)');
+
+% Get x1 and la2, T, and p indices for use in stationarity
+% equation
+ulap = [xbp(:,1); ...
+        xbp(:,4); ...
+        uidx(maps.T_idx); 
+        uidx(maps.p_idx)];
+
+% Two additional u's are d.k, d.phi
+prob = coco_add_func(prob, 'stationarity', @stationarity, ...
+  @stationarity_dU, data, 'zero',...
+  'uidx', ulap, 'u0', [0;0]); 
+adjbc_uidx = coco_get_func_data(prob, 'stationarity', 'uidx');
+prob = coco_add_pars(prob, 'dmus', adjbc_uidx(end-1:end), ...
+                     {'d.k', 'd.phi'}, 'inactive');
+
+% Objective Function
+prob = coco_add_pars(prob, 'x0', maps.x0_idx(1), 'x0');
+                   
+bd1 = coco(prob, 'init', [], 1, {'x0', 'k', 'd.x0', ...
+  'd.phi', 'phi'}, {[0.1 2]});
\ No newline at end of file
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/dfdp.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/dfdp.m
new file mode 100644
index 0000000000000000000000000000000000000000..a300b94c39e4ed98d53883ac9026b0bd3587f31b
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/dfdp.m
@@ -0,0 +1,12 @@
+function J = dfdp(t, x, p)
+
+x1 = x(1,:);
+la2 = x(4,:);
+phi = p(2,:);
+
+J = zeros(4,2,numel(x1));
+J(2,1,:) = -x1;
+J(2,2,:) = -sin(t + phi);
+J(3,1,:) = la2;
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/dfdt.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/dfdt.m
new file mode 100644
index 0000000000000000000000000000000000000000..afa96eb71bb510076591205d2e7fb4518a64cc50
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/dfdt.m
@@ -0,0 +1,9 @@
+function J = dfdt(t, x, p)
+
+x1 = x(1,:);
+phi = p(2,:);
+
+J = zeros(4,numel(x1));
+J(2,:) = -sin(t + phi);
+
+end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/dfdx.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/dfdx.m
new file mode 100644
index 0000000000000000000000000000000000000000..9692b483595d720e8853dfdb3824d51b96400b8f
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/dfdx.m
@@ -0,0 +1,14 @@
+function J = dfdx(t, x, p)
+
+x1 = x(1,:);
+k = p(1,:);
+
+J = zeros(4,4,numel(x1));
+J(1,2,:) = 1;
+J(2,1,:) = -k;
+J(2,2,:) = -1;
+J(3,4,:) = k;
+J(4,3,:) = -1;
+J(4,4,:) = 1;
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/f.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/f.m
new file mode 100644
index 0000000000000000000000000000000000000000..27fcbe2041322fbf369fc50248939a6914ab77ad
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/f.m
@@ -0,0 +1,16 @@
+function y = f(t, x, p)
+
+x1 = x(1,:);
+x2 = x(2,:);
+la1 = x(3,:);
+la2 = x(4,:);
+
+k = p(1,:);
+phi = p(2,:);
+
+y(1,:) = x2;
+y(2,:) = cos(t + phi) - x2 - k.*x1;
+y(3,:) = k.*la2;
+y(4,:) = la2 - la1;
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/fbc.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/fbc.m
new file mode 100644
index 0000000000000000000000000000000000000000..8f1791576f2fd80364bf266070aac49d0967f831
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/fbc.m
@@ -0,0 +1,20 @@
+function [data, y] = fbc(prob, data, u)
+
+x_0 = u(1:2);
+la_0 = u(3:4);
+x_1 = u(5:6);
+la_1 = u(7:8);
+T0 = u(9);
+T  = u(10);
+la3 = u(11);
+la4 = u(12);
+eta1 = u(13);
+
+y = [x_0 - x_1; ...
+     -la_0(1) + la3 + eta1; ...
+     -la_0(2) + la4; ...
+     la_1(1) - la3; ...
+     la_1(2) - la4; ...
+     T0; T-2*pi];
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/fbc_du.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/fbc_du.m
new file mode 100644
index 0000000000000000000000000000000000000000..8f75f09ed19c0a8bfe14d3eb0d20d47df8d643d4
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/archive/fbc_du.m
@@ -0,0 +1,23 @@
+function [data, J] = fbc_du(prob, data, u)
+
+x_0 = u(1:2);
+la_0 = u(3:4);
+x_1 = u(5:6);
+la_1 = u(7:8);
+T0 = u(9);
+T  = u(10);
+la3 = u(11);
+la4 = u(12);
+eta1 = u(13);
+     
+J = zeros(8,13);
+
+J = [1, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0;
+     0, 1, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0;
+     0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1;
+     0, 1, 0,-1, 0, 0, 0, 0, 0, 0, 0, 1, 0;
+     0, 1, 0, 0, 0, 0, 1, 0, 0, 0,-1, 0, 0;
+     0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,-1, 0;
+     0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0;
+     0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0];
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/ch_2_thesis_figures.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/ch_2_thesis_figures.m
index 48436c03555a5330b7635d4319fa83f38baa03b5..376622f207d13a1d84ae6722be77c5c36c90b806 100644
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/ch_2_thesis_figures.m
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/ch_2_thesis_figures.m
@@ -4,10 +4,10 @@ if not(coco_exist('phase', 'run'))
     p0 = [4;0];
 
     % Let Transients die out
-    [~, x0]   = ode45(@(t,x) linode_het(t, x, p0), [0 6*pi], [1; 0]);
+    [~, x0]   = ode45(@(t,x) linode(t, x, p0), [0 6*pi], [1; 0]);
 
     % Approximate periodic orbit
-    [t0, x0]   = ode45(@(t,x) linode_het(t, x, p0), [0 2*pi], x0(end,:));
+    [t0, x0]   = ode45(@(t,x) linode(t, x, p0), [0 2*pi], x0(end,:));
 
     NTST = 25;
     NCOL = 4;
@@ -15,15 +15,15 @@ if not(coco_exist('phase', 'run'))
     prob = coco_set(prob, 'ode', 'autonomous', false);
 
     prob = coco_set(prob, 'coll', 'NTST', NTST, 'NCOL', NCOL);
-    coll_args = {@linode_het, @linode_het_DFDX, @linode_het_DFDP, ...
-                 @linode_het_DFDT, t0, x0, {'k','phi'}, p0};
+    coll_args = {@linode, @linode_dx, @linode_dp, @linode_dt, ...
+      t0, x0, {'k','phi'}, p0};
     prob = ode_isol2coll(prob, 'orig', coll_args{:});
 
     [data, uidx] = coco_get_func_data(prob, 'orig.coll', 'data', 'uidx');
     maps = data.coll_seg.maps;
 
     % Add Boundary Conditions
-    prob = coco_add_func(prob, 'orig.po', @linode_het_bc, data, 'zero', ...
+    prob = coco_add_func(prob, 'orig.po', @linode_bc, data, 'zero', ...
        'uidx', uidx([maps.x0_idx; maps.x1_idx; maps.T0_idx; maps.T_idx]));
 
     % ICs
@@ -51,7 +51,7 @@ prob = ode_coll2coll(prob, 'orig', 'phase', EPlab(end));
 maps = data.coll_seg.maps;
 
 % Add Boundary Conditions
-prob = coco_add_func(prob, 'orig.po', @linode_het_bc, data, 'zero', ...
+prob = coco_add_func(prob, 'orig.po', @linode_bc, data, 'zero', ...
    'uidx', uidx([maps.x0_idx; maps.x1_idx; maps.T0_idx; maps.T_idx]));
 
 % ICs and lock v0 at 0
@@ -99,7 +99,6 @@ ylabel('Initial Position, $x_{1}\!\left(0\right)$', 'Interpreter', 'latex', 'Fon
 ylim([0,1.05])
 
 
-
 %% plot the trajectories for the handful of identified frequencies.
 run_names = {'klow','khigh'};
 curve_names = 'orig';
@@ -134,7 +133,7 @@ for i = 1:size(curve_names, 2)
     end
 end
 end
-% title('Position vs Time for Selected Stiffness Values', 'Interpreter', 'latex')
+title('Position vs Time for Selected Stiffness Values', 'Interpreter', 'latex')
 
 ylim([-1,1])
 xlim([0,sol.T])
@@ -150,28 +149,28 @@ lgd.Interpreter = 'latex';
 lgd.Location = 'best';
 
 bd1 = coco_bd_read('init');
-bd2 = coco_bd_read('d.x0');
+bd2 = coco_bd_read('eta1');
 bd3 = coco_bd_read('opt');
 col_phi = 9;
 col_k = 8;
 col_x0 = 12;
 
-k1 = [cell2mat(bd1(2:end,col_k))];
-k2 = [cell2mat(bd3(2:end,col_k))];
-phi1 = [cell2mat(bd1(2:end,col_phi))];
-phi2 = [cell2mat(bd3(2:end,col_phi))];
-x01 = [cell2mat(bd1(2:end,col_x0))];
-x02 = [cell2mat(bd3(2:end,col_x0))];
+k1 = coco_bd_col(bd1, 'k');
+k2 = coco_bd_col(bd3, 'k');
+phi1 = coco_bd_col(bd1, 'phi');
+phi2 = coco_bd_col(bd3, 'phi');
+x01 = coco_bd_col(bd1, 'mu1');
+x02 = coco_bd_col(bd3, 'mu1');
 bp = coco_bd_labs(bd1, 'BP');
 sol = coll_read_solution('orig', 'init', bp);
 bp2 = coco_bd_labs(bd3, 'OPT');
 sol2 = coll_read_solution('orig', 'opt', bp2);
 
 figure(3);hold on;grid on;box on;
-plot(k1, phi1, 'k-', 'DisplayName', 'Original Solution Branch')
-plot(sol.p(1),sol.p(2), 'ko', 'HandleVisibility', 'off')
-plot(sol2.p(1),sol2.p(2), 'ko', 'HandleVisibility', 'off')
-plot(k2, phi2, 'k-.', 'DisplayName', 'Second Solution Branch')
+plot3(k1, phi1, x01, 'k-', 'DisplayName', 'Original Solution Branch')
+plot3(sol.p(1),sol.p(2), sol.xbp(1,1), 'ko', 'HandleVisibility', 'off')
+plot3(sol2.p(1),sol2.p(2), sol2.xbp(1,1), 'ko', 'HandleVisibility', 'off')
+plot3(k2, phi2, x02, 'k-.', 'DisplayName', 'Second Solution Branch')
 xlim([0,4])
 ylim([-0.5, pi])
 x = [0.6, 0.53];
@@ -194,12 +193,15 @@ ax.TickLabelInterpreter = 'latex';
 ax.FontSize = 12;
 xlabel('Stiffness, k', 'Interpreter', 'latex', 'FontSize', 15)
 ylabel('Phase Angle, $\phi$', 'Interpreter', 'latex', 'FontSize', 15)
+zlabel('Initial Position, $x_{1}\!\left(0\right)$', 'Interpreter', 'latex', 'FontSize', 15)
 
 col_la3 = 15;
 col_la4 = 16;
 col_dx0 = 17;
 la31 = [cell2mat(bd2(2:end,col_la3))];
 la32 = [cell2mat(bd3(2:end,col_la3))];
+obj1  = coco_bd_col(bd2, 'mu1');
+obj2  = coco_bd_col(bd3, 'mu1');
 
 la41 = [cell2mat(bd2(2:end,col_la4))];
 la42 = [cell2mat(bd3(2:end,col_la4))];
@@ -208,21 +210,24 @@ dx01 = [cell2mat(bd2(2:end,col_dx0))];
 dx02 = [cell2mat(bd3(2:end,col_dx0))];
 la3opt = coco_read_solution('la3', 'opt', bp2, 'chart');
 la4opt = coco_read_solution('la4', 'opt', bp2, 'chart');
+x0opt = coco_read_solution('x0', 'opt', bp2, 'chart');
 dx0opt = coco_read_solution('d.x0', 'opt', bp2, 'chart');
+
 labs = coco_bd_labs(bd2, 'EP');
 bp3 = max(labs);
-la3e1 = coco_read_solution('la3', 'd.x0', bp3, 'chart');
-la4e1 = coco_read_solution('la4', 'd.x0', bp3, 'chart');
-dx0e1 = coco_read_solution('d.x0', 'd.x0', bp3, 'chart');
+la3e1 = coco_read_solution('la3', 'eta1', bp3, 'chart');
+la4e1 = coco_read_solution('la4', 'eta1', bp3, 'chart');
+x0e1 = coco_read_solution('x0', 'eta1', bp3, 'chart');
+dx0e1 = coco_read_solution('e', 'eta1', bp3, 'chart');
 
 figure(4)
 xlim([-1.2,0])
 ylim([-0.4,0.1])
 hold on;grid on; box on;
-plot(la31, la41, 'k-', 'DisplayName', '$\eta_{1} = 0 \rightarrow 1$');
-plot(la32, la42, 'k-.', 'DisplayName', 'Second Solution Branch');
-plot(la3opt.x, la4opt.x, 'ko', 'HandleVisibility', 'off')
-plot(la3e1.x, la4e1.x, 'ko', 'HandleVisibility', 'off')
+plot3(la31, la41, obj1, 'k-', 'DisplayName', '$\eta_{1} = 0 \rightarrow 1$');
+plot3(la32, la42, obj2, 'k-.', 'DisplayName', 'Second Solution Branch');
+plot3(la3opt.x, la4opt.x(1), x0opt.x(1), 'ko', 'HandleVisibility', 'off')
+plot3(la3e1.x, la4e1.x(1), x0e1.x(1), 'ko', 'HandleVisibility', 'off')
 lgd = legend('Orientation', 'vertical');
 lgd.Interpreter = 'latex';
 lgd.Location = 'best';
@@ -231,8 +236,9 @@ ax.TickLabelInterpreter = 'latex';
 ax.XTick = -1.2:0.2:0;
 ax.YTick = -0.4:0.1:0.2;
 ax.FontSize = 12;
-xlabel('$\lambda_{3}$', 'Interpreter', 'latex', 'FontSize', 15)
-ylabel('$\lambda_{4}$', 'Interpreter', 'latex', 'FontSize', 15)
+xlabel('$\lambda_{bc,1}$', 'Interpreter', 'latex', 'FontSize', 15)
+ylabel('$\lambda_{bc,2}$', 'Interpreter', 'latex', 'FontSize', 15)
+zlabel('Initial Position, $x_{1}\!\left(0\right)$', 'Interpreter', 'latex', 'FontSize', 15)
 x = [0.4, 0.26];
 y = [0.8, 0.825];
 annotation('textarrow',x, y,'String','Optimal Point', ...
@@ -240,4 +246,4 @@ annotation('textarrow',x, y,'String','Optimal Point', ...
 x = [0.4, 0.267];
 y = [0.6, 0.71];
 annotation('textarrow',x, y,'String','$\eta_{1} = 1$', ...
-  'Interpreter', 'latex', 'FontSize', 15)
+  'Interpreter', 'latex', 'FontSize', 15)
\ No newline at end of file
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/demo.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/demo_for_thesis.m
similarity index 74%
rename from coco_example_runs/ch_2_linode_optimization_manual_adjoint/demo.m
rename to coco_example_runs/ch_2_linode_optimization_manual_adjoint/demo_for_thesis.m
index 7e8a8fb4a53346024b7192a803476afa38c81ad4..0329c144efd1d73760081b1d3495c7ec030e73bb 100644
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/demo.m
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/demo_for_thesis.m
@@ -4,10 +4,10 @@ clear variables
 % angle phi
 p0 = [4;0];
 % Let Transients die out
-[~, x0]   = ode45(@(t,x) linode_het(t, x, p0), ...
+[~, x0]   = ode45(@(t,x) linode(t, x, p0), ...
   [0 6*pi], [1; 0]);
 % Approximate periodic orbit
-[t0, x0]   = ode45(@(t,x) linode_het(t, x, p0), ...
+[t0, x0]   = ode45(@(t,x) linode(t, x, p0), ...
   [0 2*pi], x0(end,:));
 
 % Initialize problem instance and set collocation options
@@ -17,8 +17,8 @@ prob = coco_set(prob, 'ode', 'autonomous', false);
 prob = coco_set(prob, 'coll', 'NTST', NTST, ...
   'NCOL', NCOL);
 
-coll_args = {@linode_het, @linode_het_DFDX, ...
-  @linode_het_DFDP, @linode_het_DFDT, t0, x0, ...
+coll_args = {@linode, @linode_dx, ...
+  @linode_dp, @linode_dt, t0, x0, ...
   {'k','phi'}, p0};
 prob = ode_isol2coll(prob, 'orig', coll_args{:});
 
@@ -27,16 +27,16 @@ prob = ode_isol2coll(prob, 'orig', coll_args{:});
 maps = data.coll_seg.maps;
 
 % Add Boundary Conditions
-prob = coco_add_func(prob, 'orig.po', @linode_het_bc, ...
+prob = coco_add_func(prob, 'orig.po', @linode_bc, ...
   data, 'zero', 'uidx', uidx([maps.x0_idx; ...
                               maps.x1_idx; ...
                               maps.T0_idx; ...
                               maps.T_idx]));
 
 % Objective Function
-prob = coco_add_pars(prob, 'x0', maps.x0_idx(1), 'x0');
+prob = coco_add_pars(prob, 'mu1', maps.x0_idx(1), 'mu1');
 
-coll_args = {@adj_F, @adj_F_dU, @adj_F_dP, @adj_F_dT, ...
+coll_args = {@adj_F, @adj_F_dx, @adj_F_dp, @adj_F_dt, ...
   t0, zeros(size(x0)), p0};
 prob = ode_isol2coll(prob, 'adj', coll_args{:});
 
@@ -51,7 +51,7 @@ prob = coco_add_glue(prob, 'glue', x1idx, x2idx);
 
 % Adjoint boundary condition
 prob = coco_add_func(prob, 'adj.bc', @adj_F_bc, ...
-  @adj_F_bc_dU, a_data, 'zero', 'uidx', ...
+  @adj_F_bc_du, a_data, 'zero', 'uidx', ...
   a_uidx([a_maps.x0_idx; a_maps.x1_idx; ...
           a_maps.T0_idx; a_maps.T_idx]), ...
  'u0', [0;0;0]); % < 3 extra are la3, la4, and eta1
@@ -62,8 +62,8 @@ prob = coco_add_pars(prob, 'la3', adjbc_uidx(7), ...
   'la3', 'active');
 prob = coco_add_pars(prob, 'la4', adjbc_uidx(8), ...
   'la4', 'active');
-prob = coco_add_pars(prob, 'd.x0', adjbc_uidx(9), ...
-  'd.x0', 'inactive');
+prob = coco_add_pars(prob, 'eta1', adjbc_uidx(9), ...
+  'eta1', 'inactive');
 
 % Get u1 and lambda2, T, and p indices for use in
 % stationarity equation
@@ -72,18 +72,17 @@ ulap = [uidx(maps.xbp_idx(1:2:end)); ...
         uidx(maps.T_idx); 
         uidx(maps.p_idx)];
 
-% Two additional u's are d.k, d.phi
+% Two additional u's are eta_k, eta_phi
 prob = coco_add_func(prob, 'stationarity', @stationarity, ...
-  @stationarity_dU, data, 'zero',...
+  @stationarity_du, data, 'zero',...
   'uidx', ulap, 'u0', [0;0]); 
 adjbc_uidx = coco_get_func_data(prob, 'stationarity', 'uidx');
 prob = coco_add_pars(prob, 'dmus', adjbc_uidx(end-1:end), ...
-                     {'d.k', 'd.phi'}, 'inactive');
+                     {'eta_k', 'eta_phi'}, 'inactive');
 
-bd1 = coco(prob, 'init', [], 1, {'x0', 'k', 'd.x0', ...
-  'd.phi', 'phi'}, {[0.1 2]});
+bd1 = coco(prob, 'init', [], 1, {'mu1', 'k', 'eta1', 'eta_phi'}, {[0.1 2]});
 
-%% Drive d.x0 to 1
+%% Drive eta1 to 1
 run_name = 'opt2';
 fprintf(['\nFrom the previously found Branch Point, continue along an ', ...
          'intersecting solution manifold where\nthe mus and etas are ', ...
@@ -100,11 +99,11 @@ prob = ode_BP2coll(prob, 'orig', 'init', BPlab(end));
 maps = data.coll_seg.maps;
 
 % Add Boundary Conditions
-prob = coco_add_func(prob, 'orig.po', @linode_het_bc, data, 'zero', ...
+prob = coco_add_func(prob, 'orig.po', @linode_bc, data, 'zero', ...
    'uidx', uidx([maps.x0_idx; maps.x1_idx; maps.T0_idx; maps.T_idx]));
 
 % Objective Function
-prob = coco_add_pars(prob, 'x0', maps.x0_idx(1), 'x0');
+prob = coco_add_pars(prob, 'mu1', maps.x0_idx(1), 'mu1');
 
 % Adjoint System
 prob = ode_BP2coll(prob, 'adj', 'init', BPlab(end));
@@ -119,15 +118,15 @@ prob = coco_add_glue(prob, 'glue', x1idx, x2idx);
 
 % Adjoint boundary condition
 prob = coco_add_func(prob, 'adj.bc', @adj_F_bc, ...
-                     @adj_F_bc_dU, a_data, 'zero', 'uidx', ...
+                     @adj_F_bc_du, a_data, 'zero', 'uidx', ...
                      a_uidx([a_maps.x0_idx; a_maps.x1_idx; ...
                              a_maps.T0_idx; a_maps.T_idx]), ...
-                     'u0', [0;0;0]); % < 3 extra are la3, la4, and d.x0
+                     'u0', [0;0;0]); % < 3 extra are la3, la4, and eta1
 
 adjbc_uidx = coco_get_func_data(prob, 'adj.bc', 'uidx');
 prob = coco_add_pars(prob, 'la3', adjbc_uidx(7), 'la3', 'active');
 prob = coco_add_pars(prob, 'la4', adjbc_uidx(8), 'la4', 'active');
-prob = coco_add_pars(prob, 'd.x0', adjbc_uidx(9), 'd.x0', 'inactive');
+prob = coco_add_pars(prob, 'eta1', adjbc_uidx(9), 'eta1', 'inactive');
 
 % Get u1 and lambda2, T, and p indices for use in stationarity equation
 ulap = [uidx(maps.xbp_idx(1:2:end)); a_uidx(a_maps.xbp_idx(2:2:end)); ...
@@ -138,18 +137,17 @@ ulap = [uidx(maps.xbp_idx(1:2:end)); a_uidx(a_maps.xbp_idx(2:2:end)); ...
 % would cause problems if adjoint and original problems have different
 % mesh points
 
-% Two additional u's are d.k, d.phi
+% Two additional u's are eta_k, eta_phi
 prob = coco_add_func(prob, 'stationarity', @stationarity, ...
-                     @stationarity_dU, data, 'zero', ...
+                     @stationarity_du, data, 'zero', ...
                      'uidx', ulap, 'u0', [0;0]); 
 adjbc_uidx = coco_get_func_data(prob, 'stationarity', 'uidx');
 prob = coco_add_pars(prob, 'dmus', adjbc_uidx(end-1:end), ...
-                     {'d.k', 'd.phi'}, 'inactive');
+                     {'eta_k', 'eta_phi'}, 'inactive');
 
-bd2 = coco(prob, 'd.x0', [], 1, {'d.x0', 'x0', 'k', ...
-  'd.phi', 'la3', 'la4', 'phi'}, {[0 1]});
+bd2 = coco(prob, 'eta1', [], 1, {'eta1', 'mu1', 'k', 'eta_phi', 'la3', 'la4'}, {[0 1]});
 
-%% Drive d.phi to 0
+%% Drive eta_phi to 0
 
 EPlab = coco_bd_labs(bd2, 'EP');
 
@@ -157,20 +155,20 @@ prob = coco_prob();
 prob = coco_set(prob, 'ode', 'autonomous', false);
 prob = coco_set(prob, 'coll', 'NTST', NTST, 'NCOL', NCOL);
 
-prob = ode_coll2coll(prob, 'orig', 'd.x0', EPlab(end));
+prob = ode_coll2coll(prob, 'orig', 'eta1', EPlab(end));
  
 [data, uidx] = coco_get_func_data(prob, 'orig.coll', 'data', 'uidx');
 maps = data.coll_seg.maps;
 
 % Add Boundary Conditions
-prob = coco_add_func(prob, 'orig.po', @linode_het_bc, data, 'zero', ...
+prob = coco_add_func(prob, 'orig.po', @linode_bc, data, 'zero', ...
    'uidx', uidx([maps.x0_idx; maps.x1_idx; maps.T0_idx; maps.T_idx]));
 
 % Objective Function
-prob = coco_add_pars(prob, 'x0', maps.x0_idx(1), 'x0');
+prob = coco_add_pars(prob, 'mu1', maps.x0_idx(1), 'mu1');
 
 % Adjoint System
-prob = ode_coll2coll(prob, 'adj', 'd.x0', EPlab(end));
+prob = ode_coll2coll(prob, 'adj', 'eta1', EPlab(end));
 
 [a_data, a_uidx] = coco_get_func_data(prob, 'adj.coll', 'data', 'uidx');
 a_maps = a_data.coll_seg.maps;
@@ -182,7 +180,7 @@ prob = coco_add_glue(prob, 'glue', x1idx, x2idx);
 
 % Adjoint boundary condition
 prob = coco_add_func(prob, 'adj.bc', @adj_F_bc, ...
-                     @adj_F_bc_dU, a_data, 'zero', 'uidx', ...
+                     @adj_F_bc_du, a_data, 'zero', 'uidx', ...
                      a_uidx([a_maps.x0_idx; a_maps.x1_idx; ...
                              a_maps.T0_idx; a_maps.T_idx]), ...
                      'u0', [-9.9392e-01;-2.8173e-02;1]); % < 3 extra are la3, la4, and eta1
@@ -190,22 +188,22 @@ prob = coco_add_func(prob, 'adj.bc', @adj_F_bc, ...
 adjbc_uidx = coco_get_func_data(prob, 'adj.bc', 'uidx');
 prob = coco_add_pars(prob, 'la3', adjbc_uidx(7), 'la3', 'active');
 prob = coco_add_pars(prob, 'la4', adjbc_uidx(8), 'la4', 'active');
-prob = coco_add_pars(prob, 'd.x0', adjbc_uidx(9), 'd.x0', 'inactive');
+prob = coco_add_pars(prob, 'eta1', adjbc_uidx(9), 'eta1', 'inactive');
 
 % Get u1 and lambda2, T, and p indices for use in stationarity equation
 ulap = [uidx(maps.xbp_idx(1:2:end)); a_uidx(a_maps.xbp_idx(2:2:end)); ...
         uidx(maps.T_idx); uidx(maps.p_idx)];
 
-% Two additional u's are d.k, d.phi
+% Two additional u's are eta_k, eta_phi
 prob = coco_add_func(prob, 'stationarity', @stationarity, ...
-                     @stationarity_dU, data, 'zero', ...
+                     @stationarity_du, data, 'zero', ...
                      'uidx', ulap, 'u0', [0;-0.5]);
 adjbc_uidx = coco_get_func_data(prob, 'stationarity', 'uidx');
 prob = coco_add_pars(prob, 'dmus', adjbc_uidx(end-1:end), ...
-                     {'d.k', 'd.phi'}, 'inactive');
+                     {'eta_k', 'eta_phi'}, 'inactive');
 
 % Mark the optimal point
-prob = coco_add_event(prob, 'OPT', 'd.phi', 0);
+prob = coco_add_event(prob, 'OPT', 'eta_phi', 0);
 
-bd3 = coco(prob, 'opt', [], 1, {'d.phi', 'x0', 'k', 'phi', 'd.x0', 'la3', 'la4', 'd.k'}, {[], [0.3 1.5]});
-%%
\ No newline at end of file
+prob = coco_set(prob, 'cont', 'NPR', 100);
+bd3 = coco(prob, 'opt', [], 1, {'eta_phi', 'mu1', 'k', 'phi', 'la3', 'la4'}, {[], [0.3 1.5]});
\ No newline at end of file
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode.m
new file mode 100644
index 0000000000000000000000000000000000000000..1f4444da8a56b711e332760636b330bf6852f662
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode.m
@@ -0,0 +1,11 @@
+function y = linode(t, x, p)
+
+x1 = x(1,:);
+x2 = x(2,:);
+k = p(1,:);
+phi = p(2,:);
+
+y(1,:) = x2;
+y(2,:) = cos(t + phi) - x2 - k.*x1;
+
+end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_bc.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_bc.m
new file mode 100644
index 0000000000000000000000000000000000000000..ba51839f2b5ebbbe2c59cde7c704a0e5afdf4df5
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_bc.m
@@ -0,0 +1,10 @@
+function [data, y] = linode_bc(prob, data, u)
+
+x0 = u(1:2);
+x1 = u(3:4);
+T0 = u(5);
+T  = u(6);
+
+y = [x0 - x1; T0; T-2*pi];
+
+end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_bc_du.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_bc_du.m
new file mode 100644
index 0000000000000000000000000000000000000000..92bf9abd578f9b16728670a5578ce64f24686c0d
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_bc_du.m
@@ -0,0 +1,8 @@
+function [data, J] = linode_bc_du(prob, data, u)
+
+J = [  1,  0, -1,  0,  0,  0;
+       0,  1,  0, -1,  0,  0;
+       0,  0,  0,  0,  1,  0;
+       0,  0,  0,  0,  0,  1];
+
+end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_dp.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_dp.m
new file mode 100644
index 0000000000000000000000000000000000000000..7124df3c027fdf822ab333296e24eee19145dbaf
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_dp.m
@@ -0,0 +1,10 @@
+function J = linode_dp(t, x, p)
+
+x1 = x(1,:);
+phi = p(2,:);
+
+J = zeros(2,2,numel(x1));
+J(2,1,:) = -x1;
+J(2,2,:) = -sin(t + phi);
+
+end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_dt.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_dt.m
new file mode 100644
index 0000000000000000000000000000000000000000..f22bda867b1a8d67febf5b792e8caaabb7763a03
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_dt.m
@@ -0,0 +1,9 @@
+function J = linode_dt(t, x, p)
+
+x1 = x(1,:);
+phi = p(2,:);
+
+J = zeros(2,numel(x1));
+J(2,:) = -sin(t + phi);
+
+end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_dx.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_dx.m
new file mode 100644
index 0000000000000000000000000000000000000000..bdbb0e056ae77bcc9a8fbdf50174ab0d83e7efb2
--- /dev/null
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_dx.m
@@ -0,0 +1,11 @@
+function J = linode_dx(t, x, p)
+
+x1 = x(1,:);
+k = p(1,:);
+
+J = zeros(2,2,numel(x1));
+J(1,2,:) = 1;
+J(2,1,:) = -k;
+J(2,2,:) = -1;
+
+end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het.m
deleted file mode 100644
index af29f6bc706cc6279ba758705c55fade6b82d9f2..0000000000000000000000000000000000000000
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het.m
+++ /dev/null
@@ -1,13 +0,0 @@
-function y = linode_het(t, x, p)
-% Vectorized implementation of the linear ODE compatible
-% with 'coll' toolbox
-
-x1 = x(1,:);
-x2 = x(2,:);
-k = p(1,:);
-phi = p(2,:);
-
-y(1,:) = x2;
-y(2,:) = cos(t + phi) - x2 - k.*x1;
-
-end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_DFDP.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_DFDP.m
deleted file mode 100644
index 377397c97c896153bd39ada77d4274312f05f5c2..0000000000000000000000000000000000000000
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_DFDP.m
+++ /dev/null
@@ -1,12 +0,0 @@
-function J = linode_het_DFDP(t, x, p)
-% Vectorized implementation of Jacobian of linear ODE w/r/t
-% to problem parameters compatible with 'coll' toolbox
-
-x1 = x(1,:);
-phi = p(2,:);
-
-J = zeros(2,2,numel(x1));
-J(2,1,:) = -x1;
-J(2,2,:) = -sin(t + phi);
-
-end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_DFDT.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_DFDT.m
deleted file mode 100644
index 8f91b1d16ee633b5b642fbecd5f2322a4870c2f4..0000000000000000000000000000000000000000
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_DFDT.m
+++ /dev/null
@@ -1,11 +0,0 @@
-function J = linode_het_DFDT(t, x, p)
-% Vectorized implementation of Jacobian of linear ODE w/r/t
-% to time compatible with 'coll' toolbox
-
-x1 = x(1,:);
-phi = p(2,:);
-
-J = zeros(2,numel(x1));
-J(2,:) = -sin(t + phi);
-
-end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_DFDX.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_DFDX.m
deleted file mode 100644
index bd401dae09f1cf8f1498306f1517c4c70e6b9021..0000000000000000000000000000000000000000
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_DFDX.m
+++ /dev/null
@@ -1,13 +0,0 @@
-function J = linode_het_DFDX(t, x, p)
-% Vectorized implementation of Jacobian of linear ODE w/r/t
-% to trajectory nodes compatible with 'coll' toolbox
-
-x1 = x(1,:);
-k = p(1,:);
-
-J = zeros(2,2,numel(x1));
-J(1,2,:) = 1;
-J(2,1,:) = -k;
-J(2,2,:) = -1;
-
-end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_bc.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_bc.m
deleted file mode 100644
index f96038e359bb4314a048ceaa73b835f79395b5eb..0000000000000000000000000000000000000000
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_bc.m
+++ /dev/null
@@ -1,12 +0,0 @@
-function [data, y] = linode_het_bc(prob, data, u)
-% coco compatible zero function for the periodic boundary
-% conditions of the linear ODE
-
-x0 = u(1:2);
-x1 = u(3:4);
-T0 = u(5);
-T  = u(6);
-
-y = [x0 - x1; T0; T-2*pi];
-
-end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_bc_dU.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_bc_dU.m
deleted file mode 100644
index 3bc85c0db57b7596332757edf4d49f12acdcdc10..0000000000000000000000000000000000000000
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/linode_het_bc_dU.m
+++ /dev/null
@@ -1,10 +0,0 @@
-function [data, J] = linode_het_bc_dU(prob, data, u)
-% coco compatible zero function for the Jacobian of the
-% periodic boundary conditions for the linear ODE
-
-J = [  1,  0, -1,  0,  0,  0;
-       0,  1,  0, -1,  0,  0;
-       0,  0,  0,  0,  1,  0;
-       0,  0,  0,  0,  0,  1];
-
-end
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/stationarity.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/stationarity.m
index b2e9450ab5f2979b6f2a1cafcf34c39e481ddf01..fb41c7301652093617dde6a311200f876177d903 100644
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/stationarity.m
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/stationarity.m
@@ -1,6 +1,4 @@
 function [data, y] = stationarity(prob, data, u)
-% Stationarity constraints for Adjoint System in a coco
-% compatible zero function format.
 
 dim = data.coll_seg.maps.xbp_shp(2);
 
@@ -9,12 +7,12 @@ la2bp = u(dim+1:2*dim);
 T = u(end-4);
 k = u(end-3);
 phi = u(end-2);
+eta_k = u(end-1);
+eta_phi = u(end);
 
-% Collect etas from input vector
-eta2 = u(end-1);
-eta3 = u(end);
-
-W = data.coll_seg.maps.W(1:2:end, 1:2:end);
+% Numerical Integration
+dim = data.coll_seg.int.dim;
+W = data.coll_seg.maps.W(1:dim:end, 1:dim:end);
 ka = repmat(data.coll_seg.mesh.ka,[data.coll_seg.int.NCOL,1]);
 ka = ka(:);
 tcn = data.coll_seg.mesh.tcn;
@@ -24,8 +22,8 @@ N = data.coll_seg.maps.NTST;
 y1_int = (0.5*T/N)*((W*la2bp).*(W*x1bp).*ka)'*w;
 y2_int = (0.5*T/N)*(sin(T*tcn+phi).*(W*la2bp).*ka)'*w;
 
-y = [y1_int + eta2;
-     y2_int + eta3];
+y = [y1_int + eta_k;
+     y2_int + eta_phi];
 
 end
 
diff --git a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/stationarity_dU.m b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/stationarity_dU.m
index 66e63fba6ee889e2ac363b6f5f616dbab7452ec5..7b7ba44a3f0a410fcc8fb2252cec4cf2f32905f9 100644
--- a/coco_example_runs/ch_2_linode_optimization_manual_adjoint/stationarity_dU.m
+++ b/coco_example_runs/ch_2_linode_optimization_manual_adjoint/stationarity_dU.m
@@ -1,6 +1,4 @@
-function [data, J] = stationarity_dU(prob, data, u)
-% coco compatible zero function for the Jacobian of the
-% stationarity constraints of the adjoint system.
+function [data, J] = stationarity_du(prob, data, u)
 
 dim = data.coll_seg.maps.xbp_shp(2);
 x1bp = u(1:dim);
@@ -8,31 +6,34 @@ la2bp = u(dim+1:2*dim);
 T = u(end-4);
 phi = u(end-2);
 
+dim = data.coll_seg.int.dim;
 w = data.coll_seg.mesh.gwt';
-W = data.coll_seg.maps.W(1:2:end, 1:2:end);
+W = data.coll_seg.maps.W(1:dim:end, 1:dim:end);
 ka = repmat(data.coll_seg.mesh.ka,[data.coll_seg.int.NCOL,1]);
 ka = ka(:);
 tcn = data.coll_seg.mesh.tcn;
 N = data.coll_seg.maps.NTST;
 
-
-y_u = [(0.5*T/N)*((W.^2)*diag(la2bp))'*(ka.*w), ...
+% Jacobians of portions of the Numerical Integration
+J_u = [(0.5*T/N)*((W.^2)*diag(la2bp))'*(ka.*w), ...
        zeros(size(x1bp))]';
 
-y_la = [(0.5*T/N)*((W.^2)*diag(x1bp))'*(ka.*w), ...
+J_la = [(0.5*T/N)*((W.^2)*diag(x1bp))'*(ka.*w), ...
         (0.5*T/N)*(diag(sin(T*tcn+phi).*ka)*W)'*w]';
 
 fds = (0.5*T/N)*diag(cos(T*tcn+phi))*diag(tcn);
 sdf = diag(sin(T*tcn+phi));
 
-y_T = [(0.5/N)*((W*x1bp).*(W*la2bp).*ka)'*w; ...
+J_T = [(0.5/N)*((W*x1bp).*(W*la2bp).*ka)'*w; ...
        (0.5/N)*((fds + sdf)*((W*la2bp).*ka))'*w];
 
-y_p = [0, 0;
+J_p = [0, 0;
        0, (0.5*T/N)*((W*la2bp).*cos(T*tcn + phi).*ka)'*w];
-y_eta = eye(2);
 
-J = [y_u, y_la, y_T, y_p, y_eta];
+J_eta = eye(2);
+
+% Combining into Full Jacobian
+J = [J_u, J_la, J_T, J_p, J_eta];
 
 end
 
diff --git a/coco_example_runs/ch_3_linode_uq/ch_3_thesis_figures.m b/coco_example_runs/ch_3_linode_uq/ch_3_thesis_figures.m
index 46f5837bcc361b25b67543672bebd7fa91052b3d..57706efb59ae78c6750e31aa2f540bf555ac0a88 100644
--- a/coco_example_runs/ch_3_linode_uq/ch_3_thesis_figures.m
+++ b/coco_example_runs/ch_3_linode_uq/ch_3_thesis_figures.m
@@ -1,12 +1,16 @@
+img_path = ['/Users/jcoleanderson/Google Drive/',...
+ 'Grad School/00_Thesis Research/00_Document/Images/'];
+
 nds = reshape(uq_gauss_nodes(4,2,{'Hermite', 'Legendre'}),[],2)';
 [x,y] = ndgrid(nds(1,:),nds(2,:));
 
-figure(1);hold on;grid on;box on
+figure1 = figure(1);
+hold on;grid on;box on
 xlim([-2.5, 2.5])
 ylim([-1,1])
 plot(x(:), y(:), 'ko', 'MarkerFaceColor', [0.5,0.5,0.5])
 plot(0,0, 'kp', 'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', 10)
-text(0.05,0.05, '$\left(k_{0}, \omega_{0}\right)$', 'Interpreter', 'latex', 'FontSize', 12)
+text(0.05,0.05, '$\left(p_1, p_2\right)$', 'Interpreter', 'latex', 'FontSize', 12)
 ha = annotation('arrow');  % store the arrow information in ha
 ha.Parent = gca;           % associate the arrow the the current axes
 ha.X = [0 0];          % the location in data units
@@ -55,54 +59,82 @@ for i=1:4
   ha.LineWidth  = 2;          % make the arrow bolder for the picture
 end
 
+set(gca, 'xticklabel', {[]}, 'yticklabel', {[]})
+xlabel('Stochastic Parameter 1, $P_{1}$', 'Interpreter', 'latex', 'FontSize', 15)
+ylabel('Stochastic Parameter 2, $P_{2}$', 'Interpreter', 'latex', 'FontSize', 15)
+
 ax = gca;
 ax.TickLabelInterpreter = 'latex';
 ax.FontSize = 12;
-set(gca, 'xticklabel', {[]}, 'yticklabel', {[]})
-xlabel('Stiffness, $k$', 'Interpreter', 'latex', 'FontSize', 15)
-ylabel('Forcing Frequency, $\omega$', 'Interpreter', 'latex', 'FontSize', 15)
+
+figname = 'uq_bvp_gen_samples.eps';
+fp = strcat(img_path, figname);
+saveas(figure1, fp, 'epsc');
 
 bd = coco_bd_read('freq_sweep');
 om_idx = strcmp('om', bd(1,:));
 mean_idx = strcmp('orig.resp.mean', bd(1,:));
 var_idx = strcmp('orig.resp.var', bd(1,:));
 
-figure(2)
+figure2 = figure(2);
 mudata = csvread('mu_data_from_mathematica.csv');
 semilogx(mudata(:,1),mudata(:,2), 'k-', 'DisplayName', 'Analytical Results', ...
   'LineWidth', 2);
 hold on;grid on;box on
-plt_samples = [300,1000:100:1400, 1400:20:1500, 1510:10:1600, 1700];
-semilogx(cell2mat(bd(plt_samples,om_idx)), cell2mat(bd(plt_samples,mean_idx)), 'ko', ...
-  'DisplayName', 'Numerical Results (PCE)')
-ax = gca;
-ax.TickLabelInterpreter = 'latex';
-ax.FontSize = 12;
+
 xlim([0.001,1000])
-xlabel('Frequency, $\omega$', 'Interpreter', 'latex', 'FontSize', 15)
-ylabel('Mean Initial Position $\mu_{x_0}$', 'Interpreter', 'latex', 'FontSize', 15)
+xlabel('Excitation Frequency, $\omega$', 'Interpreter', 'latex', 'FontSize', 15)
+ylabel('Mean Maximal Displacement $\mu_{X_{1,0}}$', 'Interpreter', 'latex', 'FontSize', 15)
 lgd = legend('Orientation', 'vertical');
 lgd.Interpreter = 'latex';
 lgd.Location = 'best';
 
-figure(3)
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = 12;
+
+figname = 'analytical_mean.eps';
+fp = strcat(img_path, figname);
+saveas(figure2, fp, 'epsc');
+
+plt_samples = [300,1000:100:1400, 1400:20:1500, 1510:10:1600, 1700];
+semilogx(cell2mat(bd(plt_samples,om_idx)), cell2mat(bd(plt_samples,mean_idx)), 'ko', ...
+  'DisplayName', 'Numerical Results (PCE)')
+ax.FontSize = 12;
+figname = 'uq_analytical_comparison_mean.eps';
+fp = strcat(img_path, figname);
+saveas(figure2, fp, 'epsc');
+
+figure3 = figure(3);
 vardata = csvread('var_data_from_mathematica.csv');
 semilogx(vardata(:,1), vardata(:,2), 'k-', 'DisplayName', 'Analytical Results', ...
   'LineWidth', 2);
 hold on;grid on;box on
-semilogx(cell2mat(bd(plt_samples,om_idx)), cell2mat(bd(plt_samples,var_idx)), 'ko', ...
-  'DisplayName', 'Numerical Results (PCE)')
-ax = gca;
-ax.TickLabelInterpreter = 'latex';
-ax.FontSize = 12;
+
 xlim([0.001,1000])
-xlabel('Frequency, $\omega$', 'Interpreter', 'latex', 'FontSize', 15)
-ylabel('Initial Position Variance, $\sigma^{2}_{x_0}$', 'Interpreter', 'latex', 'FontSize', 15)
+xlabel('Excitation Frequency, $\omega$', 'Interpreter', 'latex', 'FontSize', 15)
+ylabel('Maximal Displacement Variance, $\sigma^{2}_{X_{1,0}}$', 'Interpreter', 'latex', 'FontSize', 15)
 lgd = legend('Orientation', 'vertical');
 lgd.Interpreter = 'latex';
 lgd.Location = 'best';
 
-figure(4)
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = 12;
+
+figname = 'analytical_variance.eps';
+fp = strcat(img_path, figname);
+saveas(figure3, fp, 'epsc');
+
+semilogx(cell2mat(bd(plt_samples,om_idx)), cell2mat(bd(plt_samples,var_idx)), 'ko', ...
+  'DisplayName', 'Numerical Results (PCE)')
+ax.FontSize = 12;
+figname = 'uq_analytical_comparison_var.eps';
+fp = strcat(img_path, figname);
+saveas(figure3, fp, 'epsc');
+
+figure4 = figure(4);
+hold on; grid on;
 M = 4;
 P = 4;
 run_name = strcat('UQ_M=',int2str(M),'_P=',int2str(P));
@@ -114,6 +146,33 @@ om_idx = strcmp('om', bd(1,:));
 mean_idx = strcmp('mean', bd(1,:));
 var_idx = strcmp('variance', bd(1,:));
 
+% Plot Mean
+semilogx(coco_bd_col(bd, 'om'), coco_bd_col(bd, 'orig.resp.mean'), 'k', ...
+  'DisplayName', 'Mean, $\mu_{X_{1,0}}$')
+
+% Plot Mean - 3*Std Dev
+semilogx(coco_bd_col(bd, 'om'), coco_bd_col(bd, 'orig.resp.mean') - ...
+  3*sqrt(coco_bd_col(bd, 'orig.resp.var')), 'k--', 'DisplayName', ...
+  'Mean $\pm$ St Dev, $\mu_{X_{1,0}}\pm\sigma_{X_{1,0}}$')
+
+% Plot Mean + 3*Std Dev
+semilogx(coco_bd_col(bd, 'om'), coco_bd_col(bd, 'orig.resp.mean') + ...
+  3*sqrt(coco_bd_col(bd, 'orig.resp.var')), 'k--', 'HandleVisibility', 'off')
+
+xlabel('Excitation Frequency, $\omega$', 'Interpreter', 'latex')
+ylabel('Maximal Displacement', 'Interpreter', 'latex')
+xlim([0.001,1000])
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = 12;
+ax.XScale = 'log';
+lgd = legend('Location', 'best');
+lgd.Interpreter = 'latex';
+
+figname = 'analytical_mean_pm_variance.eps';
+fp = strcat(img_path, figname);
+saveas(figure4, fp, 'epsc');
+
 labs = coco_bd_labs(bd);
 data_mat = zeros(size(labs,2), M+1);
 for lab=labs
@@ -124,36 +183,18 @@ for lab=labs
     end
     data_mat(lab,1) = sol.p(3);
 end
+
 data_mat = sortrows(data_mat,1);
-plot_freq = 1;
-data_samples = [5, 50, 75, 100:10:140, 140:3:152, 153, 155:165];%, 160:2:170, 180];
+data_samples = [5, 50, 75, 100:10:140, 140:3:152, 153, 155:165];
 
 semilogx(data_mat(data_samples,1), data_mat(data_samples,2), 'o', ...
     'MarkerEdgeColor', 'k', 'MarkerFaceColor', ...
     [100/255 100/255 100/255], 'MarkerSize', 5, 'DisplayName', 'Samples');
-hold on
+
 semilogx(data_mat(data_samples,1), data_mat(data_samples,3:end), 'o', ...
     'MarkerEdgeColor', 'k', 'MarkerFaceColor', ...
     [100/255 100/255 100/255], 'MarkerSize', 5, 'HandleVisibility', 'off');
-
-% Plot Mean
-semilogx(coco_bd_col(bd, 'om'), coco_bd_col(bd, 'orig.resp.mean'), 'k', ...
-  'DisplayName', 'Mean, $\mu_{x_0}$')
-
-% Plot Mean - 3*Std Dev
-semilogx(coco_bd_col(bd, 'om'), coco_bd_col(bd, 'orig.resp.mean') - ...
-  3*sqrt(coco_bd_col(bd, 'orig.resp.var')), 'k--', 'DisplayName', ...
-  'Mean $\pm$ St Dev, $\mu_{x_0}\pm\sigma_{x_0}$')
-
-% Plot Mean + 3*Std Dev
-semilogx(coco_bd_col(bd, 'om'), coco_bd_col(bd, 'orig.resp.mean') + ...
-  3*sqrt(coco_bd_col(bd, 'orig.resp.var')), 'k--', 'HandleVisibility', 'off')
-
-xlabel('Frequency, $\omega$', 'Interpreter', 'latex')
-ylabel('Amplitude, $x_{1}\left(0\right)$', 'Interpreter', 'latex')
-ax = gca;
-ax.TickLabelInterpreter = 'latex';
-ax.FontSize = 12;
-lgd = legend('Location', 'best');
-lgd.Interpreter = 'latex';
-grid on
+  
+figname = 'uq_linode_pce_samples.eps';
+fp = strcat(img_path, figname);
+saveas(figure4, fp, 'epsc');
diff --git a/coco_example_runs/ch_3_linode_uq/demo_for_thesis.m b/coco_example_runs/ch_3_linode_uq/demo_for_thesis.m
index 8a3fa325aeb3c3f11d895196c8ccf04765995313..1a55d6de73758604348875d8b8f3beed0d3a9447 100644
--- a/coco_example_runs/ch_3_linode_uq/demo_for_thesis.m
+++ b/coco_example_runs/ch_3_linode_uq/demo_for_thesis.m
@@ -4,53 +4,38 @@ addpath('../utils')
 
 % Let Transients die out
 p0 = [3;0;1];
-[~, x0]   = ode45(@(t,x) linode_het(t, x, p0), ...
-  [0 6*pi], [1; 0]);
+[~, x0]   = ode45(@(t,x) linode(t, x, p0), [0 20*pi], [1; 0]);
 % Initial Solution Guess
-[t0, x0]   = ode45(@(t,x) linode_het(t, x, p0), ...
-  [0 2*pi], [x0(end,:)']);
+[t0, x0]   = ode45(@(t,x) linode(t, x, p0), [0 2*pi], [x0(end,:)']);
 
 % Initialize problem instance and set options
 prob = coco_prob();
 prob = coco_set(prob, 'ode', 'autonomous', false);
-prob = coco_set(prob, 'coll', 'NTST', 30, ...
-  'NCOL', 4);
-prob = coco_set(prob, 'cont', 'PtMX', 1500, ...
-  'h', 0.5, 'almax', 30, 'h_max', 10);
+prob = coco_set(prob, 'coll', 'NTST', 15, 'NCOL', 4);
+prob = coco_set(prob, 'cont', 'PtMX', 1500, 'h', 0.5, 'h_max', 10);
 
 % 'coll'-toolbox arguments
-coll_args = {@linode_het, ...
-  @linode_het_DFDX, @linode_het_DFDP, @linode_het_DFDT, ...
-  @linode_het_DFDXDX, @linode_het_DFDXDP, ...
-  @linode_het_DFDPDP, @linode_het_DFDXDT, ...
-  @linode_het_DFDTDP, @linode_het_DFDTDT, ...
-  t0, x0, p0};
+coll_args = {@linode, @linode_dx, @linode_dp, @linode_dt, t0, x0, p0};
 
 % Parameter names
-pnames = {'k','phi', 'om'};
+pnames = {'k', 'phi', 'om'};
 
 % 'bvp'-toolbox arguments
 % Includes a velocity condition to ensure the initial
 % position is a maximum
-bvp_args = {@fbc_x10, @Jbc_x10, @dJbc_x10};
+bvp_args = {@fbc_x10, @Jbc_x10};
 
 % 'uq'-toolbox arguments
-uq_args = {
-  {'k'}, ...                % Stochastic Parameter
-  {'Normal'}, ...           % Distribution Type
-  [[3, 0.2]], ...           % [Mean, St.Dev]
-  {'phi'}};                 % Denote phi as a unique
-                            % deterministic parameter
+% {{Stochastic Parameter}, {Distribution Type}, [[mean, std dev]], {Unique Parameter}}
+uq_args = {{'k'}, {'Normal'}, [[3, 0.2]], {'phi'}};
 
 % Call to sample constructor
-prob = uq_isol2bvp_sample(prob, 'orig', ...
-  coll_args{:}, pnames, bvp_args{:}, uq_args{:});
-
-% Add response function, 'resp', to the sample 'orig'
-prob = uq_coll_add_response(prob, 'orig', ...
-  'resp', 'bv', @x10, @x10_du, @x10_dudu);
-
-% Continue in frequency, display mean and variance
-uq_bd = coco(prob, 'freq_sweep', [], 1, ...
-  {'om', 'orig.resp.mean', 'orig.resp.var'}, ...
-  [0.001, 1000]);
\ No newline at end of file
+prob = uq_isol2bvp_sample(prob, 'orig', coll_args{:}, pnames, bvp_args{:}, uq_args{:});
+
+% % Add response function, 'resp', to the sample 'orig'
+% prob = uq_coll_add_response(prob, 'orig', 'resp', 'bv', @x10, @x10_du, @x10_dudu);
+% 
+% % Continue in frequency, display mean and variance
+% uq_bd = coco(prob, 'freq_sweep', [], 1, ...
+%   {'om', 'orig.resp.mean', 'orig.resp.var'}, ...
+%   [0.001, 1000]);
\ No newline at end of file
diff --git a/coco_example_runs/ch_4_linode_robust_optimization/analytical_optimum.m b/coco_example_runs/ch_4_linode_robust_optimization/analytical_optimum.m
new file mode 100644
index 0000000000000000000000000000000000000000..b728d991ff6a5ba68df751b2d6dae8d273d7efff
--- /dev/null
+++ b/coco_example_runs/ch_4_linode_robust_optimization/analytical_optimum.m
@@ -0,0 +1,33 @@
+rho = @(k, muk) exp((-(k - muk).^2)/(2*0.2^2))/(sqrt(2*pi*0.2^2));
+std = @(k, muk) (k-muk)./(0.2^2);
+x10 = @(k) 1./(sqrt((k-1).^2 + 1));
+
+n = 5000;
+muks1 = linspace(0.2,1,n/2);
+muks2 = linspace(1,8,n/2);
+muks = [muks1,muks2];
+mu = zeros(1,n);
+var = zeros(1,n);
+obj = zeros(1,n);
+dv = zeros(1,n);
+for i=1:n
+f = @(k) x10(k).*rho(k, muks(i));
+f2 = @(k) ((x10(k)).^2).*rho(k, muks(i));
+mu(i) = integral(f,-Inf,Inf);
+var(i) = integral(f2,-Inf,Inf) - (mu(i))^2;
+obj(i) = mu(i) - 3*sqrt(var(i));
+% dmuk = @(k) x10(k).*std(k,muks(i)).*rho(k, muks(i));
+% dvar1 = @(k) (x10(k).*(rho(k,muks(i))).^2).*std(k, muks(i));
+% dvar2 = @(k) 2*(x10(k).*std(k,muks(i)).*rho(k, muks(i)));
+% dvar3 = @(k) (x10(k).*std(k,muks(i)));
+% dv(1,i) = integral(dmuk,-Inf,Inf) - 3.*(integral(dvar1,-Inf,Inf) - integral(dvar2,-Inf,Inf).*integral(dvar3,-Inf,Inf));
+end
+
+figure(1)
+semilogx(muks, obj, 'k')
+xlim([0.2,8])
+grid on
+figure(2)
+semilogx(muks(2:end), diff(obj)./diff(muks), 'k')
+xlim([0.2,8])
+grid on
\ No newline at end of file
diff --git a/coco_example_runs/ch_4_linode_robust_optimization/ch_4_thesis_figures.m b/coco_example_runs/ch_4_linode_robust_optimization/ch_4_thesis_figures.m
new file mode 100644
index 0000000000000000000000000000000000000000..904fa52cba0899cd13cd8624e449999f390ada47
--- /dev/null
+++ b/coco_example_runs/ch_4_linode_robust_optimization/ch_4_thesis_figures.m
@@ -0,0 +1,57 @@
+rho = @(k, muk) exp((-(k - muk).^2)/(2*0.2^2))/(sqrt(2*pi*0.2^2));
+std = @(k, muk) (k-muk)./(0.2^2);
+x10 = @(k) 1./(sqrt((k-1).^2 + 1));
+
+n = 10000;
+muks1 = linspace(0.2,1,n/2);
+muks2 = linspace(1,8,n/2);
+muks = [muks1,muks2(2:end)];
+mu = zeros(1,n-1);
+var = zeros(1,n-1);
+obj = zeros(1,n-1);
+dv = zeros(1,n-1);
+for i=1:(n-1)
+f = @(k) x10(k).*rho(k, muks(i));
+f2 = @(k) ((x10(k)).^2).*rho(k, muks(i));
+mu(i) = integral(f,-Inf,Inf);
+var(i) = integral(f2,-Inf,Inf) - (mu(i))^2;
+obj(i) = mu(i) - 3*sqrt(var(i));
+end
+
+figure(1)
+semilogx(muks(1:end-1),  diff(obj)./diff(muks), 'k-', 'LineWidth', 2);
+grid on; box on
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = 12;
+xlim([0.2,8])
+xlabel('Mean Stiffness, $\mu_{k}$', 'Interpreter', 'latex', 'FontSize', 15)
+ylabel('Rate of change of objective function $\mu_r-3\sigma_r$', 'Interpreter', 'latex', 'FontSize', 15)
+
+figure(2)
+semilogx(muks,  obj, 'k-', 'LineWidth', 2);
+grid on; box on
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = 12;
+xlim([0.2,8])
+xlabel('Mean Stiffness, $\mu_{k}$', 'Interpreter', 'latex', 'FontSize', 15)
+ylabel('Objective function $\mu_{r} - 3\sigma_{r}$', 'Interpreter', 'latex', 'FontSize', 15)
+
+
+% figure(2)
+% bd = coco_bd_read('rdo');
+% mu = coco_bd_col(bd, 'orig.resp.mean');
+% var = coco_bd_col(bd, 'orig.resp.var');
+% muk = coco_bd_col(bd, 'mu.k');
+% obj = mu - 3*sqrt(var);
+% dobj = diff(mu - 3*sqrt(var))./diff(muk);
+% semilogx(muk, obj, 'k-', 'LineWidth', 2);
+% grid on; box on
+% ax = gca;
+% ax.TickLabelInterpreter = 'latex';
+% ax.FontSize = 12;
+% xlim([0.01,100])
+% xlabel('Mean Stiffness, $\mu_{k}$', 'Interpreter', 'latex', 'FontSize', 15)
+% ylabel('Objective Function Value, $\mu_{r} - 3\sigma_{r}$', 'Interpreter', 'latex', 'FontSize', 15)
+
diff --git a/coco_example_runs/ch_4_linode_robust_optimization/demo_for_thesis.m b/coco_example_runs/ch_4_linode_robust_optimization/demo_for_thesis.m
index 1c5303a85a1f128591589594de6868d6ff0e16af..edd65c8525a350b9f8ec4dbe04e01e85d98ab5f6 100644
--- a/coco_example_runs/ch_4_linode_robust_optimization/demo_for_thesis.m
+++ b/coco_example_runs/ch_4_linode_robust_optimization/demo_for_thesis.m
@@ -4,26 +4,24 @@ addpath('../utils')
 
 % Let Transients die out
 p0 = [3;0;1];
-[~, x0] = ode45(@(t,x) linode_het(t, x, p0), ...
+[~, x0] = ode45(@(t,x) linode(t, x, p0), ...
   [0 6*pi], [1; 0]);
 % Initial Solution Guess
-[t0, x0] = ode45(@(t,x) linode_het(t, x, p0), ...
+[t0, x0] = ode45(@(t,x) linode(t, x, p0), ...
   [0 2*pi], [x0(end,:)']);
 
 % Initialize problem instance and set options
 prob_init = coco_prob();
 prob_init = coco_set(prob_init, 'ode', 'autonomous', false);
-prob_init = coco_set(prob_init, 'coll', 'NTST', 15, ...
-  'NCOL', 4);
-prob_init = coco_set(prob_init, 'cont', 'PtMX', 100, ...
-  'h', 0.5, 'almax', 30, 'h_max', 10, 'NPR', 10);
+prob_init = coco_set(prob_init, 'coll', 'NTST', 15, 'NCOL', 4);
+prob_init = coco_set(prob_init, 'cont', 'h', 0.5, 'h_max', 10);
 
 % 'coll'-toolbox arguments
-coll_args = {@linode_het, ...
-  @linode_het_DFDX, @linode_het_DFDP, @linode_het_DFDT, ...
-  @linode_het_DFDXDX, @linode_het_DFDXDP, ...
-  @linode_het_DFDPDP, @linode_het_DFDXDT, ...
-  @linode_het_DFDTDP, @linode_het_DFDTDT, ...
+coll_args = {@linode, ...
+  @linode_dx, @linode_dp, @linode_dt, ...
+  @linode_dxdx, @linode_dxdp, ...
+  @linode_dpdp, @linode_dxdt, ...
+  @linode_dtdp, @linode_dtdt, ...
   t0, x0, p0};
 
 % Parameter names
@@ -35,49 +33,29 @@ pnames = {'k','phi', 'om'};
 bvp_args = {@fbc_x10, @Jbc_x10, @dJbc_x10};
 
 % 'uq'-toolbox arguments
-uq_args = {
-  {'k'}, ...       % Stochastic Parameter
-  {'Normal'}, ...  % Distribution Type
-  [[3, 0.2]], ...  % [Mean, St.Dev]
-  {'phi'}, ...     % Denote phi as a unique deterministic
-           ...     % parameter
-  '-add-adjt'};    % Flag to specify that adjoint equations
-                   % should be added to the problem during
-                   % construction of the uq sample.
+uq_args = {{'k'}, {'Normal'}, [[3, 0.2]], {'phi'}, '-add-adjt'};
 
 % Call to sample constructor
-prob = uq_isol2bvp_sample(prob_init, 'orig', ...
-  coll_args{:}, pnames, bvp_args{:}, uq_args{:});
+prob = uq_isol2bvp_sample(prob_init, 'orig', coll_args{:}, pnames, bvp_args{:}, uq_args{:});
 % Add response function, 'resp', to the sample 'orig'
-prob = uq_coll_add_response(prob, 'orig', ...
-  'resp', 'bv', @x10, @x10_du, @x10_dudu);
+prob = uq_coll_add_response(prob, 'orig', 'resp', 'bv', @x10, @x10_du, @x10_dudu);
 prob = uq_coll_add_response_adjoint(prob, 'orig', 'resp');
 
 % Robust Design Optimization Objective Function
 response_id = coco_get_id('orig', 'uq', 'responses');
 
-mean_idx = coco_get_func_data(prob, ...
-  coco_get_id(response_id, 'resp', 'mean'), 'uidx');
-var_idx = coco_get_func_data(prob, ...
-  coco_get_id(response_id, 'resp', 'variance'), 'uidx');
+mean_idx = coco_get_func_data(prob, coco_get_id(response_id, 'resp', 'mean'), 'uidx');
+var_idx = coco_get_func_data(prob, coco_get_id(response_id, 'resp', 'variance'), 'uidx');
 
-prob = coco_add_func(prob, 'rdo', @rdo, @rdo_dU, ...
-  @rdo_dUdU, [], 'inactive', 'rdo', 'uidx', ...
-  [mean_idx;var_idx]);
+prob = coco_add_func(prob, 'rdo', @rdo, @rdo_dU, @rdo_dUdU, [], 'inactive', 'rdo', 'uidx', [mean_idx;var_idx]);
 
-mean_aidx = coco_get_adjt_data(prob, ...
-  coco_get_id(response_id, 'resp', 'mean'), 'axidx');
-var_aidx = coco_get_adjt_data(prob, ...
-  coco_get_id(response_id, 'resp', 'variance'), 'axidx');
+mean_aidx = coco_get_adjt_data(prob, coco_get_id(response_id, 'resp', 'mean'), 'axidx');
+var_aidx = coco_get_adjt_data(prob, coco_get_id(response_id, 'resp', 'variance'), 'axidx');
 
-prob = coco_add_adjt(prob, 'rdo', 'd.rdo', 'aidx', ...
-  [mean_aidx;var_aidx]);
+prob = coco_add_adjt(prob, 'rdo', 'd.rdo', 'aidx', [mean_aidx;var_aidx]);
 
 % Continue in frequency, display mean and variance
-uq_bd = coco(prob, 'rdo', [], 1, ...
-  {'rdo', 'mu.k', 'd.rdo', 'orig.resp.mean', ...
-   'orig.resp.var', 'd.om', 'd.sig.k'}, ...
-   {[],[0.5,100]});
+uq_bd = coco(prob, 'rdo', [], 1, {'rdo', 'mu.k', 'd.rdo', 'orig.resp.mean', 'orig.resp.var', 'd.om', 'd.sig.k'}, {[],[1e-3,1e3]});
 
 %% Switch Branches
 BPLab = coco_bd_labs(uq_bd, 'BP');
@@ -85,34 +63,23 @@ prob = prob_init;
 
 % Call to constructor, including flag to construct the
 % adjoint equations.
-prob = uq_BP2bvp(prob, 'orig', 'rdo', BPLab(1), ...
-  '-add-adjt', '-add-resp');
+prob = uq_BP2bvp(prob, 'orig', 'rdo', BPLab(1), '-add-adjt', '-add-resp');
 
-mean_idx = coco_get_func_data(prob, ...
-  coco_get_id(response_id, 'resp', 'mean'), 'uidx');
-var_idx = coco_get_func_data(prob, ...
-  coco_get_id(response_id, 'resp', 'variance'), 'uidx');
+mean_idx = coco_get_func_data(prob, coco_get_id(response_id, 'resp', 'mean'), 'uidx');
+var_idx = coco_get_func_data(prob, coco_get_id(response_id, 'resp', 'variance'), 'uidx');
 
-prob = coco_add_func(prob, 'rdo', @rdo, @rdo_dU, ...
-  @rdo_dUdU, [], 'inactive', 'rdo', 'uidx', ...
-  [mean_idx;var_idx]);
+prob = coco_add_func(prob, 'rdo', @rdo, @rdo_dU, @rdo_dUdU, ...
+  [], 'inactive', 'rdo', 'uidx', [mean_idx;var_idx]);
 
-mean_aidx = coco_get_adjt_data(prob, ...
-  coco_get_id(response_id, 'resp', 'mean'), 'axidx');
-var_aidx = coco_get_adjt_data(prob, ...
-  coco_get_id(response_id, 'resp', 'variance'), 'axidx');
+mean_aidx = coco_get_adjt_data(prob, coco_get_id(response_id, 'resp', 'mean'), 'axidx');
+var_aidx = coco_get_adjt_data(prob, coco_get_id(response_id, 'resp', 'variance'), 'axidx');
 
 chart = coco_read_solution('rdo', BPLab(1), 'chart');
 cdata = coco_get_chart_data(chart, 'lsol');
-[chart, lidx] = coco_read_adjoint('rdo', 'rdo', ...
-  BPLab(1), 'chart', 'lidx');
+[chart, lidx] = coco_read_adjoint('rdo', 'rdo', BPLab(1), 'chart', 'lidx');
 l0 = chart.x;
 tl0 = cdata.v(lidx);
 
-prob = coco_add_adjt(prob, 'rdo', 'd.rdo', ...
-  'aidx', [mean_aidx;var_aidx], ...
-  'l0', l0, 'tl0', tl0);
-prob = coco_set(prob, 'cont', 'NPR', 1);
-uq_bd = coco(prob, 'rdo.switch', [], 1, ...
-  {'d.rdo', 'mu.k', 'rdo', 'orig.resp.mean', ...
+prob = coco_add_adjt(prob, 'rdo', 'd.rdo', 'aidx', [mean_aidx;var_aidx], 'l0', l0, 'tl0', tl0);
+uq_bd = coco(prob, 'rdo.switch', [], 1, {'d.rdo', 'mu.k', 'rdo', 'orig.resp.mean', ...
   'orig.resp.var', 'd.om', 'd.sig.k'}, [0,1]);
\ No newline at end of file
diff --git a/coco_example_runs/ch_4_linode_robust_optimization/obj_data_from_mathematica.csv b/coco_example_runs/ch_4_linode_robust_optimization/obj_data_from_mathematica.csv
new file mode 100644
index 0000000000000000000000000000000000000000..7f2e1b9ac70dad8256f0309ab9935136f0dd5aca
--- /dev/null
+++ b/coco_example_runs/ch_4_linode_robust_optimization/obj_data_from_mathematica.csv
@@ -0,0 +1,601 @@
+0.001,-0.7832491348182646
+0.0010232929922807535,-0.7832692548545528
+0.0010471285480508996,-0.7832898436292848
+0.001071519305237606,-0.783310912064606
+0.0010964781961431851,-0.7833324713372591
+0.001122018454301963,-0.7833545328845037
+0.0011481536214968829,-0.7833771084102048
+0.001174897554939529,-0.7834002098910422
+0.001202264434617413,-0.783423849582882
+0.0012302687708123812,-0.7834480400272852
+0.0012589254117941675,-0.78347279405817
+0.0012882495516931337,-0.7834981248086432
+0.0013182567385564075,-0.7835240457179631
+0.0013489628825916532,-0.7835505705386919
+0.0013803842646028853,-0.7835777133440103
+0.001412537544622754,-0.7836054885351877
+0.001445439770745928,-0.7836339108492392
+0.0014791083881682072,-0.7836629953667655
+0.0015135612484362087,-0.7836927575199648
+0.0015488166189124811,-0.7837232131008374
+0.001584893192461114,-0.7837543782695839
+0.0016218100973589297,-0.7837862695631954
+0.0016595869074375613,-0.7838189039042494
+0.0016982436524617442,-0.7838522986099037
+0.0017378008287493763,-0.783886471401109
+0.0017782794100389228,-0.7839214404393062
+0.0018197008586099826,-0.7839572242269803
+0.0018620871366628676,-0.7839938417811629
+0.0019054607179632482,-0.7840313125344479
+0.0019498445997580456,-0.784069656372594
+0.001995262314968879,-0.7841088936451097
+0.0020417379446695297,-0.7841490451760766
+0.0020892961308540386,-0.7841901322752316
+0.0021379620895022326,-0.7842321767492977
+0.002187761623949552,-0.7842752009135935
+0.00223872113856834,-0.7843192276039117
+0.0022908676527677724,-0.7843642801886589
+0.0023442288153199225,-0.784410382581304
+0.00239883291901949,-0.7844575592531058
+0.002454708915685031,-0.78450583524613
+0.0025118864315095794,-0.7845552361865864
+0.0025703957827688645,-0.7846057882984687
+0.0026302679918953813,-0.7846575184175142
+0.0026915348039269166,-0.7847104540054998
+0.002754228703338166,-0.7847646231648484
+0.002818382931264455,-0.7848200546536115
+0.0028840315031266055,-0.7848767779007686
+0.002951209226666387,-0.7849348230219141
+0.003019951720402016,-0.7849942208352793
+0.003090295432513592,-0.7850550028781673
+0.0031622776601683794,-0.785117201423732
+0.003235936569296281,-0.7851808494981927
+0.003311311214825911,-0.7852459808984035
+0.0033884415613920273,-0.7853126302098887
+0.0034673685045253167,-0.7853808328252372
+0.0035481338923357532,-0.785450624962993
+0.003630780547701014,-0.7855220436869383
+0.003715352290971728,-0.785595126925843
+0.0038018939632056127,-0.7856699134936944
+0.003890451449942805,-0.7857464431103719
+0.003981071705534973,-0.7858247564228245
+0.004073802778041126,-0.785904895026733
+0.004168693834703355,-0.7859869014886884
+0.004265795188015926,-0.7860708193688836
+0.004365158322401661,-0.786156693244342
+0.0044668359215096305,-0.7862445687326702
+0.004570881896148752,-0.7863344925164013
+0.004677351412871981,-0.7864265123678738
+0.004786300923226385,-0.7865206771747066
+0.004897788193684461,-0.7866170369658738
+0.005011872336272725,-0.7867156429383906
+0.005128613839913648,-0.786816547484596
+0.005248074602497723,-0.7869198042201191
+0.005370317963702527,-0.7870254680124633
+0.005495408738576248,-0.7871335950102623
+0.005623413251903491,-0.7872442426732433
+0.005754399373371567,-0.7873574698028654
+0.00588843655355589,-0.787473336573678
+0.0060255958607435805,-0.7875919045654256
+0.006165950018614822,-0.7877132367958778
+0.00630957344480193,-0.7878373977544626
+0.006456542290346556,-0.7879644534366311
+0.006606934480075964,-0.7880944713790798
+0.006760829753919818,-0.7882275206957536
+0.006918309709189363,-0.7883636721147025
+0.00707945784384138,-0.7885029980158087
+0.007244359600749898,-0.7886455724693592
+0.007413102413009177,-0.7887914712755484
+0.007585775750291836,-0.788940772004892
+0.00776247116628692,-0.7890935540395634
+0.007943282347242814,-0.7892498986157044
+0.008128305161640995,-0.7894098888667231
+0.008317637711026709,-0.7895736098513135
+0.008511380382023767,-0.7897411486638233
+0.008709635899560805,-0.7899125943830951
+0.008912509381337459,-0.7900880381849142
+0.009120108393559097,-0.7902675733742911
+0.009332543007969905,-0.7904512954351228
+0.009549925860214359,-0.7906393020810268
+0.009772372209558112,-0.7908316933072834
+0.01,-0.7910285714440274
+0.010232929922807542,-0.7912300412106549
+0.010471285480508996,-0.7914362097714487
+0.010715193052376065,-0.791647186792509
+0.01096478196143185,-0.7918630844999812
+0.011220184543019636,-0.7920840177395966
+0.01148153621496883,-0.7923101040376038
+0.011748975549395297,-0.7925414636630561
+0.012022644346174132,-0.7927782196915263
+0.012302687708123818,-0.7930204980702698
+0.012589254117941675,-0.7932684276848625
+0.012882495516931342,-0.7935221404273367
+0.013182567385564075,-0.7937817712658475
+0.01348962882591654,-0.7940474583159176
+0.013803842646028852,-0.7943193429132718
+0.014125375446227547,-0.7945975696882868
+0.014454397707459272,-0.7948822866419989
+0.014791083881682071,-0.7951736452447438
+0.01513561248436208,-0.7954718004333059
+0.01548816618912481,-0.7957769108153825
+0.015848931924611134,-0.7960891386704725
+0.0162181009735893,-0.7964086500557721
+0.016595869074375606,-0.7967356148918329
+0.016982436524617443,-0.797070207032615
+0.017378008287493755,-0.797412604433948
+0.01778279410038923,-0.7977629891280711
+0.018197008586099836,-0.7981215473968174
+0.018620871366628676,-0.7984884698482452
+0.019054607179632473,-0.7988639515150253
+0.019498445997580455,-0.7992481919548935
+0.0199526231496888,-0.7996413953531512
+0.020417379446695295,-0.8000437706272666
+0.020892961308540396,-0.8004555315336068
+0.021379620895022326,-0.8008768967763074
+0.02187761623949553,-0.8013080901182912
+0.0223872113856834,-0.8017493404944831
+0.022908676527677734,-0.8022008821272104
+0.023442288153199226,-0.8026629546438088
+0.02398832919019491,-0.8031358031964553
+0.02454708915685031,-0.8036196785842162
+0.025118864315095808,-0.804114837377329
+0.025703957827688632,-0.804621542043698
+0.026302679918953815,-0.8051400610776389
+0.026915348039269153,-0.8056706691308049
+0.02754228703338166,-0.8062136473586523
+0.028183829312644536,-0.8067692826904191
+0.028840315031266057,-0.8073378692827122
+0.029512092266663854,-0.807919707769573
+0.03019951720402016,-0.8085151056295454
+0.030902954325135904,-0.809124377329334
+0.03162277660168379,-0.8097478444694415
+0.03235936569296283,-0.810385835931689
+0.03311311214825911,-0.8110386880285569
+0.033884415613920256,-0.8117067446542303
+0.034673685045253165,-0.8123903574373577
+0.03548133892335755,-0.8130898858947764
+0.03630780547701014,-0.8138056975876338
+0.03715352290971726,-0.8145381682776535
+0.038018939632056124,-0.8152876820849254
+0.03890451449942807,-0.8160546316464417
+0.039810717055349734,-0.8168394182752059
+0.04073802778041128,-0.8176424521197234
+0.04168693834703355,-0.8184641523235643
+0.04265795188015928,-0.8193049471847286
+0.04365158322401661,-0.8201652743144686
+0.04466835921509633,-0.8210455807951764
+0.04570881896148752,-0.8219463233369771
+0.046773514128719815,-0.8228679684325684
+0.047863009232263824,-0.8238109925097736
+0.04897788193684462,-0.8247758820813221
+0.05011872336272722,-0.8257631338912244
+0.05128613839913648,-0.8267732550571125
+0.05248074602497726,-0.8278067632077977
+0.05370317963702527,-0.8288641866152898
+0.054954087385762455,-0.829946064320414
+0.05623413251903491,-0.8310529462510321
+0.057543993733715694,-0.8321853933319142
+0.0588843655355589,-0.8333439775850595
+0.06025595860743578,-0.8345292822192627
+0.06165950018614822,-0.8357419017075673
+0.06309573444801933,-0.8369824418511236
+0.06456542290346556,-0.8382515198278312
+0.06606934480075961,-0.8395497642240406
+0.06760829753919818,-0.8408778150472904
+0.06918309709189366,-0.8422363237180983
+0.0707945784384138,-0.8436259530384492
+0.07244359600749903,-0.8450473773064142
+0.07413102413009177,-0.8465012815552933
+0.0758577575029184,-0.847988362428135
+0.07762471166286919,-0.8495093273786225
+0.07943282347242818,-0.8510648946385102
+0.08128305161640995,-0.852655792984881
+0.08317637711026708,-0.8542827614609758
+0.08511380382023763,-0.8559465490459417
+0.08709635899560805,-0.8576479142685647
+0.08912509381337455,-0.8593876247593659
+0.09120108393559097,-0.8611664567352444
+0.0933254300796991,-0.8629851944099836
+0.09549925860214359,-0.8648446293236087
+0.09772372209558107,-0.866745559582806
+0.1,-0.8686887890039059
+0.10232929922807547,-0.8706751261492269
+0.10471285480508996,-0.8727053832466876
+0.10715193052376071,-0.8747803749816749
+0.1096478196143185,-0.8769009171491904
+0.1122018454301963,-0.8790678251531499
+0.1148153621496883,-0.881281912338562
+0.11748975549395291,-0.8835439881409735
+0.12022644346174131,-0.8858548560361078
+0.1230268770812381,-0.88821531127129
+0.12589254117941676,-0.8906261383579142
+0.12882495516931336,-0.893088108303334
+0.13182567385564073,-0.8956019755575706
+0.13489628825916533,-0.8981684746485116
+0.13803842646028852,-0.9007883164767216
+0.1412537544622754,-0.9034621842382602
+0.1445439770745928,-0.9061907289410496
+0.1479108388168207,-0.9089745644770821
+0.15135612484362088,-0.9118142622093197
+0.1548816618912481,-0.9147103450282309
+0.15848931924611143,-0.9176632808288009
+0.16218100973589297,-0.9206734753542594
+0.16595869074375613,-0.9237412643477135
+0.16982436524617442,-0.9268669049474432
+0.17378008287493762,-0.9300505662556449
+0.1778279410038923,-0.933292319003805
+0.18197008586099844,-0.9365921242307489
+0.18620871366628675,-0.9399498208816535
+0.19054607179632482,-0.9433651122276221
+0.19498445997580455,-0.9468375509962812
+0.19952623149688808,-0.9503665230934268
+0.20417379446695297,-0.9539512297849531
+0.20892961308540386,-0.957590668196178
+0.21379620895022325,-0.9612836110371284
+0.21877616239495518,-0.9650285779192063
+0.223872113856834,-0.9688238204791566
+0.22908676527677724,-0.9726672837615334
+0.23442288153199228,-0.9765565809874237
+0.239883291901949,-0.9804889590585658
+0.2454708915685031,-0.9844612619984587
+0.25118864315095796,-0.9884698909839968
+0.25703957827688645,-0.9925107606487145
+0.26302679918953814,-0.996579251322813
+0.26915348039269166,-1.0006701568393097
+0.2754228703338166,-1.0047776275079052
+0.2818382931264455,-1.008895107823035
+0.28840315031266056,-1.0130152684390117
+0.2951209226666387,-1.0171299319067522
+0.3019951720402016,-1.0212299887628409
+0.30902954325135923,-1.0253053234442007
+0.31622776601683794,-1.0293446892281788
+0.32359365692962844,-1.0333356318188016
+0.3311311214825911,-1.037264360575791
+0.33884415613920277,-1.0411156268090376
+0.34673685045253166,-1.04487258828051
+0.3548133892335757,-1.0485166619486979
+0.3630780547701014,-1.0520273640870261
+0.3715352290971724,-1.055382136883301
+0.38018939632056126,-1.0585561606080072
+0.3890451449942805,-1.0615221504361867
+0.3981071705534973,-1.0642501370182331
+0.4073802778041126,-1.0667072299289992
+0.41686938347033553,-1.0688573631849891
+0.42657951880159256,-1.0706610221151176
+0.4365158322401661,-1.0720749510089729
+0.44668359215096304,-1.0730518411598333
+0.4570881896148752,-1.0735399991747105
+0.4677351412871981,-1.0734829957617882
+0.47863009232263853,-1.0728192956483127
+0.48977881936844614,-1.071481869809417
+0.5011872336272725,-1.0693977919006692
+0.5128613839913648,-1.0664878216206195
+0.5248074602497729,-1.062665978746765
+0.5370317963702527,-1.0578391129472668
+0.5495408738576248,-1.051906475778485
+0.5623413251903491,-1.0447593033183404
+0.5754399373371573,-1.036280419942345
+0.588843655355589,-1.0263438758032546
+0.6025595860743581,-1.0148146346213367
+0.6165950018614822,-1.001548329937874
+0.6309573444801936,-0.9863911134011237
+0.6456542290346556,-0.9691796217127022
+0.6606934480075958,-0.9497410938784081
+0.6760829753919819,-0.9278936752145746
+0.6918309709189363,-0.9034469497433146
+0.707945784384138,-0.8762027479162633
+0.7244359600749899,-0.8459562817369577
+0.7413102413009177,-0.8124976642006423
+0.7585775750291835,-0.7756138738795026
+0.776247116628692,-0.7350912282006391
+0.7943282347242814,-0.6907184296905133
+0.8128305161640995,-0.6422902475279354
+0.8317637711026709,-0.589611891235684
+0.8511380382023768,-0.5325041232820522
+0.8709635899560806,-0.47080914168853105
+0.8912509381337459,-0.40439724135586896
+0.9120108393559097,-0.33317423273622043
+0.9332543007969915,-0.2570895578571033
+0.9549925860214359,-0.17614499607211503
+0.9772372209558111,-0.09040379532749014
+1.,8.673617379884043e-16
+1.0232929922807548,0.09485232473316019
+1.0471285480508996,0.1938503464987592
+1.071519305237607,0.2965946452926866
+1.096478196143185,0.40258283362529845
+1.1220184543019642,0.5112051845468724
+1.1481536214968828,0.6217428648926346
+1.1748975549395304,0.7333693698630046
+1.2022644346174132,0.8451557132166748
+1.2302687708123812,0.9560798373765614
+1.2589254117941675,1.0650405642191827
+1.2882495516931336,1.1708762087749665
+1.3182567385564075,1.2723877282671363
+1.3489628825916533,1.3683659878965977
+1.3803842646028852,1.4576224094134898
+1.412537544622754,1.5390219522109982
+1.4454397707459279,1.6115170880909537
+1.4791083881682072,1.6741812014435293
+1.5135612484362087,1.7262397072503062
+1.5488166189124812,1.7670971562380777
+1.584893192461114,1.7963587068985831
+1.6218100973589298,1.813844592533935
+1.6595869074375613,1.8195965874467
+1.6982436524617444,1.8138759538712264
+1.7378008287493762,1.7971528902859846
+1.7782794100389228,1.7700880532872056
+1.8197008586099843,1.7335072359034474
+1.8620871366628675,1.688370705596091
+1.9054607179632483,1.635739002125867
+1.9498445997580456,1.5767371247490292
+1.9952623149688808,1.5125189609340248
+2.0417379446695296,1.4442338430090296
+2.089296130854041,1.3729964895707392
+2.1379620895022327,1.2998615276693082
+2.1877616239495516,1.22580320680156
+2.23872113856834,1.1517006002214047
+2.2908676527677723,1.0783281354120544
+2.344228815319923,1.0063510992702551
+2.39883291901949,0.9363254786443959
+2.454708915685031,0.868701389178675
+2.5118864315095797,0.8038292938263766
+2.570395782768865,0.7419682187164811
+2.6302679918953813,0.6832952387522363
+2.691534803926917,0.6279155989260916
+2.7542287033381663,0.5758729490907594
+2.818382931264455,0.5271592858940525
+2.8840315031266055,0.48172430612506356
+2.951209226666387,0.4394839745332481
+3.019951720402016,0.40032819266084596
+3.090295432513592,0.36412752223331696
+3.1622776601683795,0.33073896765985067
+3.2359365692962845,0.30001085877265565
+3.311311214825911,0.2717868993679887
+3.3884415613920273,0.24590946055473728
+3.4673685045253166,0.2222222065638937
+3.548133892335757,0.20057213861840673
+3.630780547701014,0.1808111418829104
+3.715352290971728,0.1627971134749632
+3.801893963205613,0.14639474272317868
+3.890451449942805,0.13147600691793307
+3.981071705534973,0.11792043780014734
+4.073802778041126,0.10561520631196052
+4.168693834703355,0.09445506637430562
+4.265795188015925,0.08434218842823492
+4.365158322401661,0.07518591985591767
+4.46683592150963,0.0669024801004809
+4.570881896148752,0.05941462392160901
+4.677351412871981,0.052651278852465164
+4.786300923226385,0.04654717132351782
+4.897788193684462,0.041042450177595016
+5.011872336272725,0.03608231447503368
+5.1286138399136485,0.03161665073879001
+5.248074602497728,0.02759968336169212
+5.370317963702527,0.023989640752611285
+5.4954087385762485,0.020748438890715343
+5.623413251903491,0.017841383222031076
+5.754399373371572,0.015236889272652085
+5.88843655355589,0.012906222397068033
+6.025595860743581,0.010823254956532496
+6.165950018614822,0.008964242366169245
+6.309573444801936,0.007307615804793943
+6.456542290346556,0.005833791061548826
+6.606934480075965,0.00452499289763255
+6.760829753919819,0.0033650937774889512
+6.918309709189362,0.0023394660623455438
+7.07945784384138,0.0014348467335104677
+7.244359600749899,0.000639213729661376
+7.413102413009177,-0.000058326976016626064
+7.585775750291836,-0.0006676444006787977
+7.76247116628692,-0.0011976764663392293
+7.943282347242813,-0.0016565155523841427
+8.128305161640995,-0.002051486382180362
+8.317637711026709,-0.0023892168774385728
+8.511380382023768,-0.0026757027696100513
+8.709635899560805,-0.002916365658266293
+8.91250938133746,-0.003116107193779888
+9.120108393559097,-0.0032793566164883645
+9.332543007969914,-0.003410115109115852
+9.549925860214358,-0.0035119956327088284
+9.772372209558112,-0.0035882591704412947
+10.,-0.0036418476266676762
+10.232929922807536,-0.003675413693271982
+10.471285480509007,-0.0036913479560415803
+10.71519305237607,-0.0036918034974432797
+10.964781961431852,-0.003678718219097746
+11.220184543019629,-0.003653835097076766
+11.481536214968841,-0.003618720576410042
+11.748975549395302,-0.003574781236582213
+12.02264434617413,-0.0035232789310222007
+12.30268770812381,-0.0034653445201286793
+12.589254117941662,-0.0034019903207767174
+12.88249551693135,-0.003334121721124237
+13.182567385564074,-0.0032625458992330495
+13.489628825916533,-0.0031879841861516397
+13.803842646028839,-0.0031110788965242287
+14.125375446227554,-0.0030323952395725166
+14.45439770745928,-0.002952442501717452
+14.791083881682072,-0.002871665795627221
+15.135612484362072,-0.002790459041872528
+15.488166189124827,-0.002709168700643478
+15.848931924611142,-0.002628098456823055
+16.218100973589298,-0.0025475127179695693
+16.595869074375596,-0.00246764429719765
+16.98243652461746,-0.002388690255597498
+17.378008287493763,-0.0023108227486949426
+17.78279410038923,-0.0022341880207764394
+18.197008586099827,-0.002158909824011138
+18.620871366628695,-0.002085091806160589
+19.054607179632484,-0.0020128193615579154
+19.498445997580454,-0.0019421621360462223
+19.952623149688787,-0.0018731752036528371
+20.417379446695318,-0.0018059009211766255
+20.892961308540407,-0.0013308082040773485
+21.379620895022324,-0.001676584852437689
+21.87761623949552,-0.0016146149440695306
+22.387211385683422,-0.0015543259921876802
+22.90867652767775,-0.0014959773708670835
+23.442288153199225,0.
+23.9883291901949,0.
+24.547089156850287,0.
+25.11886431509582,0.
+25.703957827688647,0.
+26.302679918953814,0.
+26.91534803926914,0.
+27.54228703338169,0.
+28.18382931264455,0.
+28.84031503126606,0.
+29.51209226666384,0.
+30.199517204020193,0.
+30.90295432513592,0.
+31.622776601683793,0.
+32.35936569296281,0.
+33.11311214825915,0.
+33.884415613920275,0.
+34.673685045253166,-0.0007216069921754371
+35.481338923357534,-0.0006896800410453272
+36.30780547701018,-0.0006632197489486493
+37.15352290971728,-0.0006355493001646175
+38.018939632056124,-0.0006089865590097829
+38.904514499428046,-0.0009944824744740066
+39.81071705534978,0.
+40.7380277804113,0.
+41.68693834703355,0.
+42.65795188015925,0.
+43.65158322401656,0.
+44.668359215096345,0.
+45.708818961487516,0.
+46.77351412871981,0.
+47.863009232263806,0.
+48.97788193684466,0.
+50.11872336272725,0.
+51.28613839913648,0.
+52.48074602497723,0.
+53.70317963702533,0.
+54.954087385762485,0.
+56.23413251903491,0.
+57.543993733715666,0.
+58.884365535558956,0.
+60.25595860743581,0.
+61.65950018614822,0.
+63.0957344480193,0.
+64.56542290346563,0.
+66.06934480075964,0.
+67.60829753919819,0.
+69.18309709189363,0.
+70.79457843841388,0.
+72.44359600749905,0.
+74.13102413009177,0.
+75.85775750291836,0.
+77.62471166286912,0.
+79.43282347242821,0.
+81.28305161640995,0.
+83.17637711026708,0.
+85.11380382023759,0.
+87.09635899560814,0.
+89.12509381337459,0.
+91.20108393559097,0.
+93.32543007969905,0.
+95.49925860214368,0.
+97.72372209558111,0.
+100.,0.
+102.32929922807536,0.
+104.71285480509006,0.
+107.1519305237607,0.
+109.64781961431851,0.
+112.2018454301963,0.
+114.81536214968841,0.
+117.48975549395303,0.
+120.22644346174131,0.
+123.02687708123811,0.
+125.89254117941688,0.
+128.82495516931348,0.
+131.82567385564073,0.
+134.89628825916532,0.
+138.03842646028838,0.
+141.25375446227554,0.
+144.5439770745928,0.
+147.91083881682073,0.
+151.3561248436207,0.
+154.88166189124829,0.
+158.48931924611142,0.
+162.18100973589299,0.
+165.95869074375597,0.
+169.8243652461746,0.
+173.78008287493762,0.
+177.82794100389228,0.
+181.97008586099827,0.
+186.20871366628694,0.
+190.54607179632484,0.
+194.98445997580455,0.
+199.52623149688787,0.
+204.17379446695315,0.
+208.92961308540407,0.
+213.79620895022325,0.
+218.77616239495518,0.
+223.87211385683423,0.
+229.08676527677747,0.
+234.42288153199226,0.
+239.88329190194898,0.
+245.47089156850285,0.
+251.18864315095823,0.
+257.03957827688646,0.
+263.02679918953817,0.
+269.1534803926914,0.
+275.4228703338169,0.
+281.8382931264455,0.
+288.40315031266056,0.
+295.1209226666384,0.
+301.9951720402019,0.
+309.0295432513592,0.
+316.22776601683796,0.
+323.5936569296281,0.
+331.1311214825914,0.
+338.84415613920277,0.
+346.73685045253166,0.
+354.8133892335753,0.
+363.07805477010174,0.
+371.53522909717276,0.
+380.1893963205613,0.
+389.04514499428046,0.
+398.1071705534977,0.
+407.380277804113,0.
+416.8693834703355,0.
+426.57951880159254,0.
+436.51583224016565,0.
+446.6835921509635,0.
+457.0881896148752,0.
+467.73514128719813,0.
+478.630092322638,0.
+489.77881936844665,0.
+501.18723362727246,0.
+512.8613839913648,0.
+524.8074602497722,0.
+537.0317963702532,0.
+549.5408738576248,0.
+562.341325190349,0.
+575.4399373371566,0.
+588.8436553555896,0.
+602.5595860743581,0.
+616.5950018614822,0.
+630.957344480193,0.
+645.6542290346563,0.
+660.6934480075964,0.
+676.0829753919819,0.
+691.8309709189363,0.
+707.9457843841387,0.
+724.4359600749906,0.
+741.3102413009177,0.
+758.5775750291835,0.
+776.2471166286912,0.
+794.3282347242822,0.
+812.8305161640995,0.
+831.7637711026708,0.
+851.1380382023759,0.
+870.9635899560815,0.
+891.2509381337459,0.
+912.0108393559096,0.
+933.2543007969905,0.
+954.9925860214369,0.
+977.2372209558112,0.
+1000.,0.
\ No newline at end of file
diff --git a/coco_example_runs/ch_4_linode_robust_optimization/rdo.m b/coco_example_runs/ch_4_linode_robust_optimization/rdo.m
index bf19efeafb0a4dc7b7113af97b343c9255d61b0c..f18830f375622e8680330d86a161a30af4b4b3ac 100644
--- a/coco_example_runs/ch_4_linode_robust_optimization/rdo.m
+++ b/coco_example_runs/ch_4_linode_robust_optimization/rdo.m
@@ -3,6 +3,6 @@ function [data, y] = rdo(prob, data, u)
 mean = u(1);
 var = u(2);
 
-y = mean - 3*var;
+y = mean - 3*sqrt(var);
 
 end
\ No newline at end of file
diff --git a/coco_example_runs/ch_4_linode_robust_optimization/rdo_dU.m b/coco_example_runs/ch_4_linode_robust_optimization/rdo_dU.m
index b8c446233cc44565aef9a85a68a104dd6e00717b..3126cfc1bbb8c1951c2bbe3204f4697109396c16 100644
--- a/coco_example_runs/ch_4_linode_robust_optimization/rdo_dU.m
+++ b/coco_example_runs/ch_4_linode_robust_optimization/rdo_dU.m
@@ -1,5 +1,6 @@
 function [data, J] = rdo_dU(prob, data, u)
 
-J = [1, -3];
+var = u(2);
+J = [1, -3*(1/2)*(var).^(-1/2)];
 
 end
\ No newline at end of file
diff --git a/coco_example_runs/ch_4_linode_robust_optimization/rdo_dUdU.m b/coco_example_runs/ch_4_linode_robust_optimization/rdo_dUdU.m
index a6611ff24215c72e466d07df60e68d8029cb0c3d..191c3985da69786784a3b8d5aa7e35fda0186748 100644
--- a/coco_example_runs/ch_4_linode_robust_optimization/rdo_dUdU.m
+++ b/coco_example_runs/ch_4_linode_robust_optimization/rdo_dUdU.m
@@ -1,5 +1,8 @@
 function [data, dJ] = rdo_dUdU(prob, data, u)
 
+var = u(2);
+
 dJ = zeros(1,2,2);
+dJ(1,2,2) = 3*(1/4)*(var.^(-3/2));
 
 end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_curve_build.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_curve_build.m
index db22f4344a43c77ab65aa5b6e8e00a4df2f517f3..35ccf71c80759b3017f862b71effa691a6735913 100644
--- a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_curve_build.m
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_curve_build.m
@@ -50,7 +50,7 @@ if not(coco_exist(run_name, 'run'))
   x0_coco = uidx(maps.x0_idx);
   prob = coco_add_pars(prob, 'R', x0_coco(1), 'R', 'inactive');
   prob = coco_add_pars(prob, 'v0', x0_coco(2), 'v0', 'inactive');
-  bvp_read_solution
+  
   prob = coco_add_event(prob, 'MAX', 'v0', 0);
   % Find point where velocity is zero so that R is the peak
   % of the trajectory.
@@ -219,6 +219,9 @@ if not(coco_exist(run_name, 'run'))
     prob = coco_add_pars(prob, Rname, om_x0{i}(1), Rname, 'inactive');
     prob = coco_add_pars(prob, v0name, om_x0{i}(2), v0name, 'inactive');
 
+    omname = ['OM', int2str(i), '.om'];
+    prob = coco_add_pars(prob, omname, om_uidx{1}(om_maps{1}.p_idx(6)), omname, 'inactive');    
+    
     % Glue Parameters together
     if i > 1
       % The fold approximants share all parameter values.
@@ -242,7 +245,6 @@ if not(coco_exist(run_name, 'run'))
         om_uidx{1}(om_maps{1}.p_idx(1:5)));
     end
   end
-  prob = coco_add_pars(prob, 'OM1.om', om_uidx{1}(om_maps{1}.p_idx(6)), 'OM1.om', 'inactive');
   
   bd = coco(prob, run_name, [], 1, {'OM1R.minus.OM2R', 'OM1.om', 'OM2R.minus.OM3R', 'om', 'pk2.om', 'PK1.R', 'PK2.R', 'OM1.R', 'OM2.R', 'OM3.R'}, [1e-4, 3]);
 else
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis.m
index ad652a061d845660bde4d52a71d29a3c541cd83b..b1666307cc0de74f87a498e98622a19d6040bb9e 100644
--- a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis.m
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis.m
@@ -14,17 +14,18 @@ demo_uq_nds
 % Sweep in robust objective function value with k and m
 % released in search of a Fold Point and corresponding
 % Branch Point
-demo_for_thesis_fpbp
+% demo_for_thesis_fpbp
+demo_for_thesis_fpbp2
 
 %% Eta 1 to zero
 % From the branch point, continue along the secondary
 % direction where the lagrange multipliers can take on
 % non-trivial value and drive d.obj to 1
-demo_for_thesis_dobj_to_1
+% demo_for_thesis_dobj_to_1
 
 %% Drive d.A to zero
 % Perform continuation in the Lagrange multiplier for the
 % response amplitude, A, until it equals zero and the
 % system is at an optimal point with respect to k, m, and
 % A.
-demo_for_thesis_dA_to_0
\ No newline at end of file
+% demo_for_thesis_dA_to_0
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_PCE_convergence.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_PCE_convergence.m
index 85b4f96f8fab46a976b6ed0c4c9fb983ec3935be..048dc7e93a6e9166ec1938e24226bdb46a10fe6a 100644
--- a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_PCE_convergence.m
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_PCE_convergence.m
@@ -10,8 +10,8 @@ demo_curve_build
 % Find integration nodes used in the PCE
 
 for M=1:6
-  for P=2:6
-uq_data = demo_uq_nds_func(M,P);
+  for Pt=2:6
+uq_data = demo_uq_nds_func(M,Pt);
 
 last_run_name = 'uq_nds_M_P_vary';
 run_name = 'pce_convergence';
@@ -406,7 +406,7 @@ end
 
 end
 
-psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.P, uq_data.spdists);
+psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.Pt, uq_data.spdists);
 uq_data.wtd_psi_mat = psi_mat*diag(uq_data.wts);
 uq_data.s_idx = s_idx;
 if add_adjt
@@ -570,7 +570,7 @@ if add_adjt
   bd = coco(prob, run_name, [], 1, ...
     {obj_id, 'k', 'm', dobj_id, mean_name, var_name, omnames{:}, adj_pars2free{:}});
 else
-  bd = coco(prob, ['pce_convergence_M_',int2str(M),'_P_',int2str(P)], [], 0, {obj_id, 'k', 'm', mean_name, var_name, omnames{:}, alnames{:}});
+  bd = coco(prob, ['pce_convergence_M_',int2str(M),'_P_',int2str(Pt)], [], 0, {obj_id, 'k', 'm', mean_name, var_name, omnames{:}, alnames{:}});
 end
 
 else
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_dA_to_0.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_dA_to_0.m
index 43d08d7deb98c8586c9c750c94b0bfbc53d4d0d3..da94ae362afc71461b7c526d58632fe74113f779 100644
--- a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_dA_to_0.m
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_dA_to_0.m
@@ -418,7 +418,7 @@ if not(coco_exist(run_name, 'run'))
 
   end
   
-  psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.P, uq_data.spdists);
+  psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.Pt, uq_data.spdists);
   uq_data.wtd_psi_mat = psi_mat*diag(uq_data.wts);
  
   uq_data.s_idx = s_idx;
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_dobj_to_1.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_dobj_to_1.m
index b7ebc4cf0f37945f82f1cfa9abc585aa0cfd7cbf..c637ac0cde7c95d6687583d1321b2b8b22295648 100644
--- a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_dobj_to_1.m
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_dobj_to_1.m
@@ -418,7 +418,7 @@ end
 
 end
 
-psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.P, uq_data.spdists);
+psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.Pt, uq_data.spdists);
 uq_data.wtd_psi_mat = psi_mat*diag(uq_data.wts);
 
 uq_data.s_idx = s_idx;
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_fpbp.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_fpbp.m
index 3f67fe25338e938d9b04c4e46718d96e687f1dd1..18e65886fbdce4ccbfb1644b517ae80d55c8936e 100644
--- a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_fpbp.m
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_fpbp.m
@@ -221,7 +221,7 @@ for lab=labs
       'aidx', [sj_pk2_aidx(sj_pk2_opt.p_idx(6)), ...
       sj_pk1_aidx(sj_pk1_opt.p_idx(6))]);
 
-  end     
+  end
 
 for i=1:2
   om_id = strcat('OM', int2str(i));
@@ -282,7 +282,6 @@ for i=1:2
       drdiffnames12{j} = drdiffname;
       prob = coco_add_adjt(prob, rdiffname, drdiffname, ...
         'aidx', [om_x0a{i-1}(1), om_x0a{i}(1)]);
-
     end
 
   else
@@ -320,7 +319,6 @@ for i=3:4
   om_x0{i} = om_uidx{i}(om_maps{i}.x0_idx);
   prob = coco_add_pars(prob, v0sname, om_x0{i}(2), v0sname, 'inactive');
   if add_adjt
-
     prob = adjt_isol2bvp(prob, om34_sname);
     [sj_om_fdata{i}, sj_om_aidx{i}] = coco_get_adjt_data(prob, ...
       om34_coll_sname, 'data', 'axidx');
@@ -391,7 +389,7 @@ end
 
 end
 
-psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.P, uq_data.spdists);
+psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.Pt, uq_data.spdists);
 uq_data.wtd_psi_mat = psi_mat*diag(uq_data.wts);
 uq_data.s_idx = s_idx;
 if add_adjt
@@ -426,10 +424,6 @@ if add_adjt
 end
 
 alpha_idx = coco_get_func_data(prob, response_id, 'uidx');
-
-% Grab the last Nt parameters. This will only work for single output
-% response function.  Leaving it for now, would like to generalize this to
-% multiple output response functions.
 alpha_idx = alpha_idx(end-uq_data.Nt+1:end);
 if add_adjt
   alpha_aidx = coco_get_adjt_data(prob, response_id, 'axidx');
@@ -456,8 +450,7 @@ prob = coco_add_pars(prob, mean_par_id, mean_idx(end), mean_name);
 if add_adjt  
 
   prob = coco_add_adjt(prob, mean_id, 'aidx', ...
-    alpha_aidx, ...
-    'l0', 0);
+    alpha_aidx, 'l0', 0);
 
   mean_aidx = coco_get_adjt_data(prob, mean_id, 'axidx');
   dmean_name = coco_get_id('d', mean_name);
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_fpbp2.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_fpbp2.m
new file mode 100644
index 0000000000000000000000000000000000000000..894da7e5ed8616e2df167e6d87581596de2cc65a
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_fpbp2.m
@@ -0,0 +1,556 @@
+last_run_name = 'uq_nds';
+run_name = 'uq_sweep2';
+add_adjt=1;
+
+prob = coco_prob();
+prob = coco_set(prob, 'coll', 'NTST', 30);
+prob = coco_set(prob, 'cont', 'PtMX', 120);
+
+bd = coco_bd_read(last_run_name);
+labs = coco_bd_labs(bd, 'UQ');
+
+j = 0;
+s_idx = cell(1, uq_data.nsamples);
+r_igs = cell(1, uq_data.nsamples);
+r_idx = cell(1, uq_data.nsamples);
+adj_s_idx = cell(1, uq_data.nsamples);
+r_aidx = cell(1, uq_data.nsamples);
+for lab=labs
+  j = j+1;
+  sample_id = strcat('s', int2str(j));
+  pk1_sname = coco_get_id(sample_id, 'PK1');
+  pk1_bvp_sname = coco_get_id(pk1_sname, 'bvp');
+  pk1_coll_sname = coco_get_id(pk1_bvp_sname, 'seg1.coll');
+  coll_name = 'PK1.bvp.seg1';
+  sol = coll_read_solution(coll_name, last_run_name, lab);
+
+  coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+
+  if j == 1
+    % bvp_args defined in demo_curve_build
+    % alpha is stochastic and om will vary between
+    % samples, so they're labeled with a sample integer
+    s_pnames = {pnames{1:3}, 'alpha.1', pnames{5}, 'om.1'};
+    prob = ode_isol2bvp(prob, pk1_sname, ...
+      coll_args{:}, {}, bvp_args{:});
+
+    [pk1_s1_data, pk1_s1_uidx, pk1_s1_u0] = ...
+      coco_get_func_data(prob, pk1_coll_sname, ...
+      'data', 'uidx', 'u0');
+    pk1_s1_maps = pk1_s1_data.coll_seg.maps;
+
+    si_par_fname = coco_get_id(sample_id, 'pars');
+    si_par_pname = s_pnames([1:3, 5, 6]);
+    si_par_idx = pk1_s1_uidx(pk1_s1_maps.p_idx([1:3, 5, 6]));
+    prob = coco_add_pars(prob, si_par_fname, ...
+      si_par_idx, si_par_pname);
+
+    s_idx{j} = pk1_s1_uidx(pk1_s1_maps.p_idx);
+    r_igs{j} = pk1_s1_u0(pk1_s1_maps.x0_idx(1));
+    r_idx{j} = pk1_s1_uidx(pk1_s1_maps.x0_idx(1));
+
+    % Adjoints
+    if add_adjt
+      prob = adjt_isol2bvp(prob, pk1_sname);
+      [s1_pk1_fdata, s1_pk1_aidx] = coco_get_adjt_data(prob, ...
+        pk1_coll_sname, 'data', 'axidx');
+      s1_pk1_opt = s1_pk1_fdata.coll_opt;
+
+      prob = coco_add_adjt(prob, si_par_fname, ...
+        coco_get_id('d', si_par_pname), ...
+        'aidx', s1_pk1_aidx(s1_pk1_opt.p_idx([1:3, 5, 6])), ...
+        'l0', zeros(5,1));
+      adj_s_idx{j} = s1_pk1_aidx(s1_pk1_opt.p_idx);
+      r_aidx{j} = s1_pk1_aidx(s1_pk1_opt.x0_idx(1));
+    end
+  else
+    % 'bvp'-toolbox arguments
+    prob = ode_isol2bvp(prob, pk1_sname, ...
+      coll_args{:}, {}, bvp_args{:});
+
+    % Glue deterministic parameters together
+    [pk1_sj_data, pk1_sj_uidx, pk1_sj_u0] = ...
+      coco_get_func_data(prob, pk1_coll_sname, ...
+                         'data', 'uidx', 'u0');
+    pk1_sj_maps = pk1_sj_data.coll_seg.maps;
+    s1_p_idx = pk1_s1_uidx(pk1_s1_maps.p_idx([1:3,5]));
+    si_p_idx = pk1_sj_uidx(pk1_sj_maps.p_idx([1:3,5]));
+
+    glue_name = coco_get_id(sample_id, 'glue_to_s1');
+    prob = coco_add_glue(prob, glue_name, s1_p_idx, ...
+      si_p_idx);
+
+    si_om_fname = coco_get_id(sample_id, 'om');
+    si_om_pname = coco_get_id('om', int2str(j));
+    si_om_idx = pk1_sj_uidx(pk1_sj_maps.p_idx(6));
+    prob = coco_add_pars(prob, si_om_fname, ...
+      si_om_idx, si_om_pname);
+    s_idx{j} = pk1_sj_uidx(pk1_sj_maps.p_idx);
+    r_igs{j} = pk1_sj_u0(pk1_sj_maps.x0_idx(1));
+    r_idx{j} = pk1_sj_uidx(pk1_sj_maps.x0_idx(1));
+
+    % Adjoints
+    if add_adjt
+      % For ode
+      prob = adjt_isol2bvp(prob, pk1_sname);
+      [sj_pk1_fdata, sj_pk1_aidx] = coco_get_adjt_data(prob, ...
+        pk1_coll_sname, 'data', 'axidx');
+      sj_pk1_opt = sj_pk1_fdata.coll_opt;
+
+      % For glue
+      s1_p_aidx = s1_pk1_aidx(s1_pk1_opt.p_idx([1:3,5]));
+      si_p_aidx = sj_pk1_aidx(sj_pk1_opt.p_idx([1:3,5]));
+      prob = coco_add_adjt(prob, glue_name, ...
+        'aidx', [s1_p_aidx; si_p_aidx]);
+
+      % For frequency
+      prob = coco_add_adjt(prob, si_om_fname, ...
+        coco_get_id('d', si_om_pname), ...
+        'aidx', sj_pk1_aidx(sj_pk1_opt.p_idx(6)), ...
+        'l0', 0);
+      adj_s_idx{j} = sj_pk1_aidx(sj_pk1_opt.p_idx);
+      r_aidx{j} = sj_pk1_aidx(sj_pk1_opt.x0_idx(1));
+    end
+  end
+
+  [pk1_data, pk1_uidx] = coco_get_func_data(prob, pk1_coll_sname, 'data', 'uidx');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+  % Parameterize Amplitude Peak (Is this necessary?)
+  pk1_r_sname = coco_get_id(pk1_sname, 'R');
+  prob = coco_add_pars(prob, pk1_r_sname, pk1_x0(1), ...
+    pk1_r_sname, 'active');
+
+  % Adjoint
+  if add_adjt
+    [sj_pk1_fdata, sj_pk1_aidx] = coco_get_adjt_data(prob, ...
+      pk1_coll_sname, 'data', 'axidx');
+    sj_pk1_opt = sj_pk1_fdata.coll_opt;
+
+    prob = coco_add_adjt(prob, pk1_r_sname, ...
+      coco_get_id('d', pk1_r_sname), ...
+      'aidx', sj_pk1_aidx(sj_pk1_opt.x0_idx(1)), ...
+      'l0', 0);
+  end
+
+  % Maintain velocity constraint (could also be done with a
+  % boundary condition)
+  pk1_v0_sname = coco_get_id(pk1_sname, 'v0');
+  prob = coco_add_pars(prob, pk1_v0_sname, pk1_x0(2), ...
+    pk1_v0_sname, 'inactive');
+
+  % Adjoint
+  if add_adjt
+    dv10_sname = coco_get_id('d', pk1_v0_sname);
+    prob = coco_add_adjt(prob, pk1_v0_sname, ...
+      dv10_sname, ...
+      'aidx', sj_pk1_aidx(sj_pk1_opt.x0_idx(2)), ...
+      'l0', 0);
+  end
+
+  pk2_sname = coco_get_id(sample_id, ...
+    'PK2');
+  pk2_coll_sname = coco_get_id(pk2_sname, 'bvp', 'seg1', 'coll');
+
+  coll_name = 'PK2';
+  sol = coll_read_solution(coll_name, last_run_name, lab);
+
+  coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+  prob = ode_isol2bvp(prob, pk2_sname, ...
+    coll_args{:}, {}, bvp_args{:});
+
+  [pk2_data, pk2_uidx] = coco_get_func_data(prob, ...
+    pk2_coll_sname, 'data', 'uidx');
+  pk2_maps = pk2_data.coll_seg.maps;
+  pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+
+  % Maintain velocity constraint (could also be done with a
+  % boundary condition)
+  pk2_v0_sname = coco_get_id(pk2_sname, 'v0');
+  prob = coco_add_pars(prob, pk2_v0_sname, pk2_x0(2), ...
+    pk2_v0_sname, 'inactive');
+
+  % Glue Parameters together (except forcing frequency)
+  parglue_sname = coco_get_id(sample_id, ...
+    'par_glue_PK2_to_PK1');
+  prob = coco_add_glue(prob, parglue_sname, ...
+    pk2_uidx(pk2_maps.p_idx(1:5)), ...
+    pk1_uidx(pk1_maps.p_idx(1:5)));
+
+  pk_r_glue_sname = coco_get_id(sample_id, ...
+    'R_glue_to_PK1');
+  prob = coco_add_glue(prob, pk_r_glue_sname, ...
+    pk2_x0(1), pk1_x0(1));
+
+  % Lock in the frequency difference
+  pk_om_diff_sname = coco_get_id(sample_id, ...
+    'PK_om_diff');
+  prob = coco_add_func(prob, pk_om_diff_sname, ...
+    @udiff, @udiff_dU, @udiff_dUdU, [], ...
+    'inactive', pk_om_diff_sname, 'uidx', ...
+    [pk2_uidx(pk2_maps.p_idx(6)), ...
+     pk1_uidx(pk1_maps.p_idx(6))]);
+
+  % Adjoints
+  if add_adjt
+    % ode
+    prob = adjt_isol2bvp(prob, pk2_sname);
+    [sj_pk2_fdata, sj_pk2_aidx] = coco_get_adjt_data(prob, ...
+      pk2_coll_sname, 'data', 'axidx');
+    sj_pk2_opt = sj_pk2_fdata.coll_opt;
+
+    % velocity constraint
+    dv20_sname = coco_get_id('d', pk2_v0_sname);
+    prob = coco_add_adjt(prob, pk2_v0_sname, ...
+      dv20_sname, ...
+      'aidx', sj_pk2_aidx(sj_pk2_opt.x0_idx(2)));
+
+    % glue
+    prob = coco_add_adjt(prob, parglue_sname, ...
+      'aidx', [sj_pk2_aidx(sj_pk2_opt.p_idx(1:5)); ...
+      sj_pk1_aidx(sj_pk1_opt.p_idx(1:5))]);
+
+    prob = coco_add_adjt(prob, pk_r_glue_sname, ...
+      'aidx', [sj_pk2_aidx(sj_pk2_opt.x0_idx(1)); ...
+      sj_pk1_aidx(sj_pk1_opt.x0_idx(1))]);
+
+    % om constraint
+    prob = coco_add_adjt(prob, pk_om_diff_sname, ...
+      coco_get_id('d', pk_om_diff_sname), ...
+      'aidx', [sj_pk2_aidx(sj_pk2_opt.p_idx(6)), ...
+      sj_pk1_aidx(sj_pk1_opt.p_idx(6))]);
+
+  end
+
+for i=1:2
+  om_id = strcat('OM', int2str(i));
+  om12_sname = coco_get_id(sample_id, om_id);
+
+  om12_coll_sname = coco_get_id(om12_sname, 'bvp', 'seg1', 'coll');
+
+  sol = coll_read_solution(om_id, last_run_name, lab);
+
+  coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+  prob = ode_isol2bvp(prob, om12_sname, ...
+    coll_args{:}, {}, bvp_args{:});    
+
+  [om_data{i}, om_uidx{i}] = coco_get_func_data(prob, ...
+    om12_coll_sname, 'data', 'uidx');
+  om_maps{i} = om_data{i}.coll_seg.maps;
+
+  % Maintain velocity constraint
+  v0sname = coco_get_id(sample_id, ['OM', int2str(i)],'v0');
+  om_x0{i} = om_uidx{i}(om_maps{i}.x0_idx);
+  prob = coco_add_pars(prob, v0sname, om_x0{i}(2), v0sname, 'inactive');
+  if add_adjt
+
+    prob = adjt_isol2bvp(prob, om12_sname);
+    [sj_om_fdata{i}, sj_om_aidx{i}] = coco_get_adjt_data(prob, ...
+      om12_coll_sname, 'data', 'axidx');
+    sj_om_opt{i} = sj_om_fdata{i}.coll_opt;    
+
+    om_x0a{i} = sj_om_aidx{i}(sj_om_opt{i}.x0_idx);
+    dv0sname = coco_get_id('d', v0sname);
+    prob = coco_add_adjt(prob, v0sname, dv0sname, ...
+      'aidx', om_x0a{i}(2));
+  end
+
+  % Glue Parameters together
+  if i > 1
+    % The fold approximants share all parameter values.
+    % They differ only in response amplitude 
+
+    gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+      int2str(i), '_to_OM1']);
+    prob = coco_add_glue(prob, gluename, ...
+      om_uidx{1}(om_maps{1}.p_idx), ...
+      om_uidx{i}(om_maps{i}.p_idx));
+
+    % Parameterize Response Amplitude Difference
+    rdiffname = ['OM', int2str(i-1), 'R_minus_OM', int2str(i), 'R'];
+    rdiffname = coco_get_id(sample_id, rdiffname);
+    prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+      [], 'inactive', rdiffname, 'uidx', [om_x0{i-1}(1), om_x0{i}(1)]);
+
+    if add_adjt
+      prob = coco_add_adjt(prob, gluename, ...
+        'aidx', [sj_om_aidx{1}(sj_om_opt{1}.p_idx), ...
+        sj_om_aidx{i}(sj_om_opt{i}.p_idx)]);
+
+      drdiffname = coco_get_id('d', rdiffname);
+      drdiffnames12{j} = drdiffname;
+      prob = coco_add_adjt(prob, rdiffname, drdiffname, ...
+        'aidx', [om_x0a{i-1}(1), om_x0a{i}(1)]);
+    end
+
+  else
+    gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+      int2str(i), '_to_PK1']);
+    prob = coco_add_glue(prob, gluename, ...
+      pk2_uidx(pk2_maps.p_idx(1:5)), ...
+      om_uidx{1}(om_maps{1}.p_idx(1:5)));
+    if add_adjt
+      prob = coco_add_adjt(prob, gluename, ...
+        'aidx', [sj_pk1_aidx(sj_pk1_opt.p_idx(1:5)), ...
+        sj_om_aidx{1}(sj_om_opt{1}.p_idx(1:5))]);
+    end
+  end
+end
+
+for i=3:4
+  om_id = strcat('OM', int2str(i));
+  om34_sname = coco_get_id(sample_id, om_id);
+
+  om34_coll_sname = coco_get_id(om34_sname, 'bvp', 'seg1', 'coll');
+
+  sol = coll_read_solution(om_id, last_run_name, lab);
+
+  coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+  prob = ode_isol2bvp(prob, om34_sname, ...
+    coll_args{:}, {}, bvp_args{:});  
+
+  [om_data{i}, om_uidx{i}] = coco_get_func_data(prob, ...
+    om34_coll_sname, 'data', 'uidx');
+  om_maps{i} = om_data{i}.coll_seg.maps;
+
+  % Maintain velocity constraint
+  v0sname = coco_get_id(sample_id, ['OM', int2str(i)],'v0');
+  om_x0{i} = om_uidx{i}(om_maps{i}.x0_idx);
+  prob = coco_add_pars(prob, v0sname, om_x0{i}(2), v0sname, 'inactive');
+  if add_adjt
+    prob = adjt_isol2bvp(prob, om34_sname);
+    [sj_om_fdata{i}, sj_om_aidx{i}] = coco_get_adjt_data(prob, ...
+      om34_coll_sname, 'data', 'axidx');
+    sj_om_opt{i} = sj_om_fdata{i}.coll_opt;    
+
+    om_x0a{i} = sj_om_aidx{i}(sj_om_opt{i}.x0_idx);
+    dv0sname = coco_get_id('d', v0sname);
+    prob = coco_add_adjt(prob, v0sname, dv0sname, ...
+      'aidx', om_x0a{i}(2));
+  end
+
+  % Glue Parameters together
+  if i == 4
+    gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+      int2str(i), '_to_OM1']);
+    prob = coco_add_glue(prob, gluename, ...
+      om_uidx{i-1}(om_maps{i-1}.p_idx), ...
+      om_uidx{i}(om_maps{i}.p_idx));
+
+    % Parameterize Response Amplitude Difference
+    rdiffname = ['OM', int2str(i-1), 'R_minus_OM', int2str(i), 'R'];
+    rdiffname = coco_get_id(sample_id, rdiffname);      
+    prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+      [], 'inactive', rdiffname, 'uidx', [om_x0{i-1}(1), om_x0{i}(1)]);
+    if add_adjt
+      prob = coco_add_adjt(prob, gluename, ...
+        'aidx', [sj_om_aidx{i-1}(sj_om_opt{i-1}.p_idx), ...
+        sj_om_aidx{i}(sj_om_opt{i}.p_idx)]);
+
+      drdiffname = coco_get_id('d', rdiffname);
+      drdiffnames34{j} = drdiffname;
+      prob = coco_add_adjt(prob, rdiffname, drdiffname, ...
+        'aidx', [om_x0a{i-1}(1), om_x0a{i}(1)]);
+
+    end      
+  else
+    gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+      int2str(i), '_to_PK1']);
+    prob = coco_add_glue(prob, gluename, ...
+      pk1_uidx(pk1_maps.p_idx(1:5)), ...
+      om_uidx{i}(om_maps{i}.p_idx(1:5)));
+    if add_adjt
+      prob = coco_add_adjt(prob, gluename, ...
+        'aidx', [sj_pk1_aidx(sj_pk1_opt.p_idx(1:5)), ...
+        sj_om_aidx{i}(sj_om_opt{i}.p_idx(1:5))]);
+    end      
+  end
+end
+
+hyst_fname = coco_get_id(sample_id, 'hyst');
+hyst_pname = coco_get_id('hyst', int2str(j));
+
+prob = coco_add_func(prob, hyst_fname, @udiff, ...
+  @udiff_dU, @udiff_dUdU, [], 'active', hyst_pname, ...
+  'uidx', [om_uidx{1}(om_maps{1}.p_idx(6)), ...
+           om_uidx{3}(om_maps{3}.p_idx(6))]);
+
+[hyst_idx{j}, oms{j}] = coco_get_func_data(prob, hyst_fname, 'uidx', 'u0');
+
+if add_adjt
+  dhyst_pname = coco_get_id('d', hyst_pname);
+  prob = coco_add_adjt(prob, hyst_fname, dhyst_pname, ...
+    'aidx', [sj_om_aidx{1}(sj_om_opt{1}.p_idx(6)), ...
+    sj_om_aidx{3}(sj_om_opt{3}.p_idx(6))]);
+
+  hyst_aidx{j} = coco_get_adjt_data(prob, hyst_fname, 'axidx');
+end
+
+end
+
+psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.Pt, uq_data.spdists);
+uq_data.wtd_psi_mat = psi_mat*diag(uq_data.wts);
+uq_data.s_idx = s_idx;
+if add_adjt
+  uq_data.adj_s_idx = adj_s_idx;
+end
+uq_data.addadjt=add_adjt;
+[prob, uq_data] = uq_add_sample_nodes(prob, uq_data);
+
+igs = zeros(uq_data.nsamples,1);
+idx = zeros(1, uq_data.nsamples);
+for i=1:uq_data.nsamples
+  omi = oms{i};
+  igs(i) = r_igs{i};
+  idx(:,i) = [r_idx{i}];
+end
+
+alpha_ig = uq_data.wtd_psi_mat*igs;
+response_id = 'resp';
+prob = coco_add_func(prob, response_id, ...
+  @resp_pce2, @resp_pce2_dU, @resp_pce2_dUdU, ...
+  uq_data, 'zero', 'uidx', idx(:), 'u0', alpha_ig);
+
+if add_adjt
+  aidx = zeros(1, uq_data.nsamples);
+  for i=1:uq_data.nsamples
+    aidx(:,i) = [r_aidx{i}];
+  end
+
+  prob = coco_add_adjt(prob, response_id, ...
+    'aidx', aidx(:), 'l0', zeros(size(alpha_ig)), ...
+    'tl0', zeros(size(alpha_ig)));
+end
+
+alpha_idx = coco_get_func_data(prob, response_id, 'uidx');
+alpha_idx = alpha_idx(end-uq_data.Nt+1:end);
+if add_adjt
+  alpha_aidx = coco_get_adjt_data(prob, response_id, 'axidx');
+  alpha_aidx = alpha_aidx(end-uq_data.Nt+1:end);
+end
+
+% Calculate statistics from the PCE
+% Add zero functions for the mean and variance along with
+% inactive continuation parameters for tracking their
+% values.
+
+% Mean Zero Function
+mean_id = coco_get_id(response_id, 'pce_mean');
+prob = coco_add_func(prob, mean_id, ...
+  @uq_pce_mean, @uq_pce_mean_dU, @uq_pce_mean_dUdU, ...
+  uq_data, 'zero', 'uidx', alpha_idx, 'u0', alpha_ig(1));
+
+% Mean Continuation Parameter
+mean_par_id = coco_get_id(response_id, 'mean');
+mean_idx = coco_get_func_data(prob, mean_id, 'uidx');
+mean_name = coco_get_id(response_id, 'mean');
+prob = coco_add_pars(prob, mean_par_id, mean_idx(end), mean_name);
+
+if add_adjt  
+
+  prob = coco_add_adjt(prob, mean_id, 'aidx', ...
+    alpha_aidx, 'l0', 0);
+
+  mean_aidx = coco_get_adjt_data(prob, mean_id, 'axidx');
+  dmean_name = coco_get_id('d', mean_name);
+  prob = coco_add_adjt(prob, mean_par_id, dmean_name, ...
+    'aidx', mean_aidx(end), ...
+    'l0', 0);
+end
+
+% Variance Zero Function
+var_id = coco_get_id(response_id, 'pce_variance');
+prob = coco_add_func(prob, var_id, ...
+  @uq_pce_variance, @uq_pce_variance_dU, @uq_pce_variance_dUdU,...
+  uq_data, 'zero', 'uidx', alpha_idx, 'u0', sum(alpha_ig(2:end).^2));
+
+% Variance Parameter
+var_par_id = coco_get_id(response_id, 'variance');
+var_idx = coco_get_func_data(prob, var_id, 'uidx');
+var_name = coco_get_id(response_id, 'var');
+prob = coco_add_pars(prob, var_par_id, var_idx(end), var_name);
+
+if add_adjt
+  prob = coco_add_adjt(prob, var_id, 'aidx', ...
+    alpha_aidx, ...
+    'l0', 0);
+
+  var_aidx = coco_get_adjt_data(prob, var_id, 'axidx');
+  dvar_name = coco_get_id('d', var_name);
+  prob = coco_add_adjt(prob, var_par_id, dvar_name, ...
+    'aidx', var_aidx(end), ...
+    'l0', 0);
+end
+
+obj_id = 'obj';
+mean_idx = coco_get_func_data(prob, mean_id, 'uidx');
+var_idx = coco_get_func_data(prob, var_id, 'uidx');
+
+prob = coco_add_func(prob, obj_id, ...
+  @obj, @obj_du, @obj_dudu, [], ...
+  'inactive', obj_id, 'uidx', ...
+  [mean_idx(end); var_idx(end)]);
+
+if add_adjt
+  dobj_id = coco_get_id('d', obj_id);
+  prob = coco_add_adjt(prob, obj_id, dobj_id, ...
+    'aidx', [mean_aidx(end); var_aidx(end)]);
+end
+
+[uidx, data] = coco_get_func_data(prob, 's1.PK1.bvp.seg1.coll', 'uidx', 'data');
+mk_idx = uidx(data.coll_seg.maps.p_idx([1,3]));
+
+prob = coco_add_func(prob, 'km_constraint', ...
+  @km_const, @km_const_du, @km_const_dudu, [], ...
+  'zero', 'uidx', mk_idx);
+
+if add_adjt
+  [aidx, fdata] = coco_get_adjt_data(prob, ...
+    's1.PK1.bvp.seg1.coll', 'axidx', 'data');
+  mk_aidx = aidx(fdata.coll_opt.p_idx([1,3]));
+
+  prob = coco_add_adjt(prob, 'km_constraint', 'aidx', ...
+    mk_aidx);
+end   
+
+dnames = coco_get_id('d', s_pnames([1:3,5]));
+alnames = uq_get_sample_par_names('alpha', 1:uq_data.nsamples);
+dalnames = coco_get_id('d', alnames);
+omnames = uq_get_sample_par_names('om', 1:uq_data.nsamples);
+domnames = coco_get_id('d', omnames);
+hyst_names = uq_get_sample_par_names('hyst', 1:uq_data.nsamples);
+pk1_ids = cell(1,uq_data.nsamples);
+pk2_ids = cell(1,uq_data.nsamples);
+om1_ids = cell(1,uq_data.nsamples);
+om2_ids = cell(1,uq_data.nsamples);
+om3_ids = cell(1,uq_data.nsamples);
+om4_ids = cell(1,uq_data.nsamples);
+
+for i=1:uq_data.nsamples
+  pk1_ids{i} = coco_get_id(['s', int2str(i)], 'PK1', 'v0');
+  pk2_ids{i} = coco_get_id(['s', int2str(i)], 'PK2', 'v0');
+  om1_ids{i} = coco_get_id(['s', int2str(i)], 'OM1', 'v0');
+  om2_ids{i} = coco_get_id(['s', int2str(i)], 'OM2', 'v0');
+  om3_ids{i} = coco_get_id(['s', int2str(i)], 'OM3', 'v0');
+  om4_ids{i} = coco_get_id(['s', int2str(i)], 'OM4', 'v0');    
+end
+
+dv10_snames = coco_get_id('d', pk1_ids);
+dv20_snames = coco_get_id('d', pk2_ids);
+dv30_snames = coco_get_id('d', om1_ids);
+dv40_snames = coco_get_id('d', om2_ids);
+dv50_snames = coco_get_id('d', om3_ids);
+dv60_snames = coco_get_id('d', om4_ids);
+if not(coco_exist(run_name, 'run'))
+if add_adjt
+  adj_pars2free = {dnames{[2,4]}, domnames{:}, dv10_snames{:}, dv20_snames{:}, dv30_snames{:}, dv40_snames{:}, drdiffnames12{:}, dv50_snames{:}, dv60_snames{:},  drdiffnames34{:}, 'd.lo.alpha', 'd.up.alpha'};
+  bd = coco(prob, run_name, [], 1, ...
+    {obj_id, 'k', 'm', dobj_id, mean_name, var_name, omnames{:}, adj_pars2free{:}});
+else
+  bd = coco(prob, 'uq_sweep_no_adjt_for_plot', [], 1, {obj_id, 'k', 'm', mean_name, var_name, omnames{:}, alnames{:}});
+end
+
+else
+bd = coco_bd_read(run_name);
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_km_srch.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_km_srch.m
index f6f46d9071a6d065cc7d2dad28654c3e9743f9e4..ecb1a040ff274d8b598cf13bf646fe8c5e4919a0 100644
--- a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_km_srch.m
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_for_thesis_km_srch.m
@@ -418,7 +418,7 @@ if not(coco_exist(run_name, 'run')) || true
 
   end
   
-  psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.P, uq_data.spdists);
+  psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.Pt, uq_data.spdists);
   uq_data.wtd_psi_mat = psi_mat*diag(uq_data.wts);
  
   uq_data.s_idx = s_idx;
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_uq_nds.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_uq_nds.m
index 3313a04cd87a72db16637349370aba6c8cd0ed9b..5387139621de584b42bcd74b9e162a6938dbd987 100644
--- a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_uq_nds.m
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_uq_nds.m
@@ -169,7 +169,7 @@ opts.addadjt = 1;
 %% Initialize UQ Data Structure
 bvp_id = coco_get_id('PK1', 'bvp');
 bc_data = coco_get_func_data(prob, bvp_id, 'data');  
-uq_data = bvp_uq_init_data(prob, bc_data, 'PK1');
+uq_data = bvp_uq_init_data(bc_data, 'PK1');
 % Calculates Integration nodes and weights for the
 % continuation problem.
 uq_data = uq_init_data(prob, uq_data, args, opts);
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_uq_nds_func.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_uq_nds_func.m
index ebeb98e2e3b287d21c9ad0268770601009fd4cb7..d5755266b378e6d32aba9e7aa40085c9d23ac2b7 100644
--- a/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_uq_nds_func.m
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/demo_uq_nds_func.m
@@ -1,4 +1,4 @@
-function uq_data = demo_uq_nds_func(M,P)
+function uq_data = demo_uq_nds_func(M,Pt)
 last_run_name = 'fold_find_btm';
 run_name = 'uq_nds_M_P_vary';
 bd = coco_bd_read(last_run_name);
@@ -173,7 +173,7 @@ uq_data = bvp_uq_init_data(prob, bc_data, 'PK1');
 % Calculates Integration nodes and weights for the
 % continuation problem.
 
-prob = coco_set(prob, 'uq', 'M', M, 'P', P);
+prob = coco_set(prob, 'uq', 'M', M, 'Pt', Pt);
 uq_data = uq_init_data(prob, uq_data, args, opts);
 
 % Mark the integration node locations with the label 'UQ'
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/resp_pce2.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/resp_pce2.m
new file mode 100644
index 0000000000000000000000000000000000000000..5525de924cb77659c7c6042971819b26dfdd167e
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/resp_pce2.m
@@ -0,0 +1,13 @@
+function [data, y] = resp_pce(prob, data, u)
+%UQ_PCE_COEFFICIENTS Summary of this function goes here
+%   Evaluate Response function and calculate coefficients of polynomial
+%   chaos expansion.
+
+r = u(1:end-data.Nt);
+
+alphas = u(end-data.Nt+1:end);
+R = data.wtd_psi_mat*r;
+
+y = alphas - R;
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/resp_pce2_dU.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/resp_pce2_dU.m
new file mode 100644
index 0000000000000000000000000000000000000000..89d00f7508cf73a92d2a4170a04cfbee0a5ad557
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/resp_pce2_dU.m
@@ -0,0 +1,17 @@
+function [data, J] = resp_pce_dU(prob, data, u)
+% UQ_PCE_COEFFICIENTS_DU Jacobian of the Polynomial Chaos
+% Expansion (PCE) coefficient Evaluation function
+
+r = u(1:end-data.Nt);
+
+dr = -data.wtd_psi_mat*eye(numel(r));
+
+J = [dr, ...         % dr/du
+     eye(data.Nt)];  % alphas are linear
+
+%% Test Jacobian with following sequence:
+% [data, Jd] = coco_ezDFDX('f(o,d,x)', prob, data, @resp_pce, u);
+% diff_J = abs(J-Jd);
+% max(max(diff_J))
+% fprintf('test')
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff/resp_pce2_dUdU.m b/coco_example_runs/ch_5_duff_robust_optimization/duff/resp_pce2_dUdU.m
new file mode 100644
index 0000000000000000000000000000000000000000..e0dc549b2b788831768beb41fb390a343ee8d526
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff/resp_pce2_dUdU.m
@@ -0,0 +1,12 @@
+function [data, dJ] = resp_pce_dUdU(prob, data, u)
+% UQ_PCE_COEFFICIENTS_DU Jacobian of the Polynomial Chaos
+% Expansion (PCE) coefficient Evaluation function
+
+dJ = zeros(data.Nt, numel(u), numel(u));
+   
+%% Test Jacobian with following sequence:
+% [data, dJd] = coco_ezDFDX('f(o,d,x)', prob, data, @resp_pce_dU, u);
+% diff_dJ = abs(dJ-dJd);
+% max(max(diff_dJ))
+% fprintf('test')
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/add_bcs.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/add_bcs.m
new file mode 100644
index 0000000000000000000000000000000000000000..f4e2334ebacc3b9b06a571110645a08b5e1c450a
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/add_bcs.m
@@ -0,0 +1,24 @@
+function [data, y, J] = add_bcs(prob, data, u)
+
+% coco compatible function to add in boundary conditions
+% that are in the form required by the bvp toolbox (doesn't
+% support updating boundary conditions)
+
+bc = data.bvp_bc;
+
+T0 = u(bc.T0_idx);
+T  = u(bc.T_idx);
+x0 = u(bc.x0_idx);
+x1 = u(bc.x1_idx);
+p  = u(bc.p_idx);
+
+args = {T0, T, x0, x1, p};
+
+y  = pr.fhan(pr.bc_data, args{bc.nargs+1:end});
+
+if nargout>=3
+  J  = [zeros(numel(y), bc.nargs*numel(T0)) ...
+    pr.dfdxhan(pr.bc_data, args{bc.nargs+1:end})];
+end
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures.m
new file mode 100644
index 0000000000000000000000000000000000000000..ba1b23094ae6dd05c9329a1d3feda5f15d8008a1
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures.m
@@ -0,0 +1,37 @@
+addpath('../../utils');
+
+img_path = ['/Users/jcoleanderson/Google Drive/',...
+ 'Grad School/00_Thesis Research/00_Document/Images/'];
+
+%% Duffing Hysteresis
+%  Plot the frequency sweep.  The unstable segment plotted
+%  with dashed lines, the stable segments with solid lines,
+%  the hysteresis transitions shown with arrows.  The
+%  forward sweep plotted with a red line, the reverse sweep
+%  plotted with a blue segment.  Remove axis numbers.
+ch_5_thesis_figures_duff_hysteresis
+
+%% Duffing Multiple Orbits
+%  Plot the frequency sweep showing the actual fold points
+%  and the approximate fold points.  Show the
+%  approximations as insets of the larger figure.
+font_size = 20;
+marker_size_1 = 10;
+marker_size_2 = 7;
+
+ch_5_thesis_figures_curve_build_stage_1
+ch_5_thesis_figures_curve_build_stage_2
+ch_5_thesis_figures_curve_build_stage_3
+ch_5_thesis_figures_curve_build_stage_4
+ch_5_thesis_figures_curve_build_stage_5
+ch_5_thesis_figures_curve_build_stage_6
+ch_5_thesis_figures_curve_build_stage_7
+
+%% Duffing Optimal Continuation Run
+ch_5_thesis_figures_optimal_run
+
+%% Sigma Level Study
+ch_5_thesis_figures_sigma_level_study
+
+%% Convergence plots:
+ch_5_thesis_figures_moment_convergence
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_1.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_1.m
new file mode 100644
index 0000000000000000000000000000000000000000..8b563b7c6da157c0309a2fe8d0ded2c30f5f3c47
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_1.m
@@ -0,0 +1,27 @@
+figure2 = figure(2);
+clf
+
+figname = 'curve_build_initial_phase.eps';
+fp = strcat(img_path, figname);
+
+xlim([0, 2*pi])
+hold on; grid on; box on;
+[sol, ~] = coll_read_solution('bvp.seg1', 'set_v0', 1);
+pos = plot(sol.tbp, sol.xbp(:,1), 'k', 'DisplayName','Position', 'LineWidth', 1);
+vel = plot(sol.tbp, sol.xbp(:,2), 'k--', 'DisplayName','Velocity', 'LineWidth', 1);
+
+lgd = legend([pos, vel]);
+lgd.Interpreter = 'latex';
+lgd.Location = 'southeast';
+
+xlim([0, 2*pi])
+xlabel('Time, $t$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+
+ax = gca;
+ax.XTick = [0,pi/2, pi, 3*pi/2, 2*pi];
+ax.TickLabelInterpreter = 'latex';
+ax.XTickLabel = {'$0$', '$\frac{\pi}{2}$', '$\pi$', '$\frac{3\pi}{2}$', '$2\pi$'};
+ax.FontSize = font_size;
+
+saveas(figure2, fp, 'epsc');
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_2.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_2.m
new file mode 100644
index 0000000000000000000000000000000000000000..d04692c7cbf15325a4a0d92a4e5c8c387644a7eb
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_2.m
@@ -0,0 +1,31 @@
+figure2 = figure(2);
+clf
+bd = coco_bd_read('set_v0');
+labs = coco_bd_labs(bd, 'MAX');
+[sol, ~] = coll_read_solution('bvp.seg1', 'set_v0', labs(2));
+
+figname = 'curve_build_max_phase.eps';
+fp = strcat(img_path, figname);
+
+pos = plot(sol.tbp, sol.xbp(:,1), 'k', ...
+  'DisplayName','Position', 'LineWidth', 1);
+hold on; grid on; box on;
+vel = plot(sol.tbp, sol.xbp(:,2), 'k--', ...
+  'DisplayName','Velocity', 'LineWidth', 1);
+
+lgd = legend([pos, vel]);
+lgd.Interpreter = 'latex';
+lgd.Location = 'southeast';
+
+xlim([0, 2*pi])
+
+xlabel('Time, $t$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+
+ax = gca;
+ax.XTick = [0,pi/2, pi, 3*pi/2, 2*pi];
+ax.TickLabelInterpreter = 'latex';
+ax.XTickLabel = {'$0$', '$\frac{\pi}{2}$', '$\pi$', '$\frac{3\pi}{2}$', '$2\pi$'};
+ax.FontSize =  font_size;
+
+saveas(figure2, fp, 'epsc');
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_3.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_3.m
new file mode 100644
index 0000000000000000000000000000000000000000..f628f3666c80e18dcad879e6ff4ecd73ec11be5a
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_3.m
@@ -0,0 +1,78 @@
+figure2 = figure(2);
+clf
+figname = 'curve_build_freq_sweep.eps';
+fp = strcat(img_path, figname);
+
+% Stable branches
+semilogx(om_vals(1:fold_idx(1)), R_vals(1:fold_idx(1)), 'k-', 'LineWidth', 1)
+hold on; grid on; box on;
+xlim([1.25,1.8]);
+semilogx(om_vals(fold_idx(2):end), R_vals(fold_idx(2):end), 'k-', 'LineWidth', 1)
+% Unstable Branch
+semilogx(om_vals(fold_idx(1):fold_idx(2)), R_vals(fold_idx(1):fold_idx(2)), 'k--', 'LineWidth', 1)
+
+xlabel('Forcing Frequency, $\omega$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+ylabel('Response Amplitude, $R$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+
+pk_idx = strcmpi(coco_bd_col(swp_bd, 'TYPE'), 'PK');
+om_idx = strcmpi(coco_bd_col(swp_bd, 'TYPE'), 'OM');
+idx = 1:numel(pk_idx);
+pk_idx = idx(pk_idx);
+om_idx = idx(om_idx);
+
+% PK points
+semilogx([om_vals(pk_idx(1)),om_vals(pk_idx(2))],[1.4,1.4], 'k--')
+semilogx(om_vals(pk_idx), R_vals(pk_idx), 'ko', ...
+  'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', marker_size_2)
+
+% OM points
+semilogx([1.67,1.67],[min(R_vals(om_idx)),max(R_vals(om_idx))], 'k--')
+semilogx(om_vals(om_idx), R_vals(om_idx), 'ko', ...
+  'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', marker_size_2)
+xx = [om_vals(fold_idx(1))+0.05,om_vals(fold_idx(1))];
+yy = [1.3,1.39];
+xy_annotation(gca, 'textarrow', xx, yy, ...
+  'String', 'PK', 'Interpreter', 'latex', ...
+  'FontSize', font_size, 'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xx = [1.55, 1.59];
+yy = [1.4, 1.4];
+xy_annotation(gca, 'textarrow', xx, yy, ...
+  'String', 'PK', 'Interpreter', 'latex', ...
+  'FontSize', font_size, 'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xx = [1.62, 1.66];
+yy = [R_vals(om_idx(1)), R_vals(om_idx(1))];
+xy_annotation(gca, 'textarrow', xx, yy, ...
+  'String', 'OM', 'Interpreter', 'latex', ...
+  'FontSize', font_size, 'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xx = [1.74, 1.675];
+yy = [1, R_vals(om_idx(2))-0.01];
+xy_annotation(gca, 'textarrow', xx, yy, ...
+  'String', 'OM', 'Interpreter', 'latex', ...
+  'VerticalAlignment', 'middle', ...
+  'FontSize', font_size, 'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xx = [1.74, 1.675];
+yy = [1, R_vals(om_idx(3))+0.01];
+xy_annotation(gca, 'arrow', xx, yy, ...
+  'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xlabel('Forcing Frequency, $\omega$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+ylabel('Response Amplitude, $R$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize =  font_size;
+
+saveas(figure2, fp, 'epsc');
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_4.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_4.m
new file mode 100644
index 0000000000000000000000000000000000000000..e7e909b7f3d1207dd9cc45661e5244f79095c458
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_4.m
@@ -0,0 +1,106 @@
+figure2 = figure(2);
+clf
+
+figname = 'curve_build_peak.eps';
+fp = strcat(img_path, figname);
+
+% Stable branches
+semilogx(om_vals(1:fold_idx(1)), R_vals(1:fold_idx(1)), 'k-', 'LineWidth', 1)
+hold on; grid on; box on;
+xlim([1.25,1.8]);
+semilogx(om_vals(fold_idx(2):end), R_vals(fold_idx(2):end), 'k-', 'LineWidth', 1)
+% Unstable Branch
+semilogx(om_vals(fold_idx(1):fold_idx(2)), R_vals(fold_idx(1):fold_idx(2)), 'k--', 'LineWidth', 1)
+
+% PK points
+pk_idx = strcmpi(coco_bd_col(swp_bd, 'TYPE'), 'PK');
+idx = 1:numel(pk_idx);
+pk_idx = idx(pk_idx);
+
+semilogx([om_vals(pk_idx(1)),om_vals(pk_idx(2))],[1.4,1.4], 'k--')
+semilogx(om_vals(pk_idx), R_vals(pk_idx), 'ko', ...
+  'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', marker_size_2)
+
+xx = [1.59, 1.63];
+yy = [1.4, 1.47];
+xy_annotation(gca, 'arrow', xx, yy, ...
+  'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xx = [1.695, 1.7];
+yy = [1.4, 1.47];
+xy_annotation(gca, 'arrow', xx, yy, ...
+  'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xlabel('Forcing Frequency, $\omega$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+ylabel('Response Amplitude, $R$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize =  font_size;
+
+dim = [1.26, 1.35, 0.155, 0.23];
+bx = xy_annotation(gca, 'rectangle', dim, ...
+  'LineWidth', 1, 'LineStyle', 'none');
+
+pk_bd = coco_bd_read('pk');
+pk_idx = strcmpi(coco_bd_col(pk_bd, 'TYPE'), 'PK');
+idx = 1:numel(pk_idx);
+pk_idx = idx(pk_idx);
+fake_pk_idx = idx(pk_idx)+2;
+ompk1 = coco_bd_col(pk_bd, 'om');
+rpk1 = coco_bd_col(pk_bd, 'R.PK1');
+ompk2 = coco_bd_col(pk_bd, 'pk2.om');
+rpk2 = coco_bd_col(pk_bd, 'R.PK2');
+om = [ompk1(fake_pk_idx),ompk2(fake_pk_idx)];
+R = [rpk1(fake_pk_idx), rpk2(fake_pk_idx)];
+semilogx(ompk1(pk_idx-3), rpk1(pk_idx-3), 'ko', 'MarkerSize', marker_size_2)
+
+rect_width = 0.03;
+rect_height = 0.06;
+
+% Peak Box
+dim = [ompk1(pk_idx-3)-rect_width/2, ...
+  rpk1(pk_idx-3) - rect_height/2, ...
+  rect_width, rect_height];
+xy_annotation(gca, 'rectangle', dim, ...
+  'LineStyle', '--');
+
+axes('Position', bx.Position);
+hold on; box on; grid on;
+set(gca, 'xticklabel', {[]}, 'yticklabel', {[]})
+semilogx(om_vals(1:fold_idx(1)), R_vals(1:fold_idx(1)), 'k-', 'LineWidth', 1)
+xlim([1.64, 1.7]);
+ylim([1.475, 1.535]);
+
+semilogx(om, R, 'ko', ...
+  'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', marker_size_1)
+semilogx(ompk1(pk_idx-3), rpk1(pk_idx-3), 'ko', 'MarkerSize', marker_size_1)
+
+xy_annotation(gca, 'line', ...
+  [ompk1(fake_pk_idx),ompk1(fake_pk_idx)], ...
+  [rpk1(fake_pk_idx)+0.005, rpk1(fake_pk_idx)+0.025], ...
+  'LineStyle', '--', 'LineWidth', 1);
+
+xy_annotation(gca, 'line', ...
+  [ompk2(fake_pk_idx),ompk2(fake_pk_idx)], ...
+  [rpk2(fake_pk_idx)+0.005, rpk2(fake_pk_idx)+0.025], ...
+  'LineStyle', '--', 'LineWidth', 1);
+
+xy_annotation(gca, 'doublearrow', ...
+  [ompk1(fake_pk_idx),ompk2(fake_pk_idx)], ...
+  [rpk1(fake_pk_idx)+0.02, rpk2(fake_pk_idx)+0.02], ...
+  'LineWidth', 1, 'HeadStyle', 'cback1', ...
+  'Head1Width', 6, 'Head2Width', 6);
+
+xy_annotation(gca, 'textarrow', ...
+  [ompk1(fake_pk_idx)-0.01,ompk1(fake_pk_idx)], ...
+  [rpk1(fake_pk_idx)+0.02, rpk2(fake_pk_idx)+0.02], ...
+  'String', '$\epsilon_\omega$', ...
+  'Interpreter', 'latex', 'LineWidth', 1,'HeadStyle', ...
+  'none', 'FontSize', font_size);
+
+saveas(figure2, fp, 'epsc');
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_5.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_5.m
new file mode 100644
index 0000000000000000000000000000000000000000..6ce898d4620b5d35d516cee42a14fc0cc4ae160e
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_5.m
@@ -0,0 +1,110 @@
+figure2 = figure(2);
+clf
+figname = 'curve_build_top_fold.eps';
+fp = strcat(img_path, figname);
+
+% Stable branches
+semilogx(om_vals(1:fold_idx(1)), R_vals(1:fold_idx(1)), 'k-', 'LineWidth', 1)
+hold on; grid on; box on;
+xlim([1.25,1.8]);
+semilogx(om_vals(fold_idx(2):end), R_vals(fold_idx(2):end), 'k-', 'LineWidth', 1)
+% Unstable Branch
+semilogx(om_vals(fold_idx(1):fold_idx(2)), R_vals(fold_idx(1):fold_idx(2)), 'k--', 'LineWidth', 1)
+
+% OM points
+semilogx([1.67,1.67],[min(R_vals(om_idx(1:3))),max(R_vals(om_idx(1:3)))], 'k--')
+semilogx(om_vals(om_idx(1:3)), R_vals(om_idx(1:3)), 'ko', ...
+  'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', marker_size_2)
+
+
+xx = [1.68, 1.695];
+yy = [1.2, 1.35];
+xy_annotation(gca, 'arrow', xx, yy, ...
+  'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xx = [1.67, 1.7];
+yy = [1.52, 1.51];
+xy_annotation(gca, 'arrow', xx, yy, ...
+  'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+dim = [1.26, 1.11, 0.155, 0.23];
+bx = xy_annotation(gca, 'rectangle', dim, ...
+  'LineWidth', 1, 'LineStyle', 'none');
+
+xlabel('Forcing Frequency, $\omega$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+ylabel('Response Amplitude, $R$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize =  font_size;
+
+om12_bd = coco_bd_read('fold_find_top');
+om12_idx = strcmpi(coco_bd_col(om12_bd, 'TYPE'), 'EP');
+idx = 1:numel(om12_idx);
+om12_idx = idx(om12_idx);
+fake_om12_idx = idx(om12_idx)+4;
+
+om1 = coco_bd_col(om12_bd, 'OM1.om');
+rom1 = coco_bd_col(om12_bd, 'OM1.R');
+rom2 = coco_bd_col(om12_bd, 'OM2.R');
+om = [om1(fake_om12_idx(1)),om1(fake_om12_idx(1))];
+R = [rom1(fake_om12_idx(1)), rom2(fake_om12_idx(1))];
+fold_x = 1.692;
+fold_y = 1.455;
+semilogx(fold_x, fold_y, 'ko', 'MarkerSize', marker_size_2)
+
+% Top Fold Box
+dim = [fold_x-rect_width/2, ...
+  fold_y - rect_height/2, ...
+  rect_width, rect_height];
+xy_annotation(gca, 'rectangle', dim, ...
+  'LineStyle', '--');
+
+axes('Position', bx.Position);
+hold on; box on; grid on;
+set(gca, 'xticklabel', {[]}, 'yticklabel', {[]})
+semilogx(om_vals(1:fold_idx(1)), R_vals(1:fold_idx(1)), 'k-', 'LineWidth', 1)
+% Unstable Branch
+semilogx(om_vals(fold_idx(1):fold_idx(2)), R_vals(fold_idx(1):fold_idx(2)), 'k--', 'LineWidth', 1)
+xlim([1.685, 1.715]);
+ylim([1.42, 1.48]);
+
+semilogx(om, R, 'ko', ...
+  'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', marker_size_1)
+semilogx(om1(om12_idx), rom1(om12_idx), 'ko', 'MarkerSize', marker_size_1)
+
+xy_annotation(gca, 'line', ...
+  [om1(fake_om12_idx(1))+0.001,om1(fake_om12_idx(1))+0.01], ...
+  [rom1(fake_om12_idx(1)), rom1(fake_om12_idx(1))], ...
+  'LineStyle', '--', 'LineWidth', 1);
+
+xy_annotation(gca, 'line', ...
+  [om1(fake_om12_idx(1))+0.001,om1(fake_om12_idx(1))+0.01], ...
+  [rom2(fake_om12_idx(1)), rom2(fake_om12_idx(1))], ...
+  'LineStyle', '--', 'LineWidth', 1);
+
+xy_annotation(gca, 'doublearrow', ...
+  [om1(fake_om12_idx(1))+0.007, om1(fake_om12_idx(1))+0.007], ...
+  [rom1(fake_om12_idx(1)), rom2(fake_om12_idx(1))], ...
+  'LineWidth', 1, 'HeadStyle', 'cback1', ...
+  'Head1Width', 6, 'Head2Width', 6);
+
+xy_annotation(gca, 'line', ...
+  [om1(fake_om12_idx(1))+0.007, om1(fake_om12_idx(1))+0.007], ...
+  [rom2(fake_om12_idx(1))-0.005, rom2(fake_om12_idx(1))], ...
+  'LineWidth', 1);
+
+xy_annotation(gca, 'textarrow', ...
+  [om1(fake_om12_idx(1))+0.012, om1(fake_om12_idx(1))+0.007], ...
+  [rom2(fake_om12_idx(1))-0.015, rom2(fake_om12_idx(1))-0.015], ...
+  'String', '$\epsilon_R$', ...
+  'Interpreter', 'latex', 'LineWidth', 1,'HeadStyle', ...
+  'none', 'FontSize', font_size);
+
+semilogx(fold_x, fold_y, 'ko', 'MarkerSize', marker_size_1)
+
+saveas(figure2, fp, 'epsc');
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_6.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_6.m
new file mode 100644
index 0000000000000000000000000000000000000000..6213ff697a08f5816a8f74f9a834e630cd7afab8
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_6.m
@@ -0,0 +1,152 @@
+figure2 = figure(2);
+clf
+
+figname = 'curve_build_btm_fold.eps';
+fp = strcat(img_path, figname);
+
+if ~coco_exist('uq_sweep_2', 'run')
+  addpath('../../duff')
+  addpath('../../utils')  
+  last_run_name = 'fold_find_btm';
+
+  bd = coco_bd_read(last_run_name);
+  labs = coco_bd_labs(bd, 'UZ');
+  lab = labs(1);
+  prob = coco_prob();
+  prob = coco_set(prob, 'coll', 'NTST', 30);
+  
+  prob = ode_bvp2bvp(prob, 'PK1', last_run_name, lab);
+  bvp_data = coco_get_func_data(prob, 'PK1.bvp', 'data');
+
+  [pk1_data, pk1_uidx] = coco_get_func_data(prob, ...
+    'PK1.bvp.seg1.coll', 'data', 'uidx');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+  % Maintain velocity constraint (could also be done with a
+  % boundary condition)
+  prob = coco_add_pars(prob, 'PK1.v0', pk1_x0(2), ...
+    'PK1.v0', 'inactive');
+  prob = coco_add_pars(prob, 'R', pk1_x0(1), ...
+    'R', 'inactive');
+  bd = coco(prob, 'uq_sweep_2', [], {'om', 'R'});
+else
+  bd = coco_bd_read('uq_sweep_2');
+end
+
+% Stable branches
+semilogx(om_vals(1:fold_idx(1)), R_vals(1:fold_idx(1)), 'k-', 'LineWidth', 1)
+hold on; grid on; box on;
+xlim([1.25,1.8]);
+semilogx(om_vals(fold_idx(2):end), R_vals(fold_idx(2):end), 'k-', 'LineWidth', 1)
+% Unstable Branch
+semilogx(om_vals(fold_idx(1):fold_idx(2)), R_vals(fold_idx(1):fold_idx(2)), 'k--', 'LineWidth', 1)
+
+semilogx(coco_bd_col(bd, 'om'), coco_bd_col(bd, 'R'), 'k-', 'LineWidth', 1)
+% OM points
+top_fold_bd = coco_bd_read('fold_find_top');
+om34_idx = strcmpi(coco_bd_col(top_fold_bd, 'TYPE'), 'UZ');
+idx = 1:numel(om34_idx);
+om34_idx = idx(om34_idx);
+
+om =  coco_bd_col(top_fold_bd, 'om');
+pk1r = coco_bd_col(top_fold_bd, 'R');
+om1 = coco_bd_col(top_fold_bd, 'OM1.om');
+rom1 = coco_bd_col(top_fold_bd, 'OM1.R');
+rom2 = coco_bd_col(top_fold_bd, 'OM2.R');
+rom3 = coco_bd_col(top_fold_bd, 'OM3.R');
+om = [om1(om34_idx(1)), om1(om34_idx(1)), ...
+  om1(om34_idx(1))];
+R = [rom1(om34_idx(1)), rom2(om34_idx(1)), ...
+  rom3(om34_idx(1))];
+semilogx(om, R, 'ko', 'MarkerSize', marker_size_2, 'MarkerFaceColor', [0.5,0.5,0.5])
+
+semilogx([om(1), om(1)], [min(R)+0.01,max(R)-0.05], 'k--')
+
+dim = [1.26, 0.87, 0.155, 0.23];
+bx = xy_annotation(gca, 'rectangle', dim, ...
+  'LineWidth', 1, 'LineStyle', 'none');
+
+xlabel('Forcing Frequency, $\omega$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+ylabel('Response Amplitude, $R$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize =  font_size;
+
+% % Bottom Fold Box
+% dim = [1.48, 0.77, ...
+%         0.15, 0.14];
+% str = {'A \downarrow , \epsilon_{\omega,2} \downarrow'};
+% xy_annotation(gca, 'textbox', dim, ...
+%   'LineStyle', '-', 'String', str, ...
+%   'FitBoxToText', 'off', 'FontSize', font_size, ...
+%   'BackgroundColor', 'white', ...
+%   'VerticalAlignment', 'middle', ...
+%   'HorizontalAlignment', 'center');
+
+xy_annotation(gca, 'line', ...
+  [om(2)+0.007, om(2)+0.015], ...
+  [R(1), R(1)], ...
+  'LineWidth', 1);
+
+xy_annotation(gca, 'line', ...
+  [om(2)+0.007, om(2)+0.015], ...
+  [R(2), R(2)], ...
+  'LineWidth', 1);
+
+xy_annotation(gca, 'line', ...
+  [om(2)+0.007, om(2)+0.015], ...
+  [R(3), R(3)], ...
+  'LineWidth', 1);
+
+xy_annotation(gca, 'arrow', ...
+  [om(2)+0.01, om(2)+0.01], ...
+  [R(1)+0.05, R(1)], ...
+  'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xy_annotation(gca, 'doublearrow', ...
+  [om(2)+0.01, om(2)+0.01], ...
+  [R(2), R(3)], ...
+  'LineWidth', 1, 'HeadStyle', 'cback1', ...
+  'Head1Width', 6, 'Head2Width', 6);
+
+xy_annotation(gca, 'textarrow', ...
+  [1.75, 1.75], ...
+  [rom2(fake_om12_idx(1))-0.02, rom2(fake_om12_idx(1))-0.02], ...
+  'String', '$\epsilon_{\omega,1}$', ...
+  'Interpreter', 'latex', 'LineWidth', 1,'HeadStyle', ...
+  'none', 'FontSize', font_size);
+clear mean
+xy_annotation(gca, 'textarrow', ...
+  [1.73, om(2)+0.01], ...
+  [mean(R(2:3)), mean(R(2:3))], ...
+  'String', '$\epsilon_{\omega,2}$', ...
+  'Interpreter', 'latex', 'LineWidth', 1,'HeadStyle', ...
+  'none', 'FontSize', font_size);
+
+btm_fold_bd = coco_bd_read('fold_find_btm');
+idx = strcmpi(coco_bd_col(btm_fold_bd, 'TYPE'), 'UZ');
+idx2 = 1:numel(idx);
+idx = idx2(idx);
+
+ompk1 = coco_bd_col(btm_fold_bd, 'om');
+rpk1 = coco_bd_col(btm_fold_bd, 'R');
+omom = coco_bd_col(btm_fold_bd, 'OM.om');
+om1r = coco_bd_col(btm_fold_bd, 'OM1.R');
+
+semilogx([ompk1(idx), ompk1(idx)+0.01, omom(idx), omom(idx), omom(idx)], ...
+  [rpk1(idx), rpk1(idx), om1r(idx), om1r(idx)-0.01, om1r(idx)-0.02], ...
+  'ko', 'MarkerSize', marker_size_2, 'MarkerFaceColor', [0.5,0.5,0.5]);
+
+xy_annotation(ax, 'arrow', [1.68, 1.6], [1.45, 1.2], ...
+  'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+xy_annotation(ax, 'textbox', [1.59, 1.3, 0.05, 0.1], ...
+  'String', 'A \downarrow', 'FontSize', font_size, ...
+  'FitBoxToText', 'on', 'LineStyle', 'none');
+
+saveas(figure2, fp, 'epsc');
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_7.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_7.m
new file mode 100644
index 0000000000000000000000000000000000000000..4a919984030297ac9c09d6341397a285a958afcc
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_curve_build_stage_7.m
@@ -0,0 +1,68 @@
+figure2 = figure(2);
+clf
+figname = 'curve_build_final.eps';
+fp = strcat(img_path, figname);
+
+if ~coco_exist('uq_sweep_2', 'run')
+  addpath('../../duff')
+  addpath('../../utils')  
+  last_run_name = 'fold_find_btm';
+
+  bd = coco_bd_read(last_run_name);
+  labs = coco_bd_labs(bd, 'UZ');
+  lab = labs(1);
+  prob = coco_prob();
+  prob = coco_set(prob, 'coll', 'NTST', 30);
+  
+  prob = ode_bvp2bvp(prob, 'PK1', last_run_name, lab);
+  bvp_data = coco_get_func_data(prob, 'PK1.bvp', 'data');
+
+  [pk1_data, pk1_uidx] = coco_get_func_data(prob, ...
+    'PK1.bvp.seg1.coll', 'data', 'uidx');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+  % Maintain velocity constraint (could also be done with a
+  % boundary condition)
+  prob = coco_add_pars(prob, 'PK1.v0', pk1_x0(2), ...
+    'PK1.v0', 'inactive');
+  prob = coco_add_pars(prob, 'R', pk1_x0(1), ...
+    'R', 'inactive');
+  bd = coco(prob, 'uq_sweep_2', [], {'om', 'R'});
+else
+  bd = coco_bd_read('uq_sweep_2');
+end
+
+semilogx(coco_bd_col(bd, 'om'), coco_bd_col(bd, 'R'), 'k-', 'LineWidth', 1)
+hold on; grid on; box on;
+main_axis = gca;
+xlim([1.25, 1.8]);
+
+xlabel('Forcing Frequency, $\omega$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+ylabel('Response Amplitude, $R$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize =  font_size;
+
+dim = [1.26, 0.7, 0.155, 0.23];
+bx = xy_annotation(main_axis, 'rectangle', dim, ...
+  'LineWidth', 1, 'LineStyle', 'none');
+
+btm_fold_bd = coco_bd_read('fold_find_btm');
+idx = strcmpi(coco_bd_col(btm_fold_bd, 'TYPE'), 'UZ');
+idx2 = 1:numel(idx);
+idx = idx2(idx);
+
+ompk1 = coco_bd_col(btm_fold_bd, 'om');
+rpk1 = coco_bd_col(btm_fold_bd, 'R');
+omom = coco_bd_col(btm_fold_bd, 'OM.om');
+om1r = coco_bd_col(btm_fold_bd, 'OM1.R');
+
+semilogx([ompk1(idx), ompk1(idx)+0.01, omom(idx), omom(idx), omom(idx)], ...
+  [rpk1(idx), rpk1(idx), om1r(idx), om1r(idx)-0.01, om1r(idx)-0.02], ...
+  'ko', 'MarkerSize', marker_size_2, 'MarkerFaceColor', [0.5,0.5,0.5]);
+
+saveas(figure2, fp, 'epsc');
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_duff_hysteresis.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_duff_hysteresis.m
new file mode 100644
index 0000000000000000000000000000000000000000..34326000ea32291a4039e81e19c5eee0068c998c
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_duff_hysteresis.m
@@ -0,0 +1,107 @@
+%% Duffing Hysteresis
+%  Plot the frequency sweep.  The unstable segment plotted
+%  with dashed lines, the stable segments with solid lines,
+%  the hysteresis transitions shown with arrows.  The
+%  forward sweep plotted with a red line, the reverse sweep
+%  plotted with a blue segment.  Remove axis numbers.
+
+font_size = 15;
+swp_bd = coco_bd_read('sweep');
+
+om_vals = coco_bd_col(swp_bd, 'om');
+R_vals  = coco_bd_col(swp_bd, 'R');
+fold_idx = strcmpi(coco_bd_col(swp_bd, 'TYPE'), 'FP');
+idx = 1:numel(fold_idx);
+fold_idx = idx(fold_idx);
+om_idx_left = om_vals <= om_vals(fold_idx(2));
+om_idx_right = om_vals >= om_vals(fold_idx(1));
+
+[PK_max, PK_idx] = max(R_vals);
+up_idx = (R_vals < PK_max);
+
+figure1 = figure(1);
+hold on;grid on;box on;
+
+% Primary frequency response curve.
+% Stable branches
+semilogx(om_vals(1:fold_idx(1)), R_vals(1:fold_idx(1)), 'k-', 'LineWidth', 1)
+semilogx(om_vals(fold_idx(2):end), R_vals(fold_idx(2):end), 'k-', 'LineWidth', 1)
+% Unstable Branch
+semilogx(om_vals(fold_idx(1):fold_idx(2)), R_vals(fold_idx(1):fold_idx(2)), 'k--', 'LineWidth', 1)
+% Fold points
+% semilogx(om_vals(fold_idx), R_vals(fold_idx), 'ko', ...
+%   'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', marker_size)
+xlim([1.25,1.8]);
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize =  font_size;
+ax.XScale = 'log';
+
+xx = [om_vals(fold_idx(1)),om_vals(fold_idx(1))];
+yy = [R_vals(fold_idx(1))-0.05, 0.68];
+xy_annotation(gca, 'arrow', xx, yy, ...
+  'Color', [1,0,0], 'LineStyle', ':', 'LineWidth', 1, ...
+  'HeadStyle', 'cback1', 'HeadWidth', 6);
+
+xx = [1.71, 1.78];
+yy = [0.6, 0.45];
+xy_annotation(gca, 'arrow', xx, yy, ...
+  'Color', [1,0,0], 'LineStyle', ':', 'LineWidth', 1, ...
+  'HeadStyle', 'cback1', 'HeadWidth', 6);
+
+xx = [1.77, 1.7];
+yy = [0.42, 0.57];
+xy_annotation(gca, 'arrow', xx, yy, ...
+  'Color', [0,0,1], 'LineStyle', '-.', 'LineWidth', 1, ...
+  'HeadStyle', 'cback1', 'HeadWidth', 6);
+
+xx = [1.39,1.48];
+yy = [1.005,1.19];
+xy_annotation(gca, 'textarrow', xx, yy, ...
+  'Color', [1,0,0], 'LineStyle', ':', ...
+  'String', 'Sweep Up', ...
+  'TextColor', [0,0,0], ...
+  'VerticalAlignment', 'baseline', ...
+  'Interpreter', 'latex', ...
+  'FontSize', font_size, 'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xx = [1.48,1.39];
+yy = [1.14,0.96];
+xy_annotation(gca, 'textarrow', xx, yy, ...
+  'Color', [0,0,1], 'LineStyle', '-.', ...
+  'String', 'Sweep Down', ...
+  'TextColor', [0,0,0], ...
+  'VerticalAlignment', 'top', ...
+  'Interpreter', 'latex', ...
+  'FontSize', font_size, 'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xx = [om_vals(fold_idx(2)),om_vals(fold_idx(2))];
+yy = [R_vals(fold_idx(2))+0.1, 1.47];
+xy_annotation(gca, 'arrow', xx, yy, ...
+  'Color', [0,0,1], 'LineStyle', '-.', 'LineWidth', 1, ...
+  'HeadStyle', 'cback1', 'HeadWidth', 6);
+
+xx = [om_vals(fold_idx(2))-0.05,om_vals(fold_idx(2))];
+yy = [1.3,1.3];
+xy_annotation(gca, 'textarrow', xx, yy, ...
+  'String', '$\Delta \omega$ ', 'Interpreter', 'latex', ...
+  'FontSize', font_size, 'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+xx = [om_vals(fold_idx(1))+0.05,om_vals(fold_idx(1))];
+yy = [1.3,1.3];
+xy_annotation(gca, 'arrow', xx, yy, 'LineWidth', 1, ...
+  'HeadStyle', 'cback1','HeadWidth', 6);
+
+set(gca, 'xticklabel', {[]}, 'yticklabel', {[]})
+xlabel('Forcing Frequency, $\omega$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+ylabel('Response Amplitude, $R$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+
+figname = 'duffing_hysteresis.eps';
+fp = strcat(img_path, figname);
+
+saveas(figure1, fp, 'epsc');
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_moment_convergence.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_moment_convergence.m
new file mode 100644
index 0000000000000000000000000000000000000000..db4be27cf96087e39d4ebb95df4ea4065f5e8958
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_moment_convergence.m
@@ -0,0 +1,73 @@
+%% Convergence plots:
+figname = 'uq_pce_var_convergence.eps';
+fp = strcat(img_path, figname);
+figure5 = figure(5);
+
+font_size = 15;
+mean = zeros(6,5);
+var  = zeros(6,5);
+
+for M=1:6
+  for P=2:6
+    run_name = ['pce_convergence_M_', int2str(M), '_P_', int2str(P)];
+    bd = coco_bd_read(run_name);
+    mu = coco_bd_col(bd, 'resp.mean');
+    sigsq = coco_bd_col(bd, 'resp.var');
+    mean(M, P-1) = mu;
+    var(M, P-1) = sigsq;
+  end
+end
+
+M = repmat(1:6, 5, 1)';
+P = repmat(2:6, 6, 1);
+
+mesh(M, P, var)
+colormap(gray)
+hold on
+plot3(M(4,2), P(4,2), var(4,2), 'ko', 'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', 10)
+
+shading interp
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = font_size;
+ax.View = [30.5, 29.2];
+ax.XLabel.Position = [5,1];
+ax.XTick = 1:6;
+ax.XLabel.Position = [3.5, 1,0];
+ax.XLabel.Rotation = -11;
+ax.YLabel.Position = [6.75, 3.5, 0];
+ax.YLabel.Rotation = 32;
+ax.YTick = 2:6;
+xlabel('Integration Order, $M$', 'Interpreter', 'latex');
+ylabel('Polynomial Degree, $P$', 'Interpreter', 'latex');
+zlabel('Variance, $\sigma^{2}$', 'Interpreter', 'latex');
+
+saveas(figure5, fp, 'epsc');
+
+figname = 'uq_pce_mean_convergence.eps';
+fp = strcat(img_path, figname);
+figure6 = figure(6);
+M = repmat(1:6, 5, 1)';
+P = repmat(2:6, 6, 1);
+
+mesh(M, P, mean)
+colormap(gray)
+hold on
+plot3(M(4,2), P(4,2), mean(4,2), 'ko', 'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', 10)
+
+shading interp
+ax = gca;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = font_size;
+ax.View = [30.5, 29.2];
+ax.XTick = 1:6;
+ax.XLabel.Position = [3.5,1,1.3335];
+ax.XLabel.Rotation = -11;
+ax.YLabel.Position = [6.8,3.5,1.3335];
+ax.YLabel.Rotation = 33;
+ax.YTick = 2:6;
+xlabel('Integration Order, $M$', 'Interpreter', 'latex');
+ylabel('Polynomial Degree, $P$', 'Interpreter', 'latex');
+zlabel('Mean, $\mu$', 'Interpreter', 'latex');
+
+saveas(figure6, fp, 'epsc');
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_optimal_run.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_optimal_run.m
new file mode 100644
index 0000000000000000000000000000000000000000..cc4aa8b08069a834f755e61bbc12c06bd384667a
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_optimal_run.m
@@ -0,0 +1,104 @@
+%% Duffing Optimal Continuation Run
+
+font_size = 20;
+figname = 'uq_opt_k-m-obj.eps';
+fp = strcat(img_path, figname);
+uq_swp_bd = coco_bd_read('uq_sweep');
+
+k = coco_bd_col(uq_swp_bd, 'k');
+m = coco_bd_col(uq_swp_bd, 'm');
+obj = coco_bd_col(uq_swp_bd, 'obj');
+
+[obj_max, max_idx] = max(obj);
+
+figure3 = figure(3);
+hold on; grid on
+plot3(m, k, obj, 'k', 'LineWidth', 1)
+plot3(m(max_idx), k(max_idx), obj_max, 'ko', 'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', 10)
+
+xlim([0.9,3.1])
+ylim([0.9,3.1])
+zlim([0.7,1.15])
+xlabel('Mass, $m$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+ylabel('Stiffness, $k$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+zlabel('Objective', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+view([-114,14])
+ax = gca;
+ax.XTick = 1:0.5:3;
+ax.YTick = 1.5:0.5:3;
+ax.ZTick = 0.7:0.05:1.15;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = font_size;
+saveas(figure3, fp, 'epsc');
+clf
+
+figname = 'uq_opt_k-m.eps';
+fp = strcat(img_path, figname);
+
+plot(k, m, 'k-', 'LineWidth', 1);
+hold on; grid on; box on;
+plot(k(max_idx), m(max_idx), 'ko', ...
+  'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', 10)
+xlabel('Stiffness, $k$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+ylabel('Mass, $m$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+
+xlim([0.9,3.1])
+ylim([0.9,3.1])
+
+ax = gca;
+ax.XTick = 1:0.5:3;
+ax.YTick = 1:0.5:3;
+ax.ZTick = 0.8:0.05:1.3;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = font_size;
+saveas(figure3, fp, 'epsc');
+clf
+
+figname = 'uq_opt_k-obj.eps';
+fp = strcat(img_path, figname);
+
+plot(k, obj, 'k-', 'LineWidth', 1);
+hold on; grid on; box on;
+xlabel('Stiffness, $k$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+ylabel('Objective', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+plot(k(max_idx), obj_max, 'ko', ...
+  'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', 10)
+
+xlim([0.9,3.1])
+ylim([0.7,1.15])
+
+ax = gca;
+ax.XTick = 1:0.5:3;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = font_size;
+saveas(figure3, fp, 'epsc');
+clf
+
+figname = 'uq_opt_obj-m.eps';
+fp = strcat(img_path, figname);
+
+plot(obj, m, 'k-', 'LineWidth', 1);
+hold on; grid on; box on;
+xlabel('Objective', 'Interpreter', ...
+  'latex', 'FontSize', font_size);
+ylabel('Mass, $m$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+plot(obj_max, m(max_idx), 'ko', ...
+  'MarkerFaceColor', [0.5,0.5,0.5], 'MarkerSize', 10)
+
+xlim([0.7,1.15])
+ylim([0.9,3.1])
+
+ax = gca;
+ax.YTick = 1:0.5:3;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = font_size;
+saveas(figure3, fp, 'epsc');
+
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_sigma_level_study.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_sigma_level_study.m
new file mode 100644
index 0000000000000000000000000000000000000000..3654ac24b7d23120f9595caab8bfae0dd58fc4d8
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/ch_5_thesis_figures_sigma_level_study.m
@@ -0,0 +1,76 @@
+figure4 = figure(4);
+font_size = 15;
+figname = 'opt_change_w_n_stdev.eps';
+fp = strcat(img_path, figname);
+uq_swp_bd = coco_bd_read('uq_sweep_no_adjt_for_plot_m=1_n=1');
+mu = coco_bd_col(uq_swp_bd, 'resp.mean');
+var = coco_bd_col(uq_swp_bd, 'resp.var');
+% Plot the k-m circle
+k = linspace(1,3,100);
+m_star = sqrt(1 - (k-2).^2);
+plot([k, fliplr(k)], [m_star+2, -m_star+2], 'k-', 'LineWidth', 1);
+hold on; grid on; box on;
+for i=[0,1]
+    for j=0:6
+      run_name = ['uq_sweep_no_adjt_for_plot_m=',int2str(i),'_n=',int2str(j)];
+      if coco_exist(run_name, 'run')
+        bd = coco_bd_read(run_name);
+        fp_idx = strcmpi(coco_bd_col(bd, 'TYPE'), 'FP');
+        k = coco_bd_col(bd, 'k');
+        m = coco_bd_col(bd, 'm');
+        obj = coco_bd_col(bd, 'obj');
+        obj_fp = obj(fp_idx);
+        k_fp = k(fp_idx);
+        m_fp = m(fp_idx);
+        [obj_max, max_idx] = max(obj_fp);
+
+        k_max = k_fp(max_idx);
+        m_max = m_fp(max_idx);
+        angle = atan2(m_max-2, k_max-2);
+
+        x = 0.6*cos(angle)+2;
+        y = 0.6*sin(angle)+2;
+
+        if i == 0
+          arrow_label = '-$\sigma$';
+          plot(k_max, m_max, 'ko', ...
+            'MarkerSize', 7);        
+        else
+          plot(k_max, m_max, 'ko', ...
+            'MarkerFaceColor', [0.5,0.5,0.5], ...
+            'MarkerSize', 7);
+          if j == 0
+            arrow_label = '$\mu$';
+          else
+            arrow_label = ['$\mu - ', int2str(j), '\sigma$'];
+          end
+        end
+        switch j
+          case 0
+            x = x-0.5;
+          case 1
+            if i==1
+              x = x-0.25;
+            end
+        end
+        xy_annotation(gca, 'textarrow', ...
+          [x, k_max], ...
+          [y, m_max], ...
+          'String', arrow_label, ...
+          'Interpreter', 'latex', 'LineWidth', 1,'HeadStyle', ...
+          'cback1', 'FontSize', font_size, 'HeadWidth', 6);
+      end
+    end    
+end
+
+xlabel('Stiffness, $k$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+ylabel('Mass, $m$', 'Interpreter', ...
+  'latex', 'FontSize', font_size)
+
+ax = gca;
+ax.XTick = 1:0.5:3;
+ax.YTick = 1:0.5:3;
+ax.TickLabelInterpreter = 'latex';
+ax.FontSize = font_size;
+saveas(figure4, fp, 'epsc');
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/dRdm.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/dRdm.m
new file mode 100644
index 0000000000000000000000000000000000000000..411b6705c84caf24317387bb060e3a4b63f7ab1f
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/dRdm.m
@@ -0,0 +1,8 @@
+function j = dRdm(w,k,m,eps)
+
+A = (w - sqrt(k./m))./((3/8).*eps*0.01.*sqrt(k./m));
+B = (w.*(sqrt(m)).^(-1))./((3/8)*0.01.*eps.*sqrt(k));
+
+j = (1/4).*((sqrt(A)).^1).*(B);
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo.m
new file mode 100644
index 0000000000000000000000000000000000000000..2b6f59e7516b0bf70abe253a0cfd9df922014227
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo.m
@@ -0,0 +1,62 @@
+% Path to vector field, Jacobians, and Response Function
+addpath('../duff')
+addpath('../linode')
+
+% Initialize problem instance and set options
+prob_init = coco_prob();
+
+prob_init = coco_set(prob_init, 'coll', 'NTST', 50, 'NCOL', 6);
+prob_init = coco_set(prob_init, 'cont', 'PtMX', 100);%, ...
+%   'h', 0.5, 'almax', 30, 'h_max', 1000);
+% prob_init = coco_set(prob_init, 'cont', 'NAdapt', 5, 'NPR', 10);
+
+% % Temporarily allow really bad results for some checking of
+% % Jacobians.
+% prob_init = coco_set(prob_init, 'coll', 'TOL', 5);
+
+
+% Let Transients die out
+eps = 0.001;
+%     m, eps*c, k, eps*alpha, eps*F, omega
+p0 = [1; eps*2;1;eps*5;eps*5;1];
+[~, x0]   = ode45(@(t,x) duff(x, p0), ...
+  [0 24*pi], [1; 0; 0]);
+
+% Initial Solution Guess
+[t0, x0]   = ode45(@(t,x) duff(x, p0), ...
+  [0 2*pi], [x0(end,1:3)']);
+
+% 'coll'-toolbox arguments
+coll_args = {@duff, @duff_dx, @duff_dp, ...
+  @duff_dxdx, @duff_dxdp, @duff_dpdp, ...
+  t0, x0, p0};
+
+% parameter names
+pnames = {'m', 'c', 'k', 'eps', 'A', 'om'};
+
+% 'bvp'-toolbox arguments
+bvp_args = {@duff_bc, @duff_bc_du, @duff_bc_dudu};
+
+uq_args = {
+  {'c'}, ...        % Stochastic Parameter
+  {'Normal'}, ...   % Distribution Type
+  [[eps*2,eps*0.1]], ...    % Distribution Parameters
+  {}};%, ...
+%   '-add-adjt'};   % Option to add the adjoint
+                  % equations to the uq probs
+
+prob = uq_isol2bvp_sample(prob_init, 'duff', coll_args{:}, pnames, bvp_args{:}, uq_args{:});
+prob = uq_coll_add_response(prob, 'duff', 'resp', 'bv', @x10, @x10_du, @x10_dudu);
+% prob = uq_coll_add_response_adjoint(prob, 'duff', 'resp');
+prob = coco_set(prob, 'cont', 'PtMX', 2000);%, ...
+bd = coco(prob, 'duff', [], 1, {'om', 'duff.resp.mean', 'duff.resp.var'}, [0.02, 100]);
+% bd = coco(prob, 'duff', [], 1, {'duff.resp.mean', 'om', 'duff.resp.var', ...
+%   'd.duff.resp.mean', 'd.duff.resp.var', 'd.om', 'd.k', 'd.m', 'd.eps', 'd.A'});
+% 
+% prob = ode_isol2bvp(prob_init, '', coll_args{:}, pnames, bvp_args{:});
+% [data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
+% maps = data.coll_seg.maps;
+% x0 = uidx(maps.x0_idx);
+% prob = coco_add_pars(prob, 'A', x0(1), 'x01', 'inactive');
+% 
+% bd = coco(prob, 'duff', [], 1, {'om', 'x01'});
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_curve_build.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_curve_build.m
new file mode 100644
index 0000000000000000000000000000000000000000..06493bd4c7d634b8996dd2b5e6954eb18d4947f7
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_curve_build.m
@@ -0,0 +1,367 @@
+%% Problem Set-up
+clear variables
+addpath('../../duff')
+addpath('../../utils')
+
+% Initialize problem instance and set options
+prob_init = coco_prob();
+
+eps = 0.1;
+m = 1;
+c = 2;
+k = 2;
+alpha = 5;
+A = 5;
+om = 1;
+
+p0 = [m; eps*c; k; eps*alpha; eps*A; om];
+
+% parameter names
+pnames = {'m', 'c', 'k', 'alpha', 'A', 'om'};
+
+% Initial Guess
+% Let Transients die out
+[~, x0]   = ode45(@(t,x) duff(x, p0), ...
+  [0 30*pi], [1; 0; 0]);
+
+% Initial Solution Guess
+[t0, x0]   = ode45(@(t,x) duff(x, p0), ...
+  [0 2*pi], [x0(end,1:3)']);
+
+% 'coll'-toolbox arguments
+coll_args = {@duff, @duff_dx, @duff_dp, ...
+  @duff_dxdx, @duff_dxdp, @duff_dpdp, ...
+  t0, x0, p0};
+
+% 'bvp'-toolbox arguments
+bvp_args = {@duff_bc, @duff_bc_du, @duff_bc_dudu};
+%% Step 1:
+%  Continue in the the initial position until it is a
+%  maximum (corresponds to initial velocity = 0)
+
+run_name = 'set_v0';
+
+if not(coco_exist(run_name, 'run'))
+  prob = coco_set(prob_init, 'coll', 'NTST', 30);
+  prob = coco_set(prob, 'cont', 'PtMX', 120);
+%   prob = coco_set(prob, 'coll', 'TOL', 100);
+  prob = ode_isol2bvp(prob, '', coll_args{:}, pnames, bvp_args{:});
+  [data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
+  maps = data.coll_seg.maps;
+  x0_coco = uidx(maps.x0_idx);
+  prob = coco_add_pars(prob, 'R', x0_coco(1), 'R', 'inactive');
+  prob = coco_add_pars(prob, 'v0', x0_coco(2), 'v0', 'inactive');
+  
+  prob = coco_add_event(prob, 'MAX', 'v0', 0);
+  % Find point where velocity is zero so that R is the peak
+  % of the trajectory.
+  bd = coco(prob, run_name, [], 1, {'R', 'v0'});  
+else
+  bd = coco_bd_read(run_name);
+end
+%% Step 2
+%  Frequency sweep to find points that will be used to
+%  locate approximate peak and approximate folds
+
+last_run_name = run_name;
+run_name = 'sweep';
+if not(coco_exist(run_name, 'run'))
+  labs = coco_bd_labs(bd, 'MAX');
+  prob = coco_set(prob_init, 'cont', 'PtMX', 200);
+%   prob = coco_set(prob, 'coll', 'TOL', 100);
+  prob = ode_bvp2bvp(prob, '', last_run_name, labs(2));
+  
+  [data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
+  maps = data.coll_seg.maps;
+  x0 = uidx(maps.x0_idx);
+  prob = coco_add_pars(prob, 'R', x0(1), 'R', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'v0', x0(2), 'v0', 'inactive');
+
+  prob = coco_add_event(prob, 'PK', 'R', 1.4);
+  prob = coco_add_event(prob, 'OM', 'om', 1.67);
+  
+  bd = coco(prob, run_name, [], 1, {'om', 'R'}, {[0.1, 20]});
+else
+  bd = coco_bd_read(run_name);
+end
+
+%% Step 3
+%  Drive the frequency difference in PK values to be 1e-2
+last_run_name = run_name;
+run_name = 'pk';
+
+if not(coco_exist(run_name, 'run'))
+  pk_labs = coco_bd_labs(bd, 'PK');
+  prob = prob_init();
+  prob = coco_set(prob, 'coll', 'NTST', 30);
+  % Add peaks back to continuation problem structure
+  prob = ode_bvp2bvp(prob, 'PK1', last_run_name, '', pk_labs(1));
+  bvp_data = coco_get_func_data(prob, 'PK1.bvp', 'data');
+
+  [pk1_data, pk1_uidx] = coco_get_func_data(prob, 'PK1.bvp.seg1.coll', 'data', 'uidx');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+  prob = coco_add_pars(prob, 'R.PK1', pk1_x0(1), 'R.PK1', 'active');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'v0.PK1', pk1_x0(2), 'v0.PK1', 'inactive');
+
+  prob = ode_coll2coll(prob, 'PK2', last_run_name, 'bvp.seg1', pk_labs(2));
+
+  % Boundary conditions for PK2
+  [pk2_data, pk2_uidx] = coco_get_func_data(prob, 'PK2.coll', 'data', 'uidx');
+  pk2_maps = pk2_data.coll_seg.maps;
+
+  args = pk2_uidx([pk2_maps.T0_idx; pk2_maps.T_idx; pk2_maps.x0_idx; ...
+    pk2_maps.x1_idx; pk2_maps.p_idx]);
+  prob = coco_add_func(prob, 'PK2.bvp', @duff_bc_caf, ...
+    @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+    'zero', 'uidx', args);
+  
+  % Give PK2 Frequency a name.
+  prob = coco_add_pars(prob, 'pk2.om', pk2_uidx(pk2_maps.p_idx(end)), 'pk2.om', 'active');  
+  
+  pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+  prob = coco_add_pars(prob, 'R.PK2', pk2_x0(1), 'R.PK2', 'active');
+  
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'v0.PK2', pk2_x0(2), 'v0.PK2', 'inactive');
+
+  % Glue Parameters together (except forcing frequency)
+  prob = coco_add_glue(prob, 'par_glue', pk2_uidx(pk2_maps.p_idx(1:5)), ...
+    pk1_uidx(pk1_maps.p_idx(1:5)));
+
+  prob = coco_add_glue(prob, 'R.glue', pk2_x0(1), pk1_x0(1));
+
+  % Parameterize frequency difference
+  prob = coco_add_func(prob, 'om_diff', @udiff, @udiff_dU, @udiff_dUdU, ...
+    [], 'inactive', 'eps_om', 'uidx', [pk2_uidx(pk2_maps.p_idx(6)), ...
+    pk1_uidx(pk1_maps.p_idx(6))]);
+
+  prob = coco_add_event(prob, 'PK', 'eps_om', 1e-2);
+
+  % Drive forcing frequency difference lower
+  bd = coco(prob, run_name, [], 1, {'eps_om', 'om'}, {[0.9e-4, 0.2]});
+else
+  bd = coco_bd_read(run_name);
+end
+
+%% Step 4a
+%  Collect PK1, PK2, OM1, OM2, OM3 in one problem and
+%  reduce distance in Amplitude between OM1 and OM3 to a small value
+last_run_name = run_name;
+run_name = 'fold_find_top';
+
+if not(coco_exist(run_name, 'run'))
+  pk_labs = coco_bd_labs(bd, 'PK');
+
+  swp_bd = coco_bd_read('sweep');
+  om_labs = coco_bd_labs(swp_bd, 'OM');
+  prob = coco_set(prob_init, 'coll', 'NTST', 30);
+  prob = ode_bvp2bvp(prob, 'PK1', last_run_name, pk_labs(1));
+  bvp_data = coco_get_func_data(prob, 'PK1.bvp', 'data');
+
+  [pk1_data, pk1_uidx] = coco_get_func_data(prob, 'PK1.bvp.seg1.coll', 'data', 'uidx');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+  prob = coco_add_pars(prob, 'PK1.R', pk1_x0(1), 'R', 'active');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'PK1.v0', pk1_x0(2), 'PK1.v0', 'inactive');
+
+  prob = ode_coll2coll(prob, 'PK2', last_run_name, pk_labs(1));
+
+  % Boundary conditions for PK2
+  [pk2_data, pk2_uidx] = coco_get_func_data(prob, 'PK2.coll', 'data', 'uidx');
+  pk2_maps = pk2_data.coll_seg.maps;
+
+  args = pk2_uidx([pk2_maps.T0_idx; pk2_maps.T_idx; pk2_maps.x0_idx; ...
+    pk2_maps.x1_idx; pk2_maps.p_idx]);
+  prob = coco_add_func(prob, 'PK2.bvp', @duff_bc_caf, ...
+    @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+    'zero', 'uidx', args);
+
+  pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'PK2.v0', pk2_x0(2), 'PK2.v0', 'inactive');
+
+  % Glue Parameters together (except forcing frequency)
+  prob = coco_add_glue(prob, 'par_glue', pk2_uidx(pk2_maps.p_idx(1:5)), ...
+    pk1_uidx(pk1_maps.p_idx(1:5)));
+  prob = coco_add_glue(prob, 'PK.R.glue', pk2_x0(1), pk1_x0(1));
+
+  % Parameterize frequency difference
+  prob = coco_add_func(prob, 'om_diff', @udiff, @udiff_dU, @udiff_dUdU, ...
+    [], 'inactive', 'eps_om', 'uidx', [pk2_uidx(pk2_maps.p_idx(6)), ...
+    pk1_uidx(pk1_maps.p_idx(6))]);
+
+%   om_data = cell(1,3);
+%   om_uidx = cell(1,3);
+  om_maps = cell(1,3);
+  om_x0 = cell(1,3);
+  for i=1:3
+    prob = ode_coll2coll(prob, strcat('OM', int2str(i)), 'sweep', 'bvp.seg1', om_labs(i));
+    % Boundary conditions for OMi
+    [om_data{i}, om_uidx{i}] = coco_get_func_data(prob, ...
+      coco_get_id(strcat('OM', int2str(i)),'coll'), 'data', 'uidx');
+    om_maps{i} = om_data{i}.coll_seg.maps;
+
+    args = om_uidx{i}([om_maps{i}.T0_idx; om_maps{i}.T_idx; om_maps{i}.x0_idx; ...
+      om_maps{i}.x1_idx; om_maps{i}.p_idx]);
+    om_bvp_id = coco_get_id(strcat('OM', int2str(i)),'bvp');
+    prob = coco_add_func(prob, om_bvp_id, @duff_bc_caf, ...
+      @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+      'zero', 'uidx', args);
+
+    % Maintain velocity constraint
+    
+    v0name = coco_get_id(strcat('OM', int2str(i)),'v0');
+    om_x0{i} = om_uidx{i}(om_maps{i}.x0_idx);
+    Rname = coco_get_id(strcat('OM', int2str(i)),'R');
+    prob = coco_add_pars(prob, Rname, om_x0{i}(1), Rname, 'active');
+    prob = coco_add_pars(prob, v0name, om_x0{i}(2), v0name, 'inactive');
+    omname = ['OM', int2str(i), '.om'];
+    prob = coco_add_pars(prob, omname, om_uidx{1}(om_maps{1}.p_idx(6)), omname, 'active');
+
+    % Glue Parameters together
+    if i > 1
+      % The fold approximants share all parameter values.
+      % They differ only in response amplitude 
+      % {'OM1.R', 'OM2.R', 'OM3.R'}
+
+      gluename = ['OM', int2str(i), '.to.OM1'];
+      prob = coco_add_glue(prob, gluename, ...
+        om_uidx{1}(om_maps{1}.p_idx), ...
+        om_uidx{i}(om_maps{i}.p_idx));
+
+      if i == 2
+        % Parameterize Response Amplitude Difference between
+        % adjacent OM orbits
+        rdiffname = ['eps_R', int2str(i-1)];
+        prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+          [], 'inactive', rdiffname, 'uidx', [om_x0{i-1}(1), om_x0{i}(1)]);
+      end
+
+    else
+      gluename = ['OM', int2str(i), '.to.PK1'];
+      prob = coco_add_glue(prob, gluename, ...
+        pk2_uidx(pk2_maps.p_idx(1:5)), ...
+        om_uidx{1}(om_maps{1}.p_idx(1:5)));
+    end
+  end
+
+  prob = coco_add_event(prob, 'UZ', 'eps_R1', 1e-2);
+  
+  bd = coco(prob, run_name, [], 1, {'eps_R1', 'OM1.om', 'om', 'eps_om'}, [-0.1, 0.4]);
+else
+  bd = coco_bd_read(run_name);
+end
+
+%% Step 4b
+%  Collect PK1, PK2, OM1, OM2, OM3 in one problem and
+%  reduce distance in Amplitude to a small value
+last_run_name = 'fold_find_top';
+run_name = 'fold_find_btm';
+
+if not(coco_exist(run_name, 'run'))
+  bd   = coco_bd_read(last_run_name);
+  labs = coco_bd_labs(bd, 'UZ');
+  lab = labs(1);
+
+  prob = coco_set(prob_init, 'coll', 'NTST', 30);
+  prob = ode_bvp2bvp(prob, 'PK1', last_run_name, lab);
+  bvp_data = coco_get_func_data(prob, 'PK1.bvp', 'data');
+
+  [pk1_data, pk1_uidx] = coco_get_func_data(prob, 'PK1.bvp.seg1.coll', 'data', 'uidx');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'PK1.v0', pk1_x0(2), 'PK1.v0', 'inactive');
+  prob = coco_add_pars(prob, 'PK1.R', pk1_x0(1), 'R', 'inactive');
+  
+  prob = ode_coll2coll(prob, 'PK2', last_run_name, lab);
+
+  % Boundary conditions for PK2
+  [pk2_data, pk2_uidx] = coco_get_func_data(prob, 'PK2.coll', 'data', 'uidx');
+  pk2_maps = pk2_data.coll_seg.maps;
+
+  args = pk2_uidx([pk2_maps.T0_idx; pk2_maps.T_idx; pk2_maps.x0_idx; ...
+    pk2_maps.x1_idx; pk2_maps.p_idx]);
+  prob = coco_add_func(prob, 'PK2.bvp', @duff_bc_caf, ...
+    @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+    'zero', 'uidx', args);
+  pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'PK2.v0', pk2_x0(2), 'PK2.v0', 'inactive');
+
+  % Glue Parameters together (except forcing frequency)
+  prob = coco_add_glue(prob, 'par_glue', pk2_uidx(pk2_maps.p_idx(1:5)), ...
+    pk1_uidx(pk1_maps.p_idx(1:5)));
+  prob = coco_add_glue(prob, 'PK.R.glue', pk2_x0(1), pk1_x0(1));
+
+  % Parameterize frequency difference
+  prob = coco_add_func(prob, 'om_diff', @udiff, @udiff_dU, @udiff_dUdU, ...
+    [], 'inactive', 'eps_om', 'uidx', [pk2_uidx(pk2_maps.p_idx(6)), ...
+    pk1_uidx(pk1_maps.p_idx(6))]);
+
+  for i=1:3
+    OMi_name = strcat('OM', int2str(i));
+    sol = coll_read_solution(OMi_name, last_run_name, lab);
+
+    coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+    prob = ode_isol2bvp(prob, OMi_name, ...
+      coll_args{:}, {}, bvp_args{:});
+
+    [om_data{i}, om_uidx{i}] = coco_get_func_data(prob, ...
+      coco_get_id(strcat('OM', int2str(i)),'bvp', 'seg1', 'coll'), 'data', 'uidx');
+    om_maps{i} = om_data{i}.coll_seg.maps;
+
+    % Maintain velocity constraint
+    v0name = coco_get_id(strcat('OM', int2str(i)),'v0');
+    om_x0{i} = om_uidx{i}(om_maps{i}.x0_idx);
+    prob = coco_add_pars(prob, v0name, om_x0{i}(2), v0name, 'inactive');
+    Rname = coco_get_id(strcat('OM', int2str(i)),'R');
+    prob = coco_add_pars(prob, Rname, om_x0{i}(1), Rname, 'active');    
+    
+    omname = ['OM', int2str(i), '.om'];
+    prob = coco_add_pars(prob, omname, om_uidx{1}(om_maps{1}.p_idx(6)), omname, 'active');
+
+    % Glue Parameters together
+    if i > 1
+      % The fold approximants share all parameter values.
+      % They differ only in response amplitude 
+      % {'OM1.R', 'OM2.R', 'OM3.R'}
+
+      gluename = ['OM', int2str(i), '.to.OM1'];
+      prob = coco_add_glue(prob, gluename, ...
+        om_uidx{1}(om_maps{1}.p_idx), ...
+        om_uidx{i}(om_maps{i}.p_idx));
+
+      % Parameterize Response Amplitude Difference
+      rdiffname = ['eps_R', int2str(i-1)];
+      prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, ...
+        @udiff_dUdU, [], 'inactive', rdiffname, ...
+        'uidx', [om_x0{i-1}(1), om_x0{i}(1)]);
+
+    else
+      gluename = ['OM', int2str(i), '.to.PK1'];
+      prob = coco_add_glue(prob, gluename, ...
+        pk2_uidx(pk2_maps.p_idx(1:5)), ...
+        om_uidx{1}(om_maps{1}.p_idx(1:5)));
+      
+      prob = coco_add_pars(prob, 'OM.om', ...
+        om_uidx{1}(om_maps{1}.p_idx(6)), 'OM.om');
+      
+    end
+  end
+
+  prob = coco_add_event(prob, 'UZ', 'eps_R2', 1e-2);
+
+  bd = coco(prob, run_name, [], 1, {'eps_R2', 'A', 'om', ...
+    'OM.om', 'R', 'eps_R1', 'eps_om', 'PK1.R', 'PK2.R', 'OM1.R'}, [-0.1, 1]);
+else
+  bd = coco_bd_read(run_name);
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_deterministic.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_deterministic.m
new file mode 100644
index 0000000000000000000000000000000000000000..00123aec1342d4ebe2cc38090fd47794218a9541
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_deterministic.m
@@ -0,0 +1,489 @@
+%% Problem Set-up
+addpath('../../duff')
+addpath('../../utils')
+
+% Initialize problem instance and set options
+prob_init = coco_prob();
+
+prob_init = coco_set(prob_init, 'coll', 'NTST', 15);
+% prob_init = coco_set(prob_init, 'cont', 'PtMX', 200);%, 'h_max', 10);
+% prob_init = coco_set(prob_init, 'cont', 'PtMX', 100, ...
+%   'h', 0.5, 'almax', 30, 'h_max', 1000);
+% prob_init = coco_set(prob_init, 'cont', 'NAdapt', 5, 'NPR', 10);
+
+% % Temporarily allow really bad results for some checking of
+% % Jacobians.
+% prob_init = coco_set(prob_init, 'coll', 'TOL', 5);
+eps = 0.1;
+m = 1;
+c = 2;
+k = 2;
+alpha = 5;
+A = 5;
+om = 1;
+
+p0 = [m; eps*c; k; eps*alpha; eps*A; om];
+
+% parameter names
+pnames = {'m', 'c', 'k', 'alpha', 'A', 'om'};
+
+%% Step 1:
+%  Continue in the the initial position until it is a
+%  maximum (corresponds to initial velocity = 0)
+
+run_name = 'set_v0';
+
+if not(coco_exist(run_name, 'run'))
+  % Let Transients die out
+  [~, x0]   = ode45(@(t,x) duff(x, p0), ...
+    [0 24*pi], [1; 0; 0]);
+ 
+  % Initial Solution Guess
+  [t0, x0]   = ode45(@(t,x) duff(x, p0), ...
+    [0 2*pi], [x0(end,1:3)']);
+  
+  % 'coll'-toolbox arguments
+  coll_args = {@duff, @duff_dx, @duff_dp, ...
+    @duff_dxdx, @duff_dxdp, @duff_dpdp, ...
+    t0, x0, p0};
+
+  % 'bvp'-toolbox arguments
+  bvp_args = {@duff_bc, @duff_bc_du, @duff_bc_dudu};
+
+  prob = ode_isol2bvp(prob_init, '', coll_args{:}, pnames, bvp_args{:});
+  [data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
+  maps = data.coll_seg.maps;
+  x0_coco = uidx(maps.x0_idx);
+  prob = coco_add_pars(prob, 'R', x0_coco(1), 'R', 'inactive');
+  prob = coco_add_pars(prob, 'v0', x0_coco(2), 'v0', 'inactive');
+  
+  prob = coco_add_event(prob, 'MAX', 'v0', 0);
+  % Find point where velocity is zero so that R is the peak
+  % of the trajectory.
+  bd = coco(prob, run_name, [], 1, {'R', 'v0'});  
+else
+  bd = coco_bd_read(run_name);
+end
+%% Step 2
+%  Frequency sweep to find points that will be used to
+%  locate approximate peak and approximate folds
+
+last_run_name = run_name;
+run_name = 'sweep';
+if not(coco_exist(run_name, 'run'))
+  labs = coco_bd_labs(bd, 'MAX');
+  prob = coco_set(prob_init, 'cont', 'PtMX', 200, 'NAdapt', 1);
+  prob = ode_bvp2bvp(prob, '', last_run_name, labs(2));
+  
+  [data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
+  maps = data.coll_seg.maps;
+  x0 = uidx(maps.x0_idx);
+  prob = coco_add_pars(prob, 'R', x0(1), 'R', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'v0', x0(2), 'v0', 'inactive');
+
+  prob = coco_add_event(prob, 'PK', 'R', 1.42);
+  prob = coco_add_event(prob, 'OM', 'om', 1.67);
+  
+  bd = coco(prob, run_name, [], 1, {'om', 'R'}, {[0.1, 5]});
+else
+  bd = coco_bd_read(run_name);
+end
+
+%% Step 3
+%  Drive the frequency difference in PK values to be 1e-3
+last_run_name = run_name;
+run_name = 'pk';
+
+if not(coco_exist(run_name, 'run'))
+  pk_labs = coco_bd_labs(bd, 'PK');
+
+  % Add peaks back to continuation problem structure
+  prob = ode_bvp2bvp(prob_init, 'PK1', last_run_name, '', pk_labs(1));
+  bvp_data = coco_get_func_data(prob, 'PK1.bvp', 'data');
+
+  [pk1_data, pk1_uidx] = coco_get_func_data(prob, 'PK1.bvp.seg1.coll', 'data', 'uidx');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+  prob = coco_add_pars(prob, 'R.PK1', pk1_x0(1), 'R.PK1', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'v0.PK1', pk1_x0(2), 'v0.PK1', 'inactive');
+
+  prob = ode_coll2coll(prob, 'PK2', last_run_name, 'bvp.seg1', pk_labs(2));
+
+  % Boundary conditions for PK2
+  [pk2_data, pk2_uidx] = coco_get_func_data(prob, 'PK2.coll', 'data', 'uidx');
+  pk2_maps = pk2_data.coll_seg.maps;
+
+  args = pk2_uidx([pk2_maps.T0_idx; pk2_maps.T_idx; pk2_maps.x0_idx; ...
+    pk2_maps.x1_idx; pk2_maps.p_idx]);
+  prob = coco_add_func(prob, 'PK2.bvp', @duff_bc_caf, ...
+    @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+    'zero', 'uidx', args);
+
+  % Give PK2 Frequency a name.
+  prob = coco_add_pars(prob, 'pk2.om', pk2_uidx(pk2_maps.p_idx(end)), 'pk2.om', 'inactive');
+
+
+  pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+  prob = coco_add_pars(prob, 'R.PK2', pk2_x0(1), 'R.PK2', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'v0.PK2', pk2_x0(2), 'v0.PK2', 'inactive');
+
+  % Glue Parameters together (except forcing frequency)
+  prob = coco_add_glue(prob, 'par_glue', pk2_uidx(pk2_maps.p_idx(1:5)), ...
+    pk1_uidx(pk1_maps.p_idx(1:5)));
+
+  prob = coco_add_glue(prob, 'R.glue', pk2_x0(1), pk1_x0(1));
+
+  % Parameterize frequency difference
+  prob = coco_add_func(prob, 'om_diff', @udiff, @udiff_dU, @udiff_dUdU, ...
+    [], 'inactive', 'om_diff', 'uidx', [pk2_uidx(pk2_maps.p_idx(6)), ...
+    pk1_uidx(pk1_maps.p_idx(6))]);
+
+  prob = coco_add_event(prob, 'PK', 'om_diff', 1e-4);
+
+  % Drive forcing frequency difference lower
+  bd = coco(prob, run_name, [], 1, {'om_diff', 'om', 'pk2.om', 'R.PK1', 'R.PK2'}, {[0.9e-4, 1.5e-1]});
+else
+  bd = coco_bd_read(run_name);
+end
+
+%% Step 4a
+%  Collect PK1, PK2, OM1, OM2, OM3 in one problem and
+%  reduce distance in Amplitude to a small value
+last_run_name = run_name;
+run_name = 'fold_find_top';
+
+if not(coco_exist(run_name, 'run'))
+  pk_labs = coco_bd_labs(bd, 'EP');
+
+  swp_bd = coco_bd_read('sweep');
+  om_labs = coco_bd_labs(swp_bd, 'OM');
+
+  prob = ode_bvp2bvp(prob_init, 'PK1', last_run_name, pk_labs(1));
+  bvp_data = coco_get_func_data(prob, 'PK1.bvp', 'data');
+
+  [pk1_data, pk1_uidx] = coco_get_func_data(prob, 'PK1.bvp.seg1.coll', 'data', 'uidx');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+  prob = coco_add_pars(prob, 'PK1.R', pk1_x0(1), 'PK1.R', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'PK1.v0', pk1_x0(2), 'PK1.v0', 'inactive');
+
+  prob = ode_coll2coll(prob, 'PK2', last_run_name, pk_labs(1));
+
+  % Boundary conditions for PK2
+  [pk2_data, pk2_uidx] = coco_get_func_data(prob, 'PK2.coll', 'data', 'uidx');
+  pk2_maps = pk2_data.coll_seg.maps;
+
+  args = pk2_uidx([pk2_maps.T0_idx; pk2_maps.T_idx; pk2_maps.x0_idx; ...
+    pk2_maps.x1_idx; pk2_maps.p_idx]);
+  prob = coco_add_func(prob, 'PK2.bvp', @duff_bc_caf, ...
+    @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+    'zero', 'uidx', args);
+
+  % Give PK2 Frequency a name.
+  prob = coco_add_pars(prob, 'pk2.om', pk2_uidx(pk2_maps.p_idx(end)), 'pk2.om', 'inactive');
+
+  pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+  prob = coco_add_pars(prob, 'PK2.R', pk2_x0(1), 'PK2.R', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'PK2.v0', pk2_x0(2), 'PK2.v0', 'inactive');
+
+  % Glue Parameters together (except forcing frequency)
+  prob = coco_add_glue(prob, 'par_glue', pk2_uidx(pk2_maps.p_idx(1:5)), ...
+    pk1_uidx(pk1_maps.p_idx(1:5)));
+  prob = coco_add_glue(prob, 'PK.R.glue', pk2_x0(1), pk1_x0(1));
+
+  % Parameterize frequency difference
+  prob = coco_add_func(prob, 'om_diff', @udiff, @udiff_dU, @udiff_dUdU, ...
+    [], 'inactive', 'om_diff', 'uidx', [pk2_uidx(pk2_maps.p_idx(6)), ...
+    pk1_uidx(pk1_maps.p_idx(6))]);
+
+  for i=1:3
+    prob = ode_coll2coll(prob, strcat('OM', int2str(i)), 'sweep', 'bvp.seg1', om_labs(i));
+    % Boundary conditions for OMi
+    [om_data{i}, om_uidx{i}] = coco_get_func_data(prob, ...
+      coco_get_id(strcat('OM', int2str(i)),'coll'), 'data', 'uidx');
+    om_maps{i} = om_data{i}.coll_seg.maps;
+
+    args = om_uidx{i}([om_maps{i}.T0_idx; om_maps{i}.T_idx; om_maps{i}.x0_idx; ...
+      om_maps{i}.x1_idx; om_maps{i}.p_idx]);
+    om_bvp_id = coco_get_id(strcat('OM', int2str(i)),'bvp');
+    prob = coco_add_func(prob, om_bvp_id, @duff_bc_caf, ...
+      @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+      'zero', 'uidx', args);
+
+    % Maintain velocity constraint
+    Rname = coco_get_id(strcat('OM', int2str(i)),'R');
+    v0name = coco_get_id(strcat('OM', int2str(i)),'v0');
+    om_x0{i} = om_uidx{i}(om_maps{i}.x0_idx);
+    prob = coco_add_pars(prob, Rname, om_x0{i}(1), Rname, 'inactive');
+    prob = coco_add_pars(prob, v0name, om_x0{i}(2), v0name, 'inactive');
+
+    % Glue Parameters together
+    if i > 1
+      % The fold approximants share all parameter values.
+      % They differ only in response amplitude 
+      % {'OM1.R', 'OM2.R', 'OM3.R'}
+
+      gluename = ['OM', int2str(i), '.to.OM1'];
+      prob = coco_add_glue(prob, gluename, ...
+        om_uidx{1}(om_maps{1}.p_idx), ...
+        om_uidx{i}(om_maps{i}.p_idx));
+
+      % Parameterize Response Amplitude Difference
+      rdiffname = ['OM', int2str(i-1), 'R.minus.OM', int2str(i), 'R'];
+      prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+        [], 'inactive', rdiffname, 'uidx', [om_x0{i-1}(1), om_x0{i}(1)]);
+
+    else
+      gluename = ['OM', int2str(i), '.to.PK1'];
+      prob = coco_add_glue(prob, gluename, ...
+        pk2_uidx(pk2_maps.p_idx(1:5)), ...
+        om_uidx{1}(om_maps{1}.p_idx(1:5)));
+    end
+  end
+  prob = coco_add_pars(prob, 'OM1.om', om_uidx{1}(om_maps{1}.p_idx(6)), 'OM1.om', 'inactive');
+  
+  bd = coco(prob, run_name, [], 1, {'OM1R.minus.OM2R', 'OM1.om', 'OM2R.minus.OM3R', 'om', 'pk2.om', 'PK1.R', 'PK2.R', 'OM1.R', 'OM2.R', 'OM3.R'}, [1e-4, 3]);
+else
+  bd = coco_bd_read(run_name);
+end
+
+%% Step 4b
+%  Collect PK1, PK2, OM1, OM2, OM3 in one problem and
+%  reduce distance in Amplitude to a small value
+last_run_name = run_name;
+run_name = 'fold_clamp';
+
+if not(coco_exist(run_name, 'run'))
+  labs = coco_bd_labs(bd, 'EP');
+  prob = coco_set(prob_init, 'cont', 'NAdapt', 1);
+  prob = ode_bvp2bvp(prob, 'PK1', last_run_name, labs(1));
+  bvp_data = coco_get_func_data(prob, 'PK1.bvp', 'data');
+
+  [pk1_data, pk1_uidx] = coco_get_func_data(prob, 'PK1.bvp.seg1.coll', 'data', 'uidx');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+  prob = coco_add_pars(prob, 'PK1.R', pk1_x0(1), 'PK1.R', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'PK1.v0', pk1_x0(2), 'PK1.v0', 'inactive');
+
+  prob = ode_coll2coll(prob, 'PK2', last_run_name, labs(1));
+
+  % Boundary conditions for PK2
+  [pk2_data, pk2_uidx] = coco_get_func_data(prob, 'PK2.coll', 'data', 'uidx');
+  pk2_maps = pk2_data.coll_seg.maps;
+
+  args = pk2_uidx([pk2_maps.T0_idx; pk2_maps.T_idx; pk2_maps.x0_idx; ...
+    pk2_maps.x1_idx; pk2_maps.p_idx]);
+  prob = coco_add_func(prob, 'PK2.bvp', @duff_bc_caf, ...
+    @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+    'zero', 'uidx', args);
+
+  % Give PK2 Frequency a name.
+  prob = coco_add_pars(prob, 'pk2.om', pk2_uidx(pk2_maps.p_idx(end)), 'pk2.om', 'inactive');
+
+  pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+  prob = coco_add_pars(prob, 'PK2.R', pk2_x0(1), 'PK2.R', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'PK2.v0', pk2_x0(2), 'PK2.v0', 'inactive');
+
+  % Glue Parameters together (except forcing frequency)
+  prob = coco_add_glue(prob, 'par_glue', pk2_uidx(pk2_maps.p_idx(1:5)), ...
+    pk1_uidx(pk1_maps.p_idx(1:5)));
+  prob = coco_add_glue(prob, 'PK.R.glue', pk2_x0(1), pk1_x0(1));
+
+  % Parameterize frequency difference
+  prob = coco_add_func(prob, 'om_diff', @udiff, @udiff_dU, @udiff_dUdU, ...
+    [], 'inactive', 'om_diff', 'uidx', [pk2_uidx(pk2_maps.p_idx(6)), ...
+    pk1_uidx(pk1_maps.p_idx(6))]);
+
+  for i=1:3
+    prob = ode_coll2coll(prob, strcat('OM', int2str(i)), ...
+      last_run_name, labs(1));
+    % Boundary conditions for OMi
+    [om_data{i}, om_uidx{i}] = coco_get_func_data(prob, ...
+      coco_get_id(strcat('OM', int2str(i)),'coll'), 'data', 'uidx');
+    om_maps{i} = om_data{i}.coll_seg.maps;
+
+    args = om_uidx{i}([om_maps{i}.T0_idx; om_maps{i}.T_idx; om_maps{i}.x0_idx; ...
+      om_maps{i}.x1_idx; om_maps{i}.p_idx]);
+    om_bvp_id = coco_get_id(strcat('OM', int2str(i)),'bvp');
+    prob = coco_add_func(prob, om_bvp_id, @duff_bc_caf, ...
+      @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+      'zero', 'uidx', args);
+
+    % Maintain velocity constraint
+    Rname = coco_get_id(strcat('OM', int2str(i)),'R');
+    v0name = coco_get_id(strcat('OM', int2str(i)),'v0');
+    om_x0{i} = om_uidx{i}(om_maps{i}.x0_idx);
+    prob = coco_add_pars(prob, Rname, om_x0{i}(1), Rname, 'inactive');
+    prob = coco_add_pars(prob, v0name, om_x0{i}(2), v0name, 'inactive');
+
+    % Glue Parameters together
+    if i > 1
+      % The fold approximants share all parameter values.
+      % They differ only in response amplitude 
+      % {'OM1.R', 'OM2.R', 'OM3.R'}
+
+      gluename = ['OM', int2str(i), '.to.OM1'];
+      prob = coco_add_glue(prob, gluename, ...
+        om_uidx{1}(om_maps{1}.p_idx), ...
+        om_uidx{i}(om_maps{i}.p_idx));
+
+      % Parameterize Response Amplitude Difference
+      rdiffname = ['OM', int2str(i-1), 'R.minus.OM', int2str(i), 'R'];
+      prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+        [], 'inactive', rdiffname, 'uidx', [om_x0{i-1}(1), om_x0{i}(1)]);
+
+    else
+      gluename = ['OM', int2str(i), '.to.PK1'];
+      prob = coco_add_glue(prob, gluename, ...
+        pk2_uidx(pk2_maps.p_idx(1:5)), ...
+        om_uidx{1}(om_maps{1}.p_idx(1:5)));
+    end
+  end
+  prob = coco_add_pars(prob, 'OM1.om', om_uidx{1}(om_maps{1}.p_idx(6)), 'OM1.om', 'inactive');
+  
+  bd = coco(prob, run_name, [], 1, {'OM2R.minus.OM3R', 'A', 'OM1.om', 'om', 'pk2.om', 'PK1.R', 'PK2.R', 'OM1.R', 'OM2.R', 'OM3.R', 'OM1R.minus.OM2R'}, [1e-2, 3]);
+
+else
+  bd = coco_bd_read(run_name);
+end
+
+%% Step 4c
+%  Confirmation of the near-linear character of the
+%  frequency-response cuve
+
+last_run_name = run_name;
+swp_run_name = 'sweep2';
+if not(coco_exist(swp_run_name, 'run'))
+  labs = coco_bd_labs(bd, 'EP');
+  prob = ode_bvp2bvp(prob_init, '', last_run_name, 'PK1', labs(1));
+  
+  [data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
+  maps = data.coll_seg.maps;
+  x0 = uidx(maps.x0_idx);
+  prob = coco_add_pars(prob, 'R', x0(1), 'R', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'v0', x0(2), 'v0', 'inactive');
+  
+  bd_swp = coco(prob, swp_run_name, [], 1, {'om', 'R'}, {[0.1, 5]});
+  semilogx(cell2mat(bd_swp(2:end, 16)), cell2mat(bd_swp(2:end, 17)));
+else
+
+end
+
+%% Step 5
+last_run_name = run_name;
+run_name = 'pk_sweep';
+
+if not(coco_exist(run_name, 'run')) || true
+  labs = coco_bd_labs(bd, 'EP');
+  prob = coco_set(prob_init, 'cont', 'NAdapt', 1);
+  prob = coco_set(prob, 'cont', 'PtMX', 100);
+  prob = ode_bvp2bvp(prob, 'PK1', last_run_name, labs(1));
+  bvp_data = coco_get_func_data(prob, 'PK1.bvp', 'data');
+
+  [pk1_data, pk1_uidx] = coco_get_func_data(prob, 'PK1.bvp.seg1.coll', 'data', 'uidx');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+  prob = coco_add_pars(prob, 'PK1.R', pk1_x0(1), 'PK1.R', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'PK1.v0', pk1_x0(2), 'PK1.v0', 'inactive');
+
+  prob = ode_coll2coll(prob, 'PK2', last_run_name, labs(1));
+
+  % Boundary conditions for PK2
+  [pk2_data, pk2_uidx] = coco_get_func_data(prob, 'PK2.coll', 'data', 'uidx');
+  pk2_maps = pk2_data.coll_seg.maps;
+
+  args = pk2_uidx([pk2_maps.T0_idx; pk2_maps.T_idx; pk2_maps.x0_idx; ...
+    pk2_maps.x1_idx; pk2_maps.p_idx]);
+  prob = coco_add_func(prob, 'PK2.bvp', @duff_bc_caf, ...
+    @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+    'zero', 'uidx', args);
+
+  % Give PK2 Frequency a name.
+  prob = coco_add_pars(prob, 'PK2.om', pk2_uidx(pk2_maps.p_idx(end)), 'pk2.om', 'inactive');
+
+  pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+  prob = coco_add_pars(prob, 'PK2.R', pk2_x0(1), 'PK2.R', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'PK2.v0', pk2_x0(2), 'PK2.v0', 'inactive');
+
+  % Glue Parameters together (except forcing frequency)
+  prob = coco_add_glue(prob, 'par_glue', pk2_uidx(pk2_maps.p_idx(1:5)), ...
+    pk1_uidx(pk1_maps.p_idx(1:5)));
+  prob = coco_add_glue(prob, 'PK.R.glue', pk2_x0(1), pk1_x0(1));
+
+  % Parameterize frequency difference
+  prob = coco_add_func(prob, 'om_diff', @udiff, @udiff_dU, @udiff_dUdU, ...
+    [], 'inactive', 'om_diff', 'uidx', [pk2_uidx(pk2_maps.p_idx(6)), ...
+    pk1_uidx(pk1_maps.p_idx(6))]);
+
+  for i=1:3
+    prob = ode_coll2coll(prob, strcat('OM', int2str(i)), ...
+      last_run_name, labs(1));
+    % Boundary conditions for OMi
+    [om_data{i}, om_uidx{i}] = coco_get_func_data(prob, ...
+      coco_get_id(strcat('OM', int2str(i)),'coll'), 'data', 'uidx');
+    om_maps{i} = om_data{i}.coll_seg.maps;
+
+    args = om_uidx{i}([om_maps{i}.T0_idx; om_maps{i}.T_idx; om_maps{i}.x0_idx; ...
+      om_maps{i}.x1_idx; om_maps{i}.p_idx]);
+    om_bvp_id = coco_get_id(strcat('OM', int2str(i)),'bvp');
+    prob = coco_add_func(prob, om_bvp_id, @duff_bc_caf, ...
+      @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+      'zero', 'uidx', args);
+
+    % Maintain velocity constraint
+    Rname = coco_get_id(strcat('OM', int2str(i)),'R');
+    v0name = coco_get_id(strcat('OM', int2str(i)),'v0');
+    om_x0{i} = om_uidx{i}(om_maps{i}.x0_idx);
+    prob = coco_add_pars(prob, Rname, om_x0{i}(1), Rname, 'inactive');
+    prob = coco_add_pars(prob, v0name, om_x0{i}(2), v0name, 'inactive');
+
+    % Glue Parameters together
+    if i > 1
+      % The fold approximants share all parameter values.
+      % They differ only in response amplitude 
+      % {'OM1.R', 'OM2.R', 'OM3.R'}
+
+      gluename = ['OM', int2str(i), '.to.OM1'];
+      prob = coco_add_glue(prob, gluename, ...
+        om_uidx{1}(om_maps{1}.p_idx), ...
+        om_uidx{i}(om_maps{i}.p_idx));
+
+      % Parameterize Response Amplitude Difference
+      rdiffname = ['OM', int2str(i-1), 'R.minus.OM', int2str(i), 'R'];
+      prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+        [], 'inactive', rdiffname, 'uidx', [om_x0{i-1}(1), om_x0{i}(1)]);
+
+    else
+      gluename = ['OM', int2str(i), '.to.PK1'];
+      prob = coco_add_glue(prob, gluename, ...
+        pk2_uidx(pk2_maps.p_idx(1:5)), ...
+        om_uidx{1}(om_maps{1}.p_idx(1:5)));
+    end
+  end
+  prob = coco_add_pars(prob, 'OM1.om', om_uidx{1}(om_maps{1}.p_idx(6)), 'OM1.om', 'inactive');
+  
+  [uidx, data] = coco_get_func_data(prob, 'PK1.bvp.seg1.coll', 'uidx', 'data');
+  mk_idx = uidx(data.coll_seg.maps.p_idx([1,3]));
+%   prob = coco_add_func(prob, 'km_constraint', ...
+%     @km_const, @km_const_du, @km_const_dudu, [], ...
+%     'zero', 'uidx', mk_idx);
+  
+  bd = coco(prob, run_name, [], 1, {'PK1.R', 'om', 'A', 'OM1.om', 'PK2.om', 'PK2.R', 'OM1.R', 'OM2.R', 'OM3.R'});
+
+else
+  bd = coco_bd_read(run_name);
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_embeddable.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_embeddable.m
new file mode 100644
index 0000000000000000000000000000000000000000..d368e1dbae6571c034c6533bb711067d5471a09f
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_embeddable.m
@@ -0,0 +1,126 @@
+last_run_name = 'fold_find_btm';
+run_name = 'uq_nds';
+bd = coco_bd_read(last_run_name);
+labs = coco_bd_labs(bd, 'UZ');
+lab = labs(1);
+prob = coco_prob();
+prob = coco_set(prob, 'coll', 'NTST', 30);
+
+orbit_name = 'PK1';
+orbit_pnames = coco_get_id(orbit_name, pnames);
+pk1_bvp_sname = coco_get_id(orbit_name, 'bvp');
+pk1_coll_sname = coco_get_id(pk1_bvp_sname, 'seg1.coll');
+coll_name = 'PK1.bvp.seg1';
+sol = coll_read_solution(coll_name, last_run_name, lab);
+
+coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+bvp_args = {@duff_bc_v2, @duff_bc_v2_du, @duff_bc_v2_dudu};
+% 'uq'-toolbox arguments
+uq_args = {{orbit_pnames{4}}, {'Uniform'}, [[0.3, 0.7]], ...
+  {}};
+
+prob = uq_isol2bvp_sample(prob, 'PK1', ...
+  coll_args{:}, orbit_pnames, bvp_args{:}, uq_args{:});
+
+prob = uq_coll_add_response(prob, 'PK1', 'resp', 'bv', ...
+  @x10, @x10_du, @x10_dudu);
+
+seg2ndsid = coco_get_id(orbit_name, 'uq.s_par_glue');
+PK1_uq_data = coco_get_func_data(prob, seg2ndsid, 'data');
+
+PK1_loidx = coco_get_func_data(prob, coco_get_id(orbit_name, 'lo'), 'uidx');
+% PK1_loaidx = coco_get_adjt_data(prob, coco_get_id(orbit_name, 'lo'), 'axidx');
+
+PK1_upidx = coco_get_func_data(prob, coco_get_id(orbit_name, 'up'), 'uidx');
+% PK1_upaidx = coco_get_adjt_data(prob, coco_get_id(orbit_name, 'up'), 'axidx');
+
+orbit_name = 'PK2';
+orbit_pnames = coco_get_id(orbit_name, pnames);
+
+sol = coll_read_solution(orbit_name, last_run_name, lab);
+
+coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+uq_args = {{orbit_pnames{4}}, {'Uniform'}, [[0.3, 0.7]], ...
+  {}};
+
+prob = uq_isol2bvp_sample(prob, orbit_name, ...
+  coll_args{:}, orbit_pnames, bvp_args{:}, uq_args{:});
+
+seg2ndsid = coco_get_id(orbit_name, 'uq.s_par_glue');
+PK2_uq_data = coco_get_func_data(prob, seg2ndsid, 'data');
+
+PK2_loidx = coco_get_func_data(prob, coco_get_id(orbit_name, 'lo'), 'uidx');
+% PK2_loaidx = coco_get_adjt_data(prob, coco_get_id(orbit_name, 'lo'), 'axidx');
+
+PK2_upidx = coco_get_func_data(prob, coco_get_id(orbit_name, 'up'), 'uidx');
+% PK2_upaidx = coco_get_adjt_data(prob, coco_get_id(orbit_name, 'up'), 'axidx');
+
+
+% PK1 and PK2 share all parameters except forcing
+% frequency.  The nonlinear stiffness is (parameter 4) is
+% also omitted as it's now controlled by the uniform
+% distribution parameters.
+PK1_glue_par_idx = PK1_uq_data.s_idx{1};
+PK1_glue_par_idx = PK1_glue_par_idx([1:3,5]);
+PK1_glue_par_idx = [PK1_glue_par_idx; PK1_loidx; PK1_upidx];
+
+PK2_glue_par_idx = PK2_uq_data.s_idx{1};
+PK2_glue_par_idx = PK2_glue_par_idx([1:3,5]);
+PK2_glue_par_idx = [PK2_glue_par_idx; PK2_loidx; PK2_upidx];
+
+prob = coco_add_glue(prob, 'PK1_to_PK2_par_glue', ...
+  PK1_glue_par_idx, PK2_glue_par_idx);
+
+% pars_to_release = {orbit_pnames{[1:3,5]}};
+% pars_to_release = {pars_to_release{:}, 'lo.PK2.alpha', 'up.PK2.alpha'};
+
+% PK1_adj_glue_par_idx = cell2mat(PK1_uq_data.adj_s_idx);
+% PK1_adj_glue_par_idx = PK1_adj_glue_par_idx([1:3,5],:);
+% PK1_adj_glue_par_idx = PK1_adj_glue_par_idx(:);
+% PK1_adj_glue_par_idx = [PK1_adj_glue_par_idx; PK1_loaidx; PK1_upaidx];
+% 
+% PK2_adj_glue_par_idx = cell2mat(PK2_uq_data.adj_s_idx);
+% PK2_adj_glue_par_idx = PK2_adj_glue_par_idx([1:3,5],:);
+% PK2_adj_glue_par_idx = PK2_adj_glue_par_idx(:);
+% PK2_adj_glue_par_idx = [PK2_adj_glue_par_idx; PK2_loaidx; PK2_upaidx];
+% 
+% prob = coco_add_adjt(prob, 'PK1_to_PK2_par_glue', 'aidx', ...
+%   [PK1_adj_glue_par_idx; PK2_adj_glue_par_idx]);
+
+% orbit_name = 'OM1';
+% orbit_pnames = coco_get_id(orbit_name, pnames);
+% om1_coll_sname = coco_get_id(orbit_name, 'bvp.seg1');
+% sol = coll_read_solution(om1_coll_sname, last_run_name, lab);
+% 
+% coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+% uq_args = {{orbit_pnames{4}}, {'Uniform'}, [[0.3, 0.7]], ...
+%   {},'-add-adjt'};
+% 
+% prob = uq_isol2bvp_sample(prob, orbit_name, ...
+%   coll_args{:}, orbit_pnames, bvp_args{:}, uq_args{:});
+% 
+% orbit_name = 'OM2';
+% orbit_pnames = coco_get_id(orbit_name, pnames);
+% om1_coll_sname = coco_get_id(orbit_name, 'bvp.seg1');
+% sol = coll_read_solution(om1_coll_sname, last_run_name, lab);
+% 
+% coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+% uq_args = {{orbit_pnames{4}}, {'Uniform'}, [[0.3, 0.7]], ...
+%   {},'-add-adjt'};
+% 
+% prob = uq_isol2bvp_sample(prob, orbit_name, ...
+%   coll_args{:}, orbit_pnames, bvp_args{:}, uq_args{:});
+% 
+% orbit_name = 'OM3';
+% orbit_pnames = coco_get_id(orbit_name, pnames);
+% om1_coll_sname = coco_get_id(orbit_name, 'bvp.seg1');
+% sol = coll_read_solution(om1_coll_sname, last_run_name, lab);
+% 
+% coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+% uq_args = {{orbit_pnames{4}}, {'Uniform'}, [[0.3, 0.7]], ...
+%   {},'-add-adjt'};
+% 
+% prob = uq_isol2bvp_sample(prob, orbit_name, ...
+%   coll_args{:}, orbit_pnames, bvp_args{:}, uq_args{:});
+% 
+coco(prob, 'test', [], 0, {'PK1.resp.mean', 'PK1.resp.var', pars_to_release{:}})
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_fold_follow.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_fold_follow.m
new file mode 100644
index 0000000000000000000000000000000000000000..8fba83f0dbd03fbe6e8778a6309cfb64c8592058
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_fold_follow.m
@@ -0,0 +1,54 @@
+% Path to vector field, Jacobians, and Response Function
+addpath('../duff')
+addpath('../linode')
+
+% Initialize problem instance and set options
+prob_init = coco_prob();
+prob_init = coco_set(prob_init, 'ode', 'autonomous', false);
+prob_init = coco_set(prob_init, 'coll', 'NTST', 15, ...
+  'NCOL', 4);
+prob_init = coco_set(prob_init, 'cont', 'PtMX', 100, ...
+  'h', 0.5, 'almax', 30, 'h_max', 1000);
+
+% Let Transients die out
+p0 = [3;0.46365;1];
+[~, x0]   = ode45(@(t,x) linode_het(t, x, p0), ...
+  [0 6*pi], [1; 0]);
+
+% Initial Solution Guess
+[t0, x0]   = ode45(@(t,x) linode_het(t, x, p0), ...
+  [0 2*pi], [x0(end,:)']);
+
+% 'coll'-toolbox arguments
+coll_args = {@linode_het, ...
+  @linode_het_DFDX, @linode_het_DFDP, @linode_het_DFDT, ...
+  @linode_het_DFDXDX, @linode_het_DFDXDP, ...
+  @linode_het_DFDPDP, @linode_het_DFDXDT, ...
+  @linode_het_DFDTDP, @linode_het_DFDTDT, ...
+  t0, x0, p0};
+
+% parameter names
+pnames = {'k','phi', 'om'};
+
+% 'bvp'-toolbox arguments
+bvp_args = {@fbc_x10, @Jbc_x10, @dJbc_x10};
+
+prob = ode_isol2bvp(prob_init, '', coll_args{:}, pnames, bvp_args{:});
+[data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
+maps = data.coll_seg.maps;
+x0 = uidx(maps.x0_idx);
+prob = coco_add_pars(prob, 'A', x0(1), 'A', 'inactive');
+
+bd = coco(prob, 'test', [], 1, {'A', 'phi', 'om', 'k', 'atlas.test.FP'});
+
+%%
+FPLab = coco_bd_labs(bd, 'FP');
+
+prob = prob_init;
+prob = ode_bvp2bvp(prob, '', 'test', FPLab(1));
+[data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
+maps = data.coll_seg.maps;
+x0 = uidx(maps.x0_idx);
+prob = coco_add_pars(prob, 'A', x0(1), 'A', 'inactive');
+prob = coco_xchg_pars(prob, 'k', 'atlas.test.FP');
+bd = coco(prob, 'test', [], 1, {'A', 'phi', 'om', 'k', 'atlas.test.FP'});
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis.m
new file mode 100644
index 0000000000000000000000000000000000000000..bf0876bebbf750bb19fae5d56b7ee2a717a9170f
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis.m
@@ -0,0 +1,23 @@
+%% Starting Point Build
+% Generate the starting point for uncertainty
+% quantification.  Result is six orbits, two on either side
+% of the maximum frequency response, two on either side of
+% the top fold point and two on either side of the bottom
+% fold point.
+demo_curve_build
+
+%% PCE Integration Nodes
+% Find integration nodes used in the PCE
+demo_uq_nds
+
+%% KM Sweep
+% Sweep in robust objective function value with k and m
+% released in search of a Fold Point and corresponding
+% Branch Point
+demo_for_thesis_fpbp
+
+%% Eta 1 to zero
+% From the branch point, continue along the secondary
+% direction where the lagrange multipliers can take on
+% non-trivial value and drive d.obj to 1
+demo_for_thesis_dobj_to_1
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_PCE_convergence.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_PCE_convergence.m
new file mode 100644
index 0000000000000000000000000000000000000000..8943039d72f7d274b23931eb9d95cb6ef29febcd
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_PCE_convergence.m
@@ -0,0 +1,536 @@
+%% Starting Point Build
+% Generate the starting point for uncertainty
+% quantification.  Result is six orbits, two on either side
+% of the maximum frequency response, two on either side of
+% the top fold point and two on either side of the bottom
+% fold point.
+demo_curve_build
+
+%% PCE Integration Nodes
+% Find integration nodes used in the PCE
+
+for M=1:6
+  for Pt=2:6
+uq_data = demo_uq_nds_func(M,Pt);
+
+last_run_name = 'uq_nds_M_P_vary';
+run_name = 'pce_convergence';
+add_adjt=0;
+stochastic_damping=1;
+
+% Initialize problem data structure
+prob = coco_prob();
+prob = coco_set(prob, 'coll', 'NTST', 30);
+
+% Previous run found points to be used for PCE numerical
+% integration.  Read that data and identify those points.
+bd = coco_bd_read(last_run_name);
+uq_labs = coco_bd_labs(bd, 'UQ');
+
+% Sample counter
+sample_idx = 0;
+om_counter = 0;
+% Stochastic parameter indices
+pk1_par_idx = cell(1, uq_data.nsamples);
+% Response function initial guesses
+r_igs = cell(1, uq_data.nsamples);
+% Response function input indices
+r_idx = cell(1, uq_data.nsamples);
+% Stochastic parameter adjoint indices
+pk1_par_aidx = cell(1, uq_data.nsamples);
+% Response function input adjoint indices
+r_aidx = cell(1, uq_data.nsamples);
+
+% drdiffnames = cell(2*uq_data.nsamples, 1);
+
+% Build samples in this for loop
+for lab=uq_labs
+  sample_idx = sample_idx + 1;
+  % Sample name prefix
+  sample_id = strcat('s', int2str(sample_idx));
+  
+  %% PK1
+  %  Read data from previous run
+  coll_name = 'PK1.bvp.seg1';
+  sol = coll_read_solution(coll_name, last_run_name, lab);
+  coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};  
+  
+  %  PK1 sample names for current run
+  pk1_sname = coco_get_id(sample_id, 'PK1');
+  pk1_bvp_sname = coco_get_id(pk1_sname, 'bvp');
+  pk1_coll_sname = coco_get_id(pk1_bvp_sname, 'seg1.coll');
+
+  % bvp_args defined in demo_curve_build
+  bvp_pnames = {};%uq_get_sample_par_names(pnames, sample_idx);
+  
+  prob = ode_isol2bvp(prob, pk1_sname, ...
+    coll_args{:}, bvp_pnames, bvp_args{:});
+  % Adjoints
+  if add_adjt
+    prob = adjt_isol2bvp(prob, pk1_sname);
+  end
+
+  if sample_idx == 1
+    % The deterministic parameters are added when building
+    % the first sample of PK1
+    s_pnames = {pnames{1}, 'c.1', pnames{[3,4]}, 'A.1', pnames{6}};
+
+    % Keep the data, uidx, and u0 for s1.PK1 for later
+    % gluing conditions
+    [pk1_s1_data, pk1_s1_uidx] = ...
+      coco_get_func_data(prob, pk1_coll_sname, ...
+      'data', 'uidx');
+    pk1_s1_maps = pk1_s1_data.coll_seg.maps;
+
+    s1_par_fname = coco_get_id(sample_id, 'pars');
+    if stochastic_damping
+      s1_par_pname = s_pnames([1,3,4]);
+      s1_par_idx = pk1_s1_uidx(pk1_s1_maps.p_idx([1,3,4]));
+      prob = coco_add_pars(prob, s1_par_fname, ...
+        s1_par_idx, s1_par_pname);    
+    else
+      s1_par_pname = s_pnames(1:3);
+      s1_par_idx = pk1_s1_uidx(pk1_s1_maps.p_idx(1:3));
+      prob = coco_add_pars(prob, s1_par_fname, ...
+        s1_par_idx, s1_par_pname);
+    end
+    
+%     prob = coco_add_pars(prob, 'test', ...
+%       pk1_s1_uidx(pk1_s1_maps.x0_idx(1)), 'R');
+
+    % Adjoints
+    if add_adjt
+      [s1_pk1_fdata, s1_pk1_aidx] = ...
+        coco_get_adjt_data(prob, ...
+        pk1_coll_sname, 'data', 'axidx');
+      s1_pk1_opt = s1_pk1_fdata.coll_opt;
+
+      if stochastic_damping
+        prob = coco_add_adjt(prob, s1_par_fname, ...
+        coco_get_id('d', s1_par_pname), ...
+        'aidx', s1_pk1_aidx(s1_pk1_opt.p_idx([1,3,4])), ...
+        'l0', zeros(3,1));
+      else
+        prob = coco_add_adjt(prob, s1_par_fname, ...
+          coco_get_id('d', s1_par_pname), ...
+          'aidx', s1_pk1_aidx(s1_pk1_opt.p_idx(1:3)), ...
+          'l0', zeros(3,1));
+      end
+      
+%       prob = coco_add_adjt(prob, 'test', ...
+%         'd.R', 'aidx', ...
+%         s1_pk1_aidx(s1_pk1_opt.x0_idx(1)), 'l0', 0);
+    end
+  else
+    % Glue deterministic parameters together
+    [pk1_si_data, pk1_si_uidx] = ...
+      coco_get_func_data(prob, pk1_coll_sname, ...
+                         'data', 'uidx');
+    pk1_si_maps = pk1_si_data.coll_seg.maps;
+    if stochastic_damping
+      s1_p_idx = pk1_s1_uidx(pk1_s1_maps.p_idx([1,3,4]));
+      si_p_idx = pk1_si_uidx(pk1_si_maps.p_idx([1,3,4]));
+    else
+      s1_p_idx = pk1_s1_uidx(pk1_s1_maps.p_idx(1:3));
+      si_p_idx = pk1_si_uidx(pk1_si_maps.p_idx(1:3));
+    end
+
+    glue_name = coco_get_id(sample_id, 'glue_to_s1');
+    prob = coco_add_glue(prob, glue_name, s1_p_idx, ...
+      si_p_idx);
+
+    % Adjoints
+    if add_adjt
+
+      [si_pk1_fdata, si_pk1_aidx] = coco_get_adjt_data(prob, ...
+        pk1_coll_sname, 'data', 'axidx');
+      si_pk1_opt = si_pk1_fdata.coll_opt;
+
+      % For glue
+      if stochastic_damping
+        s1_p_aidx = s1_pk1_aidx(s1_pk1_opt.p_idx([1,3,4]));
+        si_p_aidx = si_pk1_aidx(si_pk1_opt.p_idx([1,3,4]));
+      else
+        s1_p_aidx = s1_pk1_aidx(s1_pk1_opt.p_idx(1:3));
+        si_p_aidx = si_pk1_aidx(si_pk1_opt.p_idx(1:3));
+      end
+
+      prob = coco_add_adjt(prob, glue_name, ...
+        'aidx', [s1_p_aidx; si_p_aidx]);
+    end
+  end
+  
+  [pk1_data, pk1_uidx, pk1_u0] = ...
+    coco_get_func_data(prob, pk1_coll_sname, ...
+    'data', 'uidx', 'u0');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+  
+  pk1_par_idx{sample_idx} = pk1_uidx(pk1_maps.p_idx);
+  r_igs{sample_idx} = pk1_u0(pk1_maps.x0_idx(1));
+  r_idx{sample_idx} = pk1_uidx(pk1_maps.x0_idx(1));
+
+%   % Damping names
+%   si_c_fname = coco_get_id(sample_id, 'c');
+%   si_c_pname = coco_get_id('c', int2str(sample_idx));
+%   si_c_idx = pk1_uidx(pk1_maps.p_idx(2));
+%   prob = coco_add_pars(prob, si_c_fname, ...
+%     si_c_idx, si_c_pname, 'inactive');
+  
+  % Forcing amplitude names
+  si_A_fname = coco_get_id(sample_id, 'A');
+  si_A_pname = coco_get_id('A', int2str(sample_idx));
+  si_A_idx = pk1_uidx(pk1_maps.p_idx(5));
+  prob = coco_add_pars(prob, si_A_fname, ...
+    si_A_idx, si_A_pname, 'inactive');
+  
+  % Forcing frequency names
+  si_om_fname = coco_get_id(sample_id, 'om');
+  si_om_pname = coco_get_id('om', int2str(sample_idx));
+  si_om_idx = pk1_uidx(pk1_maps.p_idx(6));
+  prob = coco_add_pars(prob, si_om_fname, ...
+    si_om_idx, si_om_pname, 'inactive');
+
+  % Velocity constraint for PK1
+  pk1_v0_sname = coco_get_id(pk1_sname, 'v0');
+  prob = coco_add_pars(prob, pk1_v0_sname, pk1_x0(2), ...
+    pk1_v0_sname, 'inactive');
+  
+  if add_adjt
+    [pk1_adata, pk1_aidx] = coco_get_adjt_data(prob, ...
+      pk1_coll_sname, 'data', 'axidx');
+    pk1_opt = pk1_adata.coll_opt;
+    
+    pk1_par_aidx{sample_idx} = pk1_aidx(pk1_opt.p_idx);
+    r_aidx{sample_idx} = pk1_aidx(pk1_opt.x0_idx(1)); 
+
+%     % Damping
+%     prob = coco_add_adjt(prob, si_c_fname, ...
+%       coco_get_id('d', si_c_pname), ...
+%       'aidx', pk1_aidx(pk1_opt.p_idx(2)), ...
+%       'l0', 0);
+    
+    % Forcing Amplitude
+    prob = coco_add_adjt(prob, si_A_fname, ...
+      coco_get_id('d', si_A_pname), ...
+      'aidx', pk1_aidx(pk1_opt.p_idx(5)), ...
+      'l0', 0);  
+    
+    % Forcing frequency
+    prob = coco_add_adjt(prob, si_om_fname, ...
+      coco_get_id('d', si_om_pname), ...
+      'aidx', pk1_aidx(pk1_opt.p_idx(6)), ...
+      'l0', 0);
+
+    % Velocity constraint
+    dv10_sname = coco_get_id('d', pk1_v0_sname);
+    prob = coco_add_adjt(prob, pk1_v0_sname, ...
+      dv10_sname, ...
+      'aidx', pk1_aidx(pk1_opt.x0_idx(2)), ...
+      'l0', 0);
+  end
+  
+  %% PK2
+  % Read data from previous run.  PK2 was added with
+  % coll2coll in the previous run, so it doesn't have the
+  % bvp.seg1 identifiers.
+  coll_name = 'PK2';
+  sol = coll_read_solution(coll_name, last_run_name, lab);
+  
+  %  PK2 sample names for current run
+  pk2_sname = coco_get_id(sample_id, 'PK2');
+  coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+  prob = ode_isol2bvp(prob, pk2_sname, ...
+    coll_args{:}, {}, bvp_args{:});
+
+  % PK2 was added with isol2bvp in this run, so reading the
+  % data requires the bvp identifiers.
+  pk2_coll_sname = coco_get_id(pk2_sname, 'bvp', 'seg1', 'coll');
+
+  [pk2_data, pk2_uidx] = coco_get_func_data(prob, ...
+    pk2_coll_sname, 'data', 'uidx');
+  pk2_maps = pk2_data.coll_seg.maps;
+  pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+
+  % Velocity constraint for PK2
+  pk2_v0_sname = coco_get_id(pk2_sname, 'v0');
+  prob = coco_add_pars(prob, pk2_v0_sname, pk2_x0(2), ...
+    pk2_v0_sname, 'inactive');
+
+  % Glue Parameters together (except forcing frequency)
+  parglue_sname = coco_get_id(sample_id, ...
+    'par_glue_PK2_to_PK1');
+  prob = coco_add_glue(prob, parglue_sname, ...
+    pk2_uidx(pk2_maps.p_idx(1:5)), ...
+    pk1_uidx(pk1_maps.p_idx(1:5)));
+  
+  pk_r_glue_sname = coco_get_id(sample_id, ...
+    'R_glue_to_PK1');
+  prob = coco_add_glue(prob, pk_r_glue_sname, ...
+    pk2_x0(1), pk1_x0(1));
+
+  % Lock in the frequency difference
+  pk_om_diff_sname = coco_get_id(sample_id, ...
+    'PK_om_diff');
+
+  prob = coco_add_func(prob, pk_om_diff_sname, ...
+    @udiff, @udiff_dU, @udiff_dUdU, [], ...
+    'inactive', pk_om_diff_sname, 'uidx', ...
+    [pk2_uidx(pk2_maps.p_idx(6)), ...
+     pk1_uidx(pk1_maps.p_idx(6))]);
+
+  % Adjoints
+  if add_adjt
+    % ode
+    prob = adjt_isol2bvp(prob, pk2_sname);
+    [pk2_fdata, pk2_aidx] = coco_get_adjt_data(prob, ...
+      pk2_coll_sname, 'data', 'axidx');
+    pk2_opt = pk2_fdata.coll_opt;
+
+    % velocity constraint
+    dv20_sname = coco_get_id('d', pk2_v0_sname);
+    prob = coco_add_adjt(prob, pk2_v0_sname, ...
+      dv20_sname, ...
+      'aidx', pk2_aidx(pk2_opt.x0_idx(2)));
+
+    % glue
+    prob = coco_add_adjt(prob, parglue_sname, ...
+      'aidx', [pk2_aidx(pk2_opt.p_idx(1:5)); ...
+      pk1_aidx(pk1_opt.p_idx(1:5))]);
+
+    prob = coco_add_adjt(prob, pk_r_glue_sname, ...
+      'aidx', [pk2_aidx(pk2_opt.x0_idx(1)); ...
+      pk1_aidx(pk1_opt.x0_idx(1))]);
+    
+    pk_om_diff_dpname = coco_get_id('d', pk_om_diff_sname);
+    pk_om_diff_dpnames{sample_idx} = pk_om_diff_dpname;  
+    
+    % om constraint
+    prob = coco_add_adjt(prob, pk_om_diff_sname, ...
+      pk_om_diff_dpname, ...
+      'aidx', [pk2_aidx(pk2_opt.p_idx(6)), ...
+      pk1_aidx(pk1_opt.p_idx(6))]);
+
+  end
+  %% OMs
+  % Build OM orbits for the sample in a for loop
+  om_fdata = cell(3,1);
+  om_aidx = cell(3,1);
+  om_opt = cell(3,1);
+  om_data = cell(3,1);
+  om_uidx = cell(3,1);
+  om_maps = cell(3,1);
+  om_x0 = cell(3,1);
+  om_x0a = cell(3,1);
+  
+  for om_idx=1:3
+    om_id = strcat('OM', int2str(om_idx));
+    om_sname = coco_get_id(sample_id, om_id);
+    om_seg_name = coco_get_id(om_id, 'bvp', 'seg1');
+    sol = coll_read_solution(om_seg_name, last_run_name, lab);
+
+    coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+    prob = ode_isol2bvp(prob, om_sname, ...
+      coll_args{:}, {}, bvp_args{:});
+
+    if add_adjt
+      prob = adjt_isol2bvp(prob, om_sname);
+    end
+    
+    om_coll_sname = coco_get_id(om_sname, 'bvp', 'seg1', 'coll');
+    [om_data{om_idx}, om_uidx{om_idx}] = coco_get_func_data(prob, ...
+      om_coll_sname, 'data', 'uidx');
+    om_maps{om_idx} = om_data{om_idx}.coll_seg.maps;
+
+    % Maintain velocity constraint
+    v0sname = coco_get_id(sample_id, ['OM', int2str(om_idx)],'v0');
+    om_x0{om_idx} = om_uidx{om_idx}(om_maps{om_idx}.x0_idx);
+    prob = coco_add_pars(prob, v0sname, om_x0{om_idx}(2), v0sname, ...
+      'inactive');
+    
+    if add_adjt
+      [om_fdata{om_idx}, om_aidx{om_idx}] = coco_get_adjt_data(prob, ...
+        om_coll_sname, 'data', 'axidx');
+      om_opt{om_idx} = om_fdata{om_idx}.coll_opt;
+      om_x0a{om_idx} = om_aidx{om_idx}(om_opt{om_idx}.x0_idx);
+
+      dv0sname = coco_get_id('d', v0sname);
+      prob = coco_add_adjt(prob, v0sname, dv0sname, ...
+        'aidx', om_x0a{om_idx}(2));
+    end
+
+    % Glue Parameters together
+    if om_idx > 1
+      % The fold approximants share all parameter values.
+      % They differ only in response amplitude 
+      gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+        int2str(om_idx), '_to_OM1']);
+
+      prob = coco_add_glue(prob, gluename, ...
+        om_uidx{1}(om_maps{1}.p_idx), ...
+        om_uidx{om_idx}(om_maps{om_idx}.p_idx));
+
+      % Parameterize Response Amplitude Difference
+      rdiffname = ['OM', int2str(om_idx-1), 'R_minus_OM', int2str(om_idx), 'R'];
+      rdiffname = coco_get_id(sample_id, rdiffname);
+      prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+        [], 'inactive', rdiffname, 'uidx', [om_x0{om_idx-1}(1), om_x0{om_idx}(1)]);
+      
+      if add_adjt
+        prob = coco_add_adjt(prob, gluename, ...
+          'aidx', [om_aidx{1}(om_opt{1}.p_idx); ...
+          om_aidx{om_idx}(om_opt{om_idx}.p_idx)]);
+
+        om_counter = om_counter + 1;
+        drdiffname = coco_get_id('d', rdiffname);
+        drdiffnames{om_counter} = drdiffname;
+        prob = coco_add_adjt(prob, rdiffname, drdiffname, ...
+          'aidx', [om_x0a{om_idx-1}(1), om_x0a{om_idx}(1)]);
+      end
+
+    else
+      gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+        int2str(om_idx), '_to_PK1']);
+
+      prob = coco_add_glue(prob, gluename, ...
+        pk1_uidx(pk1_maps.p_idx(1:5)), ...
+        om_uidx{1}(om_maps{1}.p_idx(1:5)));
+      
+      omomname = coco_get_id(sample_id, coco_get_id(om_id, 'om'));
+      prob = coco_add_pars(prob, omomname, ...
+        om_uidx{om_idx}(om_maps{om_idx}.p_idx(6)), ...
+        omomname, 'inactive');
+      
+      if add_adjt
+        prob = coco_add_adjt(prob, gluename, ...
+          'aidx', [pk1_aidx(pk1_opt.p_idx(1:5)); ...
+          om_aidx{1}(om_opt{1}.p_idx(1:5))]);
+
+        domomname = coco_get_id('d', omomname);
+        prob = coco_add_adjt(prob, omomname, domomname, ...
+                'aidx', om_aidx{om_idx}(om_opt{om_idx}.p_idx(6)));
+      end
+    end
+  end
+end
+
+psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.Pt, uq_data.spdists);
+uq_data.wtd_psi_mat = psi_mat*diag(uq_data.wts);
+uq_data.s_idx = pk1_par_idx;
+if add_adjt
+  uq_data.adj_s_idx = pk1_par_aidx;
+end
+uq_data.addadjt=add_adjt;
+prob = uq_add_sample_nodes(prob, uq_data);
+% Final data structure for a UQ sample is stored in the
+% parameter glue function
+uq_data = coco_get_func_data(prob, 'PK1.uq.s_par_glue', 'data');
+
+igs = zeros(uq_data.nsamples, 1);
+idx = zeros(1, uq_data.nsamples);
+for i=1:uq_data.nsamples
+  igs(i) = r_igs{i};
+  idx(i) = [r_idx{i}];
+end
+
+alpha_ig = uq_data.wtd_psi_mat*igs;
+response_id = 'resp';
+prob = coco_add_func(prob, response_id, ...
+  @resp_pce, @resp_pce_dU, @resp_pce_dUdU, ...
+  uq_data, 'zero', 'uidx', idx(:), 'u0', alpha_ig);
+
+if add_adjt
+  aidx = zeros(1, uq_data.nsamples);
+  for i=1:uq_data.nsamples
+    aidx(i) = [r_aidx{i}];
+  end
+
+  prob = coco_add_adjt(prob, response_id, ...
+    'aidx', aidx(:), 'l0', zeros(size(alpha_ig)), ...
+    'tl0', zeros(size(alpha_ig)));
+end
+
+alpha_idx = coco_get_func_data(prob, response_id, 'uidx');
+alpha_idx = alpha_idx(end-uq_data.Nt+1:end);
+
+if add_adjt
+  alpha_aidx = coco_get_adjt_data(prob, response_id, 'axidx');
+  alpha_aidx = alpha_aidx(end-uq_data.Nt+1:end);
+end
+
+% Mean Zero Function
+mean_id = coco_get_id(response_id, 'pce_mean');
+prob = coco_add_func(prob, mean_id, ...
+  @uq_pce_mean, @uq_pce_mean_dU, @uq_pce_mean_dUdU, ...
+  uq_data, 'zero', 'uidx', alpha_idx, 'u0', alpha_ig(1));
+
+if add_adjt  
+  prob = coco_add_adjt(prob, mean_id, 'aidx', ...
+    alpha_aidx, 'l0', 0);
+end
+
+% Variance Zero Function
+var_id = coco_get_id(response_id, 'pce_variance');
+prob = coco_add_func(prob, var_id, ...
+  @uq_pce_variance, @uq_pce_variance_dU, @uq_pce_variance_dUdU,...
+  uq_data, 'zero', 'uidx', alpha_idx, 'u0', sum(alpha_ig(2:end).^2));
+
+if add_adjt
+  prob = coco_add_adjt(prob, var_id, 'aidx', ...
+    alpha_aidx, 'l0', 0);
+end
+
+obj_id = 'obj';
+mean_idx = coco_get_func_data(prob, mean_id, 'uidx');
+var_idx = coco_get_func_data(prob, var_id, 'uidx');
+
+prob = coco_add_func(prob, obj_id, ...
+  @obj, @obj_du, @obj_dudu, [], ...
+  'inactive', obj_id, 'uidx', ...
+  [mean_idx(end); var_idx(end)]);
+
+if add_adjt
+  dobj_id = coco_get_id('d', obj_id);
+  mean_aidx = coco_get_adjt_data(prob, mean_id, 'axidx');  
+  var_aidx = coco_get_adjt_data(prob, var_id, 'axidx');
+  prob = coco_add_adjt(prob, obj_id, dobj_id, ...
+    'aidx', [mean_aidx(end); var_aidx(end)]);
+end
+
+[uidx, data] = coco_get_func_data(prob, 's1.PK1.bvp.seg1.coll', 'uidx', 'data');
+mk_idx = uidx(data.coll_seg.maps.p_idx([1,3]));
+
+prob = coco_add_func(prob, 'km_constraint', ...
+  @km_const, @km_const_du, @km_const_dudu, [], ...
+  'zero', 'uidx', mk_idx);
+
+if add_adjt
+  [aidx, fdata] = coco_get_adjt_data(prob, ...
+    's1.PK1.bvp.seg1.coll', 'axidx', 'data');
+  mk_aidx = aidx(fdata.coll_opt.p_idx([1,3]));
+
+  prob = coco_add_adjt(prob, 'km_constraint', 'aidx', ...
+    mk_aidx);
+end
+
+num_samples = uq_data.nsamples;
+
+omnames = uq_get_sample_par_names('om', 1:num_samples);
+Anames = uq_get_sample_par_names('A', 1:num_samples);
+
+% Mean Continuation Parameter
+mean_par_id = coco_get_id(response_id, 'mean');
+mean_idx = coco_get_func_data(prob, mean_id, 'uidx');
+mean_name = coco_get_id(response_id, 'mean');
+prob = coco_add_pars(prob, mean_par_id, mean_idx(end), mean_name);  
+
+% Variance Parameter
+var_par_id = coco_get_id(response_id, 'variance');
+var_idx = coco_get_func_data(prob, var_id, 'uidx');
+var_name = coco_get_id(response_id, 'var');
+prob = coco_add_pars(prob, var_par_id, var_idx(end), var_name);  
+
+bd = coco(prob, ['pce_convergence_M_',int2str(M),'_P_',int2str(Pt)], [], 0, ...
+  {'obj', 'k', 'm', mean_name, var_name, omnames{:}, Anames{:}, 's1.OM1.om', 's2.OM1.om', 's3.OM1.om', 's4.OM1.om', 's5.OM1.om', 's6.OM1.om'});
+  end
+end
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_dobj_to_1.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_dobj_to_1.m
new file mode 100644
index 0000000000000000000000000000000000000000..83683936d63ffea82525574fcb9687290c7c989c
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_dobj_to_1.m
@@ -0,0 +1,540 @@
+last_run_name = 'uq_sweep';
+run_name = 'uq_dobj_to_1';
+add_adjt=1;
+
+% Initialize problem data structure
+prob = coco_prob();
+prob = coco_set(prob, 'coll', 'NTST', 30);
+prob = coco_set(prob, 'cont', 'PtMX', 50);
+prob = coco_set(prob, 'cont', 'h', 5, 'h_min', 1e-5, 'h_max', 1e5);
+prob = coco_set(prob, 'corr', 'TOL', 1e-5);
+prob = coco_set(prob, 'corr', 'ItNW', 30);
+% % For testing only
+% prob = coco_set(prob, 'coll', 'TOL', 100);
+
+% Previous run located a fold point coincident with a
+% branch point.
+bd = coco_bd_read(last_run_name);
+BPlabs = coco_bd_labs(bd, 'BP');
+BPlab = BPlabs(2);
+
+om_counter = 0;
+% Stochastic parameter indices
+s_idx = cell(1, uq_data.nsamples);
+% Response function initial guesses
+r_igs = cell(1, uq_data.nsamples);
+% Response function input indices
+r_idx = cell(1, uq_data.nsamples);
+% Stochastic parameter adjoint indices
+adj_s_idx = cell(1, uq_data.nsamples);
+% Response function input adjoint indices
+r_aidx = cell(1, uq_data.nsamples);
+% Cell array for OM orbit names
+om_sname = cell(1,3);
+
+for sample_idx=1:uq_data.nsamples
+
+  sample_id = strcat('s', int2str(sample_idx));
+  pk1_sname = coco_get_id(sample_id, 'PK1');
+  pk2_sname = coco_get_id(sample_id, 'PK2');
+  om_sname{1} = coco_get_id(sample_id, 'OM1');
+  om_sname{2} = coco_get_id(sample_id, 'OM2');
+  om_sname{3} = coco_get_id(sample_id, 'OM3');
+
+  prob = ode_BP2bvp(prob, pk1_sname, last_run_name, BPlab);
+  prob = ode_BP2bvp(prob, pk2_sname, last_run_name, BPlab);
+  prob = ode_BP2bvp(prob, om_sname{1}, last_run_name, BPlab);
+  prob = ode_BP2bvp(prob, om_sname{2}, last_run_name, BPlab);
+  prob = ode_BP2bvp(prob, om_sname{3}, last_run_name, BPlab);
+  
+  adjt_args = struct();
+  if add_adjt
+    adjt_args.run = last_run_name;
+    adjt_args.lab = BPlab;
+    adjt_chart = coco_read_solution(last_run_name, BPlab, 'chart');
+    cdata = coco_get_chart_data(adjt_chart, 'lsol');
+
+    prob = adjt_BP2bvp(prob, pk1_sname, last_run_name, BPlab);
+    prob = adjt_BP2bvp(prob, pk2_sname, last_run_name, BPlab);
+    prob = adjt_BP2bvp(prob, om_sname{1}, last_run_name, BPlab);
+    prob = adjt_BP2bvp(prob, om_sname{2}, last_run_name, BPlab);
+    prob = adjt_BP2bvp(prob, om_sname{3}, last_run_name, BPlab);
+  end
+  %% PK1
+  pk1_coll_sname = coco_get_id(pk1_sname, 'bvp', ...
+    'seg1', 'coll');
+  % Peak 1 Information
+  [pk1_data, pk1_uidx, pk1_u0] = ...
+    coco_get_func_data(prob, pk1_coll_sname, ...
+    'data', 'uidx', 'u0');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+  if add_adjt
+      [pk1_fdata, pk1_aidx] = coco_get_adjt_data(prob, ...
+        pk1_coll_sname, 'data', 'axidx');
+      pk1_opt = pk1_fdata.coll_opt;
+  end
+
+  if sample_idx == 1
+    % Name the parameters
+    par_fname = coco_get_id(sample_id, 'pars');
+    par_pname = pnames([1,3,4]);
+    par_idx = pk1_uidx(pk1_maps.p_idx([1,3,4]));
+    prob = coco_add_pars(prob, par_fname, ...
+      par_idx, par_pname);    
+
+    % Store first sample's info for glue
+    s1_pk1_data = pk1_data;
+    s1_pk1_uidx = pk1_uidx;
+    s1_pk1_maps = pk1_maps;
+
+    % Adjoints
+    if add_adjt
+      [chart, lidx] = coco_read_adjoint(par_fname, ...
+        last_run_name, BPlab, 'chart', 'lidx');
+
+      prob = coco_add_adjt(prob, par_fname, ...
+      coco_get_id('d', par_pname), ...
+      'aidx', pk1_aidx(pk1_opt.p_idx([1,3,4])), ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+
+      s1_pk1_fdata = pk1_fdata;
+      s1_pk1_aidx  = pk1_aidx;
+      s1_pk1_opt   = pk1_opt;
+
+      adj_s_idx{sample_idx} = pk1_aidx(pk1_opt.p_idx);
+      r_aidx{sample_idx} = pk1_aidx(pk1_opt.x0_idx(1));
+    end
+  else
+    % Glue deterministic parameters together
+    s1_p_idx = s1_pk1_uidx(s1_pk1_maps.p_idx([1,3,4]));
+    p_idx = pk1_uidx(pk1_maps.p_idx([1,3,4]));
+
+    glue_name = coco_get_id(sample_id, 'glue_to_s1');
+    prob = coco_add_glue(prob, glue_name, s1_p_idx, p_idx);
+
+    % Adjoints
+    if add_adjt
+      % For glue
+      [chart, lidx] = coco_read_adjoint(glue_name, ...
+        last_run_name, BPlab, 'chart', 'lidx');
+      s1_p_aidx = s1_pk1_aidx(s1_pk1_opt.p_idx([1,3,4]));
+      p_aidx = pk1_aidx(pk1_opt.p_idx([1,3,4]));
+      
+      prob = coco_add_adjt(prob, glue_name, ...
+        'aidx', [s1_p_aidx; p_aidx], 'l0', chart.x, ...
+        'tl0', cdata.v(lidx));
+
+      adj_s_idx{sample_idx} = pk1_aidx(sj_pk1_opt.p_idx);
+      r_aidx{sample_idx} = pk1_aidx(sj_pk1_opt.x0_idx(1));
+    end
+  end
+
+  s_idx{sample_idx} = pk1_uidx(pk1_maps.p_idx);
+  r_igs{sample_idx} = pk1_u0(pk1_maps.x0_idx(1));
+  r_idx{sample_idx} = pk1_uidx(pk1_maps.x0_idx(1));
+
+  % Forcing amplitude names
+  si_A_fname = coco_get_id(sample_id, 'A');
+  si_A_pname = coco_get_id('A', int2str(sample_idx));
+  si_A_idx = pk1_uidx(pk1_maps.p_idx(5));
+  prob = coco_add_pars(prob, si_A_fname, ...
+    si_A_idx, si_A_pname, 'inactive');
+  
+  % Forcing frequency names
+  si_om_fname = coco_get_id(sample_id, 'om');
+  si_om_pname = coco_get_id('om', int2str(sample_idx));
+  si_om_idx = pk1_uidx(pk1_maps.p_idx(6));
+  prob = coco_add_pars(prob, si_om_fname, ...
+    si_om_idx, si_om_pname, 'inactive');
+
+  % Maintain velocity constraint (could also be done with a
+  % boundary condition)
+  pk1_v0_sname = coco_get_id(pk1_sname, 'v0');
+  prob = coco_add_pars(prob, pk1_v0_sname, pk1_x0(2), ...
+    pk1_v0_sname, 'inactive');
+
+  % Adjoint
+  if add_adjt
+    
+    [pk1_fdata, pk1_aidx] = coco_get_adjt_data(prob, ...
+      pk1_coll_sname, 'data', 'axidx');
+    sj_pk1_opt = pk1_fdata.coll_opt;
+    
+    [chart, lidx] = coco_read_adjoint(si_A_fname, ...
+      last_run_name, BPlab, 'chart', 'lidx');
+    dA_sname = coco_get_id('d', si_A_pname);
+    prob = coco_add_adjt(prob, si_A_fname, ...
+      dA_sname, ...
+      'aidx', pk1_aidx(pk1_opt.p_idx(5)), ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+    
+    [chart, lidx] = coco_read_adjoint(si_om_fname, ...
+      last_run_name, BPlab, 'chart', 'lidx');
+    dom_sname = coco_get_id('d', si_om_pname);
+    prob = coco_add_adjt(prob, si_om_fname, ...
+      dom_sname, ...
+      'aidx', pk1_aidx(pk1_opt.p_idx(6)), ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+    
+    [chart, lidx] = coco_read_adjoint(pk1_v0_sname, ...
+      last_run_name, BPlab, 'chart', 'lidx');
+    dv10_sname = coco_get_id('d', pk1_v0_sname);
+    prob = coco_add_adjt(prob, pk1_v0_sname, ...
+      dv10_sname, ...
+      'aidx', pk1_aidx(pk1_opt.x0_idx(2)), ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+  end
+  %% PK2
+  % Maintain velocity constraint (could also be done with a
+  % boundary condition)
+  pk2_coll_sname = coco_get_id(pk2_sname, 'bvp', ...
+    'seg1', 'coll');
+  % Peak 2 Information
+  [pk2_data, pk2_uidx] = coco_get_func_data(prob, ...
+    pk2_coll_sname, 'data', 'uidx');
+  pk2_maps = pk2_data.coll_seg.maps;
+  pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+  
+  pk2_v0_sname = coco_get_id(pk2_sname, 'v0');
+  prob = coco_add_pars(prob, pk2_v0_sname, pk2_x0(2), ...
+    pk2_v0_sname, 'inactive');
+  
+  % Glue Parameters together (except forcing frequency)
+  parglue_sname = coco_get_id(sample_id, ...
+    'par_glue_PK2_to_PK1');
+  prob = coco_add_glue(prob, parglue_sname, ...
+    pk2_uidx(pk2_maps.p_idx(1:5)), ...
+    pk1_uidx(pk1_maps.p_idx(1:5)));
+
+  pk_r_glue_sname = coco_get_id(sample_id, ...
+    'R_glue_to_PK1');
+  prob = coco_add_glue(prob, pk_r_glue_sname, ...
+    pk2_x0(1), pk1_x0(1));
+
+  % Lock in the frequency difference
+  pk_om_diff_sname = coco_get_id(sample_id, ...
+    'PK_om_diff');
+  prob = coco_add_func(prob, pk_om_diff_sname, ...
+    @udiff, @udiff_dU, @udiff_dUdU, [], ...
+    'inactive', pk_om_diff_sname, 'uidx', ...
+    [pk2_uidx(pk2_maps.p_idx(6)), ...
+     pk1_uidx(pk1_maps.p_idx(6))]);
+
+  % Adjoints
+  if add_adjt
+    [pk2_fdata, pk2_aidx] = coco_get_adjt_data(prob, ...
+      pk2_coll_sname, 'data', 'axidx');
+    pk2_opt = pk2_fdata.coll_opt;
+    % velocity constraint
+    [chart, lidx] = coco_read_adjoint(pk2_v0_sname, ...
+      last_run_name, BPlab, 'chart', 'lidx');
+
+    dv20_sname = coco_get_id('d', pk2_v0_sname);
+    prob = coco_add_adjt(prob, pk2_v0_sname, ...
+      dv20_sname, ...
+      'aidx', pk2_aidx(pk2_opt.x0_idx(2)),...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+
+    % glue
+    [chart, lidx] = coco_read_adjoint(parglue_sname, ...
+      last_run_name, BPlab, 'chart', 'lidx');
+
+    prob = coco_add_adjt(prob, parglue_sname, ...
+      'aidx', [pk2_aidx(pk2_opt.p_idx(1:5)); ...
+      pk1_aidx(pk1_opt.p_idx(1:5))], ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+
+    [chart, lidx] = coco_read_adjoint(pk_r_glue_sname, ...
+      last_run_name, BPlab, 'chart', 'lidx');
+
+    prob = coco_add_adjt(prob, pk_r_glue_sname, ...
+      'aidx', [pk2_aidx(pk2_opt.x0_idx(1)); ...
+      pk1_aidx(pk1_opt.x0_idx(1))], ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+
+    % om constraint
+    [chart, lidx] = coco_read_adjoint(pk_om_diff_sname, ...
+      last_run_name, BPlab, 'chart', 'lidx');
+
+    prob = coco_add_adjt(prob, pk_om_diff_sname, ...
+      coco_get_id('d', pk_om_diff_sname), ...
+      'aidx', [pk2_aidx(pk2_opt.p_idx(6)), ...
+      pk1_aidx(pk1_opt.p_idx(6))], ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+
+  end
+  %% OM 
+  om_data = cell(1,3);
+  om_uidx = cell(1,3);
+  om_maps = cell(1,3);
+  om_x0 = cell(1,3);
+  om_fdata = cell(1,3);
+  om_aidx = cell(1,3);
+  om_opt = cell(1,3);
+  om_x0a = cell(1,3);
+
+  for om_idx=1:3
+    om_coll_sname = coco_get_id(om_sname{om_idx}, 'bvp', ...
+      'seg1', 'coll');
+    [om_data{om_idx}, om_uidx{om_idx}] = coco_get_func_data(prob, ...
+      om_coll_sname, 'data', 'uidx');
+    om_maps{om_idx} = om_data{om_idx}.coll_seg.maps;
+
+    % Maintain velocity constraint
+    v0sname = coco_get_id(om_sname{om_idx},'v0');
+    om_x0{om_idx} = om_uidx{om_idx}(om_maps{om_idx}.x0_idx);
+    prob = coco_add_pars(prob, v0sname, om_x0{om_idx}(2), ...
+      v0sname, 'inactive');    
+
+    if add_adjt
+      [om_fdata{om_idx}, om_aidx{om_idx}] = coco_get_adjt_data(prob, ...
+        om_coll_sname, 'data', 'axidx');
+      om_opt{om_idx} = om_fdata{om_idx}.coll_opt;
+      om_x0a{om_idx} = om_aidx{om_idx}(om_opt{om_idx}.x0_idx);
+
+      [chart, lidx] = coco_read_adjoint(pk_om_diff_sname, ...
+        last_run_name, BPlab, 'chart', 'lidx');
+
+      dv0sname = coco_get_id('d', v0sname);
+      prob = coco_add_adjt(prob, v0sname, dv0sname, ...
+        'aidx', om_x0a{om_idx}(2),...
+        'l0', chart.x, 'tl0', cdata.v(lidx));
+    end
+    
+    % Glue Parameters together
+    if om_idx > 1
+      % The fold approximants share all parameter values.
+      % They differ only in response amplitude 
+      gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+        int2str(om_idx), '_to_OM1']);
+
+      prob = coco_add_glue(prob, gluename, ...
+        om_uidx{1}(om_maps{1}.p_idx), ...
+        om_uidx{om_idx}(om_maps{om_idx}.p_idx));
+
+      % Parameterize Response Amplitude Difference
+      rdiffname = ['OM', int2str(om_idx-1), 'R_minus_OM', int2str(om_idx), 'R'];
+      rdiffname = coco_get_id(sample_id, rdiffname);
+      prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+        [], 'inactive', rdiffname, 'uidx', [om_x0{om_idx-1}(1), om_x0{om_idx}(1)]);
+
+      if add_adjt
+        [chart, lidx] = ...
+          coco_read_adjoint(gluename, ...
+          last_run_name, BPlab, 'chart', 'lidx');
+
+        prob = coco_add_adjt(prob, gluename, ...
+          'aidx', [om_aidx{1}(om_opt{1}.p_idx), ...
+          om_aidx{om_idx}(om_opt{om_idx}.p_idx)], ...
+          'l0', chart.x, 'tl0', cdata.v(lidx));
+
+        [chart, lidx] = ...
+          coco_read_adjoint(rdiffname, ...
+          last_run_name, BPlab, 'chart', 'lidx');
+        
+        om_counter = om_counter + 1;
+        drdiffname = coco_get_id('d', rdiffname);
+        drdiffnames{om_counter} = drdiffname;
+        prob = coco_add_adjt(prob, rdiffname, drdiffname, ...
+          'aidx', [om_x0a{om_idx-1}(1), om_x0a{om_idx}(1)], ...
+          'l0', chart.x, 'tl0', cdata.v(lidx));
+      end
+
+    else
+      gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+        int2str(om_idx), '_to_PK1']);
+
+      prob = coco_add_glue(prob, gluename, ...
+        pk1_uidx(pk1_maps.p_idx(1:5)), ...
+        om_uidx{1}(om_maps{1}.p_idx(1:5)));
+      
+      omomname = coco_get_id(om_sname{om_idx}, 'om');
+      prob = coco_add_pars(prob, omomname, ...
+        om_uidx{om_idx}(om_maps{om_idx}.p_idx(6)), ...
+        omomname, 'inactive');
+      
+      if add_adjt
+        [chart, lidx] = ...
+          coco_read_adjoint(gluename, ...
+          last_run_name, BPlab, 'chart', 'lidx');
+
+        prob = coco_add_adjt(prob, gluename, ...
+          'aidx', [pk1_aidx(pk1_opt.p_idx(1:5)), ...
+          om_aidx{om_idx}(om_opt{om_idx}.p_idx(1:5))], ...
+          'l0', chart.x, 'tl0', cdata.v(lidx));
+
+        [chart, lidx] = ...
+          coco_read_adjoint(omomname, ...
+          last_run_name, BPlab, 'chart', 'lidx');
+
+        domomname = coco_get_id('d', omomname);
+        prob = coco_add_adjt(prob, omomname, domomname, ...
+                'aidx', om_aidx{om_idx}(om_opt{om_idx}.p_idx(6)),  ...
+                'l0', chart.x, 'tl0', cdata.v(lidx));
+      end
+    end
+  end
+end
+
+psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.Pt, uq_data.spdists);
+uq_data.wtd_psi_mat = psi_mat*diag(uq_data.wts);
+uq_data.s_idx = s_idx;
+if add_adjt
+  uq_data.adj_s_idx = adj_s_idx;
+end
+uq_data.addadjt=add_adjt;
+prob = uq_add_sample_nodes(prob, uq_data);
+% Final data structure for a UQ sample is stored in the
+% parameter glue function
+uq_data = coco_get_func_data(prob, 'PK1.uq.s_par_glue', 'data');
+
+igs = zeros(uq_data.nsamples, 1);
+idx = zeros(1, uq_data.nsamples);
+for i=1:uq_data.nsamples
+  igs(i) = r_igs{i};
+  idx(i) = [r_idx{i}];
+end
+
+alpha_ig = uq_data.wtd_psi_mat*igs;
+response_id = 'resp';
+prob = coco_add_func(prob, response_id, ...
+  @resp_pce, @resp_pce_dU, @resp_pce_dUdU, ...
+  uq_data, 'zero', 'uidx', idx(:), 'u0', alpha_ig);
+
+if add_adjt
+  aidx = zeros(1, uq_data.nsamples);
+  for i=1:uq_data.nsamples
+    aidx(i) = [r_aidx{i}];
+  end
+  
+  [chart, lidx] = ...
+    coco_read_adjoint(response_id, ...
+    last_run_name, BPlab, 'chart', 'lidx');
+  
+  prob = coco_add_adjt(prob, response_id, ...
+    'aidx', aidx(:), ...
+    'l0', chart.x, 'tl0', cdata.v(lidx));
+end
+
+alpha_idx = coco_get_func_data(prob, response_id, 'uidx');
+alpha_idx = alpha_idx(end-uq_data.Nt+1:end);
+
+if add_adjt
+  alpha_aidx = coco_get_adjt_data(prob, response_id, 'axidx');
+  alpha_aidx = alpha_aidx(end-uq_data.Nt+1:end);
+end
+
+% Mean Zero Function
+mean_id = coco_get_id(response_id, 'pce_mean');
+prob = coco_add_func(prob, mean_id, ...
+  @uq_pce_mean, @uq_pce_mean_dU, @uq_pce_mean_dUdU, ...
+  uq_data, 'zero', 'uidx', alpha_idx, 'u0', alpha_ig(1));
+
+if add_adjt  
+  [chart, lidx] = ...
+    coco_read_adjoint(mean_id, ...
+    last_run_name, BPlab, 'chart', 'lidx');
+  
+  prob = coco_add_adjt(prob, mean_id, 'aidx', ...
+    alpha_aidx, 'l0', chart.x, 'tl0', cdata.v(lidx));
+end
+
+% Variance Zero Function
+var_id = coco_get_id(response_id, 'pce_variance');
+prob = coco_add_func(prob, var_id, ...
+  @uq_pce_variance, @uq_pce_variance_dU, @uq_pce_variance_dUdU,...
+  uq_data, 'zero', 'uidx', alpha_idx, 'u0', sum(alpha_ig(2:end).^2));
+
+if add_adjt
+  [chart, lidx] = ...
+    coco_read_adjoint(var_id, ...
+    last_run_name, BPlab, 'chart', 'lidx');
+  
+  prob = coco_add_adjt(prob, var_id, 'aidx', ...
+    alpha_aidx, 'l0', chart.x, 'tl0', cdata.v(lidx));
+end
+
+obj_id = 'obj';
+mean_idx = coco_get_func_data(prob, mean_id, 'uidx');
+var_idx = coco_get_func_data(prob, var_id, 'uidx');
+
+prob = coco_add_func(prob, obj_id, ...
+  @obj, @obj_du, @obj_dudu, [], ...
+  'inactive', obj_id, 'uidx', ...
+  [mean_idx(end); var_idx(end)]);
+
+if add_adjt
+  [chart, lidx] = coco_read_adjoint(obj_id, ...
+    last_run_name, BPlab, 'chart', 'lidx');
+  
+  mean_aidx = coco_get_adjt_data(prob, mean_id, 'axidx');  
+  var_aidx = coco_get_adjt_data(prob, var_id, 'axidx');
+  
+  dobj_id = coco_get_id('d', obj_id);
+  prob = coco_add_adjt(prob, obj_id, dobj_id, ...
+    'aidx', [mean_aidx(end); var_aidx(end)], ...
+    'l0', chart.x, 'tl0', cdata.v(lidx));
+end
+
+[uidx, data] = coco_get_func_data(prob, 's1.PK1.bvp.seg1.coll', 'uidx', 'data');
+mk_idx = uidx(data.coll_seg.maps.p_idx([1,3]));
+
+prob = coco_add_func(prob, 'km_constraint', ...
+  @km_const, @km_const_du, @km_const_dudu, [], ...
+  'zero', 'uidx', mk_idx);
+
+if add_adjt
+  [aidx, fdata] = coco_get_adjt_data(prob, ...
+    's1.PK1.bvp.seg1.coll', 'axidx', 'data');
+  [chart, lidx] = coco_read_adjoint('km_constraint', ...
+    last_run_name, BPlab, 'chart', 'lidx');
+  
+  mk_aidx = aidx(fdata.coll_opt.p_idx([1,3]));
+
+  prob = coco_add_adjt(prob, 'km_constraint', 'aidx', ...
+    mk_aidx, 'l0', chart.x, 'tl0', cdata.v(lidx));
+end
+
+num_samples = uq_data.nsamples;
+
+alnames = uq_get_sample_par_names('alpha', 1:num_samples);
+omnames = uq_get_sample_par_names('om', 1:num_samples);
+Anames = uq_get_sample_par_names('A', 1:num_samples);
+
+om_diff_ids = cell(1, num_samples);
+pk1_ids = cell(1, num_samples);
+pk2_ids = cell(1, num_samples);
+om1_ids = cell(1, num_samples);
+om2_ids = cell(1, num_samples);
+om3_ids = cell(1, num_samples);
+
+for i=1:num_samples
+  om_diff_ids{i} = coco_get_id(['s', int2str(i)], 'PK_om_diff');
+  pk1_ids{i} = coco_get_id(['s', int2str(i)], 'PK1', 'v0');
+  pk2_ids{i} = coco_get_id(['s', int2str(i)], 'PK2', 'v0');
+  om1_ids{i} = coco_get_id(['s', int2str(i)], 'OM1', 'v0');
+  om2_ids{i} = coco_get_id(['s', int2str(i)], 'OM2', 'v0');
+  om3_ids{i} = coco_get_id(['s', int2str(i)], 'OM3', 'v0');
+end
+dom_diff_ids = coco_get_id('d', om_diff_ids);
+dv10_snames = coco_get_id('d', pk1_ids);
+dv20_snames = coco_get_id('d', pk2_ids);
+dv30_snames = coco_get_id('d', om1_ids);
+dv40_snames = coco_get_id('d', om2_ids);
+dv50_snames = coco_get_id('d', om3_ids);
+
+dalnames = coco_get_id('d', alnames);
+domnames = coco_get_id('d', omnames);
+dAnames = coco_get_id('d', Anames);
+adj_pars2free = {'d.alpha', ...
+    dom_diff_ids{:}, dv10_snames{:}, ...
+    dv20_snames{:}, dv30_snames{:},  ...
+    dv40_snames{:}, dv50_snames{:}, drdiffnames{:}, ...
+    'd.lo.c', 'd.up.c'};
+
+bd = coco(prob, run_name, [], 1, ...
+  {'d.obj', 'k', 'm', 'obj', omnames{:}, Anames{:}, ...
+  's1.OM1.om', 's2.OM1.om', 's3.OM1.om', 's4.OM1.om', ...
+  adj_pars2free{:}}, [0, 1]);
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_fpbp.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_fpbp.m
new file mode 100644
index 0000000000000000000000000000000000000000..eab05536001690c62dfec98d5dd16f71a735af3c
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_fpbp.m
@@ -0,0 +1,539 @@
+last_run_name = 'uq_nds';
+run_name = 'uq_sweep';
+add_adjt = 1;
+
+% Initialize problem data structure
+prob = coco_prob();
+prob = coco_set(prob, 'coll', 'NTST', 30);
+prob = coco_set(prob, 'cont', 'PtMX', 50);
+prob = coco_set(prob, 'cont', 'h', 5, 'h_min', 1e-5, 'h_max', 1e5);
+% prob = coco_set(prob, 'corr', 'TOL', 1e-5);
+% prob = coco_set(prob, 'corr', 'ItNW', 30);
+% For testing only
+% prob = coco_set(prob, 'coll', 'TOL', 100);
+
+% Previous run found points to be used for PCE numerical
+% integration.  Read that data and identify those points.
+bd = coco_bd_read(last_run_name);
+uq_labs = coco_bd_labs(bd, 'UQ');
+
+% Sample counter
+sample_idx = 0;
+om_counter = 0;
+% Stochastic parameter indices
+pk1_par_idx = cell(1, uq_data.nsamples);
+% Response function initial guesses
+r_igs = cell(1, uq_data.nsamples);
+% Response function input indices
+r_idx = cell(1, uq_data.nsamples);
+% Stochastic parameter adjoint indices
+pk1_par_aidx = cell(1, uq_data.nsamples);
+% Response function input adjoint indices
+r_aidx = cell(1, uq_data.nsamples);
+
+% drdiffnames = cell(2*uq_data.nsamples, 1);
+
+% Build samples in this for loop
+for lab=uq_labs
+  sample_idx = sample_idx + 1;
+  % Sample name prefix
+  sample_id = strcat('s', int2str(sample_idx));
+  
+  %% PK1
+  %  Read data from previous run
+  coll_name = 'PK1.bvp.seg1';
+  sol = coll_read_solution(coll_name, last_run_name, lab);
+  coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};  
+  
+  %  PK1 sample names for current run
+  pk1_sname = coco_get_id(sample_id, 'PK1');
+  pk1_bvp_sname = coco_get_id(pk1_sname, 'bvp');
+  pk1_coll_sname = coco_get_id(pk1_bvp_sname, 'seg1.coll');
+
+  % bvp_args defined in demo_curve_build
+  bvp_pnames = {};%uq_get_sample_par_names(pnames, sample_idx);
+  
+  prob = ode_isol2bvp(prob, pk1_sname, ...
+    coll_args{:}, bvp_pnames, bvp_args{:});
+  % Adjoints
+  if add_adjt
+    prob = adjt_isol2bvp(prob, pk1_sname);
+  end
+
+  if sample_idx == 1
+    % The deterministic parameters are added when building
+    % the first sample of PK1
+    s_pnames = {pnames{1}, 'c.1', pnames{[3,4]}, 'A.1', pnames{6}};
+
+    % Keep the data, uidx, and u0 for s1.PK1 for later
+    % gluing conditions
+    [pk1_s1_data, pk1_s1_uidx] = ...
+      coco_get_func_data(prob, pk1_coll_sname, ...
+      'data', 'uidx');
+    pk1_s1_maps = pk1_s1_data.coll_seg.maps;
+
+    s1_par_fname = coco_get_id(sample_id, 'pars');
+    s1_par_pname = s_pnames([1,3,4]);
+    s1_par_idx = pk1_s1_uidx(pk1_s1_maps.p_idx([1,3,4]));
+    prob = coco_add_pars(prob, s1_par_fname, ...
+      s1_par_idx, s1_par_pname);    
+
+    % Adjoints
+    if add_adjt
+      [s1_pk1_fdata, s1_pk1_aidx] = ...
+        coco_get_adjt_data(prob, ...
+        pk1_coll_sname, 'data', 'axidx');
+      s1_pk1_opt = s1_pk1_fdata.coll_opt;
+
+      prob = coco_add_adjt(prob, s1_par_fname, ...
+      coco_get_id('d', s1_par_pname), ...
+      'aidx', s1_pk1_aidx(s1_pk1_opt.p_idx([1,3,4])), ...
+      'l0', zeros(3,1));
+    end
+  else
+    % Glue deterministic parameters together
+    [pk1_si_data, pk1_si_uidx] = ...
+      coco_get_func_data(prob, pk1_coll_sname, ...
+                         'data', 'uidx');
+    pk1_si_maps = pk1_si_data.coll_seg.maps;
+    s1_p_idx = pk1_s1_uidx(pk1_s1_maps.p_idx([1,3,4]));
+    si_p_idx = pk1_si_uidx(pk1_si_maps.p_idx([1,3,4]));
+
+    glue_name = coco_get_id(sample_id, 'glue_to_s1');
+    prob = coco_add_glue(prob, glue_name, s1_p_idx, ...
+      si_p_idx);
+
+    % Adjoints
+    if add_adjt
+
+      [si_pk1_fdata, si_pk1_aidx] = coco_get_adjt_data(prob, ...
+        pk1_coll_sname, 'data', 'axidx');
+      si_pk1_opt = si_pk1_fdata.coll_opt;
+
+      % For glue
+      s1_p_aidx = s1_pk1_aidx(s1_pk1_opt.p_idx([1,3,4]));
+      si_p_aidx = si_pk1_aidx(si_pk1_opt.p_idx([1,3,4]));
+
+      prob = coco_add_adjt(prob, glue_name, ...
+        'aidx', [s1_p_aidx; si_p_aidx]);
+    end
+  end
+  
+  [pk1_data, pk1_uidx, pk1_u0] = ...
+    coco_get_func_data(prob, pk1_coll_sname, ...
+    'data', 'uidx', 'u0');
+  pk1_maps = pk1_data.coll_seg.maps;
+  pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+  
+  pk1_par_idx{sample_idx} = pk1_uidx(pk1_maps.p_idx);
+  r_igs{sample_idx} = pk1_u0(pk1_maps.x0_idx(1));
+  r_idx{sample_idx} = pk1_uidx(pk1_maps.x0_idx(1));
+
+%   % Damping names
+%   si_c_fname = coco_get_id(sample_id, 'c');
+%   si_c_pname = coco_get_id('c', int2str(sample_idx));
+%   si_c_idx = pk1_uidx(pk1_maps.p_idx(2));
+%   prob = coco_add_pars(prob, si_c_fname, ...
+%     si_c_idx, si_c_pname, 'inactive');
+  
+  % Forcing amplitude names
+  si_A_fname = coco_get_id(sample_id, 'A');
+  si_A_pname = coco_get_id('A', int2str(sample_idx));
+  si_A_idx = pk1_uidx(pk1_maps.p_idx(5));
+  prob = coco_add_pars(prob, si_A_fname, ...
+    si_A_idx, si_A_pname, 'inactive');
+  
+  % Forcing frequency names
+  si_om_fname = coco_get_id(sample_id, 'om');
+  si_om_pname = coco_get_id('om', int2str(sample_idx));
+  si_om_idx = pk1_uidx(pk1_maps.p_idx(6));
+  prob = coco_add_pars(prob, si_om_fname, ...
+    si_om_idx, si_om_pname, 'inactive');
+
+  % Velocity constraint for PK1
+  pk1_v0_sname = coco_get_id(pk1_sname, 'v0');
+  prob = coco_add_pars(prob, pk1_v0_sname, pk1_x0(2), ...
+    pk1_v0_sname, 'inactive');
+  
+  if add_adjt
+    [pk1_adata, pk1_aidx] = coco_get_adjt_data(prob, ...
+      pk1_coll_sname, 'data', 'axidx');
+    pk1_opt = pk1_adata.coll_opt;
+    
+    pk1_par_aidx{sample_idx} = pk1_aidx(pk1_opt.p_idx);
+    r_aidx{sample_idx} = pk1_aidx(pk1_opt.x0_idx(1)); 
+
+%     % Damping
+%     prob = coco_add_adjt(prob, si_c_fname, ...
+%       coco_get_id('d', si_c_pname), ...
+%       'aidx', pk1_aidx(pk1_opt.p_idx(2)), ...
+%       'l0', 0);
+    
+    % Forcing Amplitude
+    prob = coco_add_adjt(prob, si_A_fname, ...
+      coco_get_id('d', si_A_pname), ...
+      'aidx', pk1_aidx(pk1_opt.p_idx(5)), ...
+      'l0', 0);  
+    
+    % Forcing frequency
+    prob = coco_add_adjt(prob, si_om_fname, ...
+      coco_get_id('d', si_om_pname), ...
+      'aidx', pk1_aidx(pk1_opt.p_idx(6)), ...
+      'l0', 0);
+
+    % Velocity constraint
+    dv10_sname = coco_get_id('d', pk1_v0_sname);
+    prob = coco_add_adjt(prob, pk1_v0_sname, ...
+      dv10_sname, ...
+      'aidx', pk1_aidx(pk1_opt.x0_idx(2)), ...
+      'l0', 0);
+  end
+  
+  %% PK2
+  % Read data from previous run.  PK2 was added with
+  % coll2coll in the previous run, so it doesn't have the
+  % bvp.seg1 identifiers.
+  coll_name = 'PK2';
+  sol = coll_read_solution(coll_name, last_run_name, lab);
+  
+  %  PK2 sample names for current run
+  pk2_sname = coco_get_id(sample_id, 'PK2');
+  coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+  prob = ode_isol2bvp(prob, pk2_sname, ...
+    coll_args{:}, {}, bvp_args{:});
+
+  % PK2 was added with isol2bvp in this run, so reading the
+  % data requires the bvp identifiers.
+  pk2_coll_sname = coco_get_id(pk2_sname, 'bvp', 'seg1', 'coll');
+
+  [pk2_data, pk2_uidx] = coco_get_func_data(prob, ...
+    pk2_coll_sname, 'data', 'uidx');
+  pk2_maps = pk2_data.coll_seg.maps;
+  pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+
+  % Velocity constraint for PK2
+  pk2_v0_sname = coco_get_id(pk2_sname, 'v0');
+  prob = coco_add_pars(prob, pk2_v0_sname, pk2_x0(2), ...
+    pk2_v0_sname, 'inactive');
+
+  % Glue Parameters together (except forcing frequency)
+  parglue_sname = coco_get_id(sample_id, ...
+    'par_glue_PK2_to_PK1');
+  prob = coco_add_glue(prob, parglue_sname, ...
+    pk2_uidx(pk2_maps.p_idx(1:5)), ...
+    pk1_uidx(pk1_maps.p_idx(1:5)));
+  
+  pk_r_glue_sname = coco_get_id(sample_id, ...
+    'R_glue_to_PK1');
+  prob = coco_add_glue(prob, pk_r_glue_sname, ...
+    pk2_x0(1), pk1_x0(1));
+
+  % Lock in the frequency difference
+  pk_om_diff_sname = coco_get_id(sample_id, ...
+    'PK_om_diff');
+
+  prob = coco_add_func(prob, pk_om_diff_sname, ...
+    @udiff, @udiff_dU, @udiff_dUdU, [], ...
+    'inactive', pk_om_diff_sname, 'uidx', ...
+    [pk2_uidx(pk2_maps.p_idx(6)), ...
+     pk1_uidx(pk1_maps.p_idx(6))]);
+
+  % Adjoints
+  if add_adjt
+    % ode
+    prob = adjt_isol2bvp(prob, pk2_sname);
+    [pk2_fdata, pk2_aidx] = coco_get_adjt_data(prob, ...
+      pk2_coll_sname, 'data', 'axidx');
+    pk2_opt = pk2_fdata.coll_opt;
+
+    % velocity constraint
+    dv20_sname = coco_get_id('d', pk2_v0_sname);
+    prob = coco_add_adjt(prob, pk2_v0_sname, ...
+      dv20_sname, ...
+      'aidx', pk2_aidx(pk2_opt.x0_idx(2)));
+
+    % glue
+    prob = coco_add_adjt(prob, parglue_sname, ...
+      'aidx', [pk2_aidx(pk2_opt.p_idx(1:5)); ...
+      pk1_aidx(pk1_opt.p_idx(1:5))]);
+
+    prob = coco_add_adjt(prob, pk_r_glue_sname, ...
+      'aidx', [pk2_aidx(pk2_opt.x0_idx(1)); ...
+      pk1_aidx(pk1_opt.x0_idx(1))]);
+    
+    pk_om_diff_dpname = coco_get_id('d', pk_om_diff_sname);
+    pk_om_diff_dpnames{sample_idx} = pk_om_diff_dpname;  
+    
+    % om constraint
+    prob = coco_add_adjt(prob, pk_om_diff_sname, ...
+      pk_om_diff_dpname, ...
+      'aidx', [pk2_aidx(pk2_opt.p_idx(6)), ...
+      pk1_aidx(pk1_opt.p_idx(6))]);
+
+  end
+  %% OMs
+  % Build OM orbits for the sample in a for loop
+  om_fdata = cell(3,1);
+  om_aidx = cell(3,1);
+  om_opt = cell(3,1);
+  om_data = cell(3,1);
+  om_uidx = cell(3,1);
+  om_maps = cell(3,1);
+  om_x0 = cell(3,1);
+  om_x0a = cell(3,1);
+  
+  for om_idx=1:3
+    om_id = strcat('OM', int2str(om_idx));
+    om_sname = coco_get_id(sample_id, om_id);
+    om_seg_name = coco_get_id(om_id, 'bvp', 'seg1');
+    sol = coll_read_solution(om_seg_name, last_run_name, lab);
+
+    coll_args = {coll_args{1:6}, sol.tbp-sol.tbp(1), sol.xbp, sol.p};
+    prob = ode_isol2bvp(prob, om_sname, ...
+      coll_args{:}, {}, bvp_args{:});
+
+    if add_adjt
+      prob = adjt_isol2bvp(prob, om_sname);
+    end
+    
+    om_coll_sname = coco_get_id(om_sname, 'bvp', 'seg1', 'coll');
+    [om_data{om_idx}, om_uidx{om_idx}] = coco_get_func_data(prob, ...
+      om_coll_sname, 'data', 'uidx');
+    om_maps{om_idx} = om_data{om_idx}.coll_seg.maps;
+
+    % Maintain velocity constraint
+    v0sname = coco_get_id(sample_id, ['OM', int2str(om_idx)],'v0');
+    om_x0{om_idx} = om_uidx{om_idx}(om_maps{om_idx}.x0_idx);
+    prob = coco_add_pars(prob, v0sname, om_x0{om_idx}(2), v0sname, ...
+      'inactive');
+    
+    if add_adjt
+      [om_fdata{om_idx}, om_aidx{om_idx}] = coco_get_adjt_data(prob, ...
+        om_coll_sname, 'data', 'axidx');
+      om_opt{om_idx} = om_fdata{om_idx}.coll_opt;
+      om_x0a{om_idx} = om_aidx{om_idx}(om_opt{om_idx}.x0_idx);
+
+      dv0sname = coco_get_id('d', v0sname);
+      prob = coco_add_adjt(prob, v0sname, dv0sname, ...
+        'aidx', om_x0a{om_idx}(2));
+    end
+
+    % Glue Parameters together
+    if om_idx > 1
+      % The fold approximants share all parameter values.
+      % They differ only in response amplitude 
+      gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+        int2str(om_idx), '_to_OM1']);
+
+      prob = coco_add_glue(prob, gluename, ...
+        om_uidx{1}(om_maps{1}.p_idx), ...
+        om_uidx{om_idx}(om_maps{om_idx}.p_idx));
+
+      % Parameterize Response Amplitude Difference
+      rdiffname = ['OM', int2str(om_idx-1), 'R_minus_OM', int2str(om_idx), 'R'];
+      rdiffname = coco_get_id(sample_id, rdiffname);
+      prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+        [], 'inactive', rdiffname, 'uidx', [om_x0{om_idx-1}(1), om_x0{om_idx}(1)]);
+      
+      if add_adjt
+        prob = coco_add_adjt(prob, gluename, ...
+          'aidx', [om_aidx{1}(om_opt{1}.p_idx); ...
+          om_aidx{om_idx}(om_opt{om_idx}.p_idx)]);
+
+        om_counter = om_counter + 1;
+        drdiffname = coco_get_id('d', rdiffname);
+        drdiffnames{om_counter} = drdiffname;
+        prob = coco_add_adjt(prob, rdiffname, drdiffname, ...
+          'aidx', [om_x0a{om_idx-1}(1), om_x0a{om_idx}(1)]);
+      end
+
+    else
+      gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+        int2str(om_idx), '_to_PK1']);
+
+      prob = coco_add_glue(prob, gluename, ...
+        pk1_uidx(pk1_maps.p_idx(1:5)), ...
+        om_uidx{1}(om_maps{1}.p_idx(1:5)));
+      
+      omomname = coco_get_id(sample_id, coco_get_id(om_id, 'om'));
+      prob = coco_add_pars(prob, omomname, ...
+        om_uidx{om_idx}(om_maps{om_idx}.p_idx(6)), ...
+        omomname, 'inactive');
+      
+      if add_adjt
+        prob = coco_add_adjt(prob, gluename, ...
+          'aidx', [pk1_aidx(pk1_opt.p_idx(1:5)); ...
+          om_aidx{1}(om_opt{1}.p_idx(1:5))]);
+
+        domomname = coco_get_id('d', omomname);
+        prob = coco_add_adjt(prob, omomname, domomname, ...
+                'aidx', om_aidx{om_idx}(om_opt{om_idx}.p_idx(6)));
+      end
+    end
+  end
+end
+
+psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.Pt, uq_data.spdists);
+uq_data.wtd_psi_mat = psi_mat*diag(uq_data.wts);
+uq_data.s_idx = pk1_par_idx;
+if add_adjt
+  uq_data.adj_s_idx = pk1_par_aidx;
+end
+uq_data.addadjt=add_adjt;
+prob = uq_add_sample_nodes(prob, uq_data);
+% Final data structure for a UQ sample is stored in the
+% parameter glue function
+uq_data = coco_get_func_data(prob, 'PK1.uq.s_par_glue', 'data');
+
+igs = zeros(uq_data.nsamples, 1);
+idx = zeros(1, uq_data.nsamples);
+for i=1:uq_data.nsamples
+  igs(i) = r_igs{i};
+  idx(i) = [r_idx{i}];
+end
+
+alpha_ig = uq_data.wtd_psi_mat*igs;
+response_id = 'resp';
+prob = coco_add_func(prob, response_id, ...
+  @resp_pce, @resp_pce_dU, @resp_pce_dUdU, ...
+  uq_data, 'zero', 'uidx', idx(:), 'u0', alpha_ig);
+
+if add_adjt
+  aidx = zeros(1, uq_data.nsamples);
+  for i=1:uq_data.nsamples
+    aidx(i) = [r_aidx{i}];
+  end
+
+  prob = coco_add_adjt(prob, response_id, ...
+    'aidx', aidx(:), 'l0', zeros(size(alpha_ig)));
+
+end
+
+alpha_idx = coco_get_func_data(prob, response_id, 'uidx');
+alpha_idx = alpha_idx(end-uq_data.Nt+1:end);
+
+if add_adjt
+  alpha_aidx = coco_get_adjt_data(prob, response_id, 'axidx');
+  alpha_aidx = alpha_aidx(end-uq_data.Nt+1:end);
+end
+
+% Mean Zero Function
+mean_id = coco_get_id(response_id, 'pce_mean');
+prob = coco_add_func(prob, mean_id, ...
+  @uq_pce_mean, @uq_pce_mean_dU, @uq_pce_mean_dUdU, ...
+  uq_data, 'zero', 'uidx', alpha_idx, 'u0', alpha_ig(1));
+
+if add_adjt  
+  prob = coco_add_adjt(prob, mean_id, 'aidx', ...
+    alpha_aidx, 'l0', 0);
+end
+
+% Variance Zero Function
+var_id = coco_get_id(response_id, 'pce_variance');
+prob = coco_add_func(prob, var_id, ...
+  @uq_pce_variance, @uq_pce_variance_dU, @uq_pce_variance_dUdU,...
+  uq_data, 'zero', 'uidx', alpha_idx, 'u0', sum(alpha_ig(2:end).^2));
+
+if add_adjt
+  prob = coco_add_adjt(prob, var_id, 'aidx', ...
+    alpha_aidx, 'l0', 0);
+end
+
+obj_id = 'obj';
+mean_idx = coco_get_func_data(prob, mean_id, 'uidx');
+var_idx = coco_get_func_data(prob, var_id, 'uidx');
+
+prob = coco_add_func(prob, obj_id, ...
+  @obj, @obj_du, @obj_dudu, [], ...
+  'inactive', obj_id, 'uidx', ...
+  [mean_idx(end); var_idx(end)]);
+
+if add_adjt
+  dobj_id = coco_get_id('d', obj_id);
+  mean_aidx = coco_get_adjt_data(prob, mean_id, 'axidx');  
+  var_aidx = coco_get_adjt_data(prob, var_id, 'axidx');
+  prob = coco_add_adjt(prob, obj_id, dobj_id, ...
+    'aidx', [mean_aidx(end); var_aidx(end)]);
+end
+
+[uidx, data] = coco_get_func_data(prob, 's1.PK1.bvp.seg1.coll', 'uidx', 'data');
+mk_idx = uidx(data.coll_seg.maps.p_idx([1,3]));
+
+prob = coco_add_func(prob, 'km_constraint', ...
+  @km_const, @km_const_du, @km_const_dudu, [], ...
+  'zero', 'uidx', mk_idx);
+
+if add_adjt
+  [aidx, fdata] = coco_get_adjt_data(prob, ...
+    's1.PK1.bvp.seg1.coll', 'axidx', 'data');
+  mk_aidx = aidx(fdata.coll_opt.p_idx([1,3]));
+
+  prob = coco_add_adjt(prob, 'km_constraint', 'aidx', ...
+    mk_aidx);
+end
+
+num_samples = uq_data.nsamples;
+
+alnames = uq_get_sample_par_names('alpha', 1:num_samples);
+omnames = uq_get_sample_par_names('om', 1:num_samples);
+Anames = uq_get_sample_par_names('A', 1:num_samples);
+
+om_diff_ids = cell(1, num_samples);
+pk1_ids = cell(1, num_samples);
+pk2_ids = cell(1, num_samples);
+om1_ids = cell(1, num_samples);
+om2_ids = cell(1, num_samples);
+om3_ids = cell(1, num_samples);
+
+for i=1:num_samples
+  om_diff_ids{i} = coco_get_id(['s', int2str(i)], 'PK_om_diff');
+  pk1_ids{i} = coco_get_id(['s', int2str(i)], 'PK1', 'v0');
+  pk2_ids{i} = coco_get_id(['s', int2str(i)], 'PK2', 'v0');
+  om1_ids{i} = coco_get_id(['s', int2str(i)], 'OM1', 'v0');
+  om2_ids{i} = coco_get_id(['s', int2str(i)], 'OM2', 'v0');
+  om3_ids{i} = coco_get_id(['s', int2str(i)], 'OM3', 'v0');
+end
+dom_diff_ids = coco_get_id('d', om_diff_ids);
+dv10_snames = coco_get_id('d', pk1_ids);
+dv20_snames = coco_get_id('d', pk2_ids);
+dv30_snames = coco_get_id('d', om1_ids);
+dv40_snames = coco_get_id('d', om2_ids);
+dv50_snames = coco_get_id('d', om3_ids);
+
+
+if add_adjt
+  dnames = coco_get_id('d', uq_get_sample_par_names(pnames, 1:4));
+  dcnames = coco_get_id('d', {'c.1', 'c.2', 'c.3', 'c.4'});
+  domnames = coco_get_id('d', omnames);
+  dAnames = coco_get_id('d', Anames);
+  dmoments = {'d.lo.c', 'd.up.c'};
+  adj_pars2free = {'d.alpha', ...
+    dom_diff_ids{:}, dv10_snames{:}, ...
+    dv20_snames{:}, dv30_snames{:},  ...
+    dv40_snames{:}, dv50_snames{:}, drdiffnames{:}, ...
+    dmoments{:}};
+  omnames = {omnames{:}, 's1.OM1.om', 's2.OM1.om', 's3.OM1.om', 's4.OM1.om'};
+  if not(coco_exist(run_name, 'run'))
+    bd = coco(prob, run_name, [], 1, ...
+      {'obj', 'k', 'm', 'd.obj', omnames{:}, Anames{:}, 
+      adj_pars2free{:}}, [0.1, 3.1]);
+  else
+    bd = coco_bd_read(run_name);    
+  end
+else
+  % Mean Continuation Parameter
+  mean_par_id = coco_get_id(response_id, 'mean');
+  mean_idx = coco_get_func_data(prob, mean_id, 'uidx');
+  mean_name = coco_get_id(response_id, 'mean');
+  prob = coco_add_pars(prob, mean_par_id, mean_idx(end), mean_name);  
+  
+  % Variance Parameter
+  var_par_id = coco_get_id(response_id, 'variance');
+  var_idx = coco_get_func_data(prob, var_id, 'uidx');
+  var_name = coco_get_id(response_id, 'var');
+  prob = coco_add_pars(prob, var_par_id, var_idx(end), var_name);  
+
+  bd = coco(prob, 'uq_sweep_no_adjt_for_plot_m=1_n=0', [], ...
+    {'obj', 'k', 'm', mean_name, var_name, omnames{:}, Anames{:}, 's1.OM1.om', 's2.OM1.om', 's3.OM1.om', 's4.OM1.om'}, ...
+    [-0.355, 4]);
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_km_srch.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_km_srch.m
new file mode 100644
index 0000000000000000000000000000000000000000..ecb1a040ff274d8b598cf13bf646fe8c5e4919a0
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_for_thesis_km_srch.m
@@ -0,0 +1,619 @@
+demo_for_thesis_dobj_to_1
+
+last_run_name = run_name;
+run_name = 'uq_km_srch';
+add_adjt=1;
+
+% Initialize cell arrays
+s_idx = cell(1, uq_data.nsamples);
+r_igs = cell(1, uq_data.nsamples);
+r_idx = cell(1, uq_data.nsamples);
+
+if not(coco_exist(run_name, 'run')) || true
+  prob = prob_init;
+  prob = coco_set(prob, 'coll', 'NTST', 20);
+%   prob_init = coco_set(prob_init, 'coll', 'NAdapt', 1);  
+  labs = coco_bd_labs(bd, 'EP');
+  lab = labs(2);
+  
+  for j=1:uq_data.nsamples
+    
+    sample_id = strcat('s', int2str(j));
+    pk1_sname = coco_get_id(sample_id, 'PK1');
+    pk2_sname = coco_get_id(sample_id, 'PK2');
+    om_sname{1} = coco_get_id(sample_id, 'OM1');
+    om_sname{2} = coco_get_id(sample_id, 'OM2');
+    om_sname{3} = coco_get_id(sample_id, 'OM3');
+    om_sname{4} = coco_get_id(sample_id, 'OM4');
+
+    prob = ode_bvp2bvp(prob, pk1_sname, last_run_name, lab);
+    prob = ode_bvp2bvp(prob, pk2_sname, last_run_name, lab);
+    prob = ode_bvp2bvp(prob, om_sname{1}, last_run_name, lab);
+    prob = ode_bvp2bvp(prob, om_sname{2}, last_run_name, lab);
+    prob = ode_bvp2bvp(prob, om_sname{3}, last_run_name, lab);
+    prob = ode_bvp2bvp(prob, om_sname{4}, last_run_name, lab);
+    
+    adjt_args = struct();
+    if add_adjt
+      adjt_args.run = last_run_name;
+      adjt_args.lab = lab;
+      adjt_chart = coco_read_solution(last_run_name, lab, 'chart');
+      cdata = coco_get_chart_data(adjt_chart, 'lsol');
+      
+      prob = adjt_bvp2bvp(prob, pk1_sname, last_run_name, lab);
+      prob = adjt_bvp2bvp(prob, pk2_sname, last_run_name, lab);
+      prob = adjt_bvp2bvp(prob, om_sname{1}, last_run_name, lab);
+      prob = adjt_bvp2bvp(prob, om_sname{2}, last_run_name, lab);
+      prob = adjt_bvp2bvp(prob, om_sname{3}, last_run_name, lab);
+      prob = adjt_bvp2bvp(prob, om_sname{4}, last_run_name, lab);
+    end    
+
+    pk1_coll_sname = coco_get_id(pk1_sname, 'bvp', ...
+      'seg1', 'coll');
+    pk2_coll_sname = coco_get_id(pk2_sname, 'bvp', ...
+      'seg1', 'coll');
+    
+    % Peak 1 Information
+    [pk1_data, pk1_uidx, pk1_u0] = ...
+      coco_get_func_data(prob, pk1_coll_sname, ...
+      'data', 'uidx', 'u0');
+    pk1_maps = pk1_data.coll_seg.maps;
+    pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+    % Peak 2 Information
+    [pk2_data, pk2_uidx] = coco_get_func_data(prob, ...
+      pk2_coll_sname, 'data', 'uidx');
+    pk2_maps = pk2_data.coll_seg.maps;
+    pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+    
+    if add_adjt
+        [pk1_fdata, pk1_aidx] = coco_get_adjt_data(prob, ...
+          pk1_coll_sname, 'data', 'axidx');
+        pk1_opt = pk1_fdata.coll_opt;
+
+        [pk2_fdata, pk2_aidx] = coco_get_adjt_data(prob, ...
+          pk2_coll_sname, 'data', 'axidx');
+        pk2_opt = pk2_fdata.coll_opt;
+    end
+
+    if j == 1
+      % Name the parameters
+      par_fname = coco_get_id(sample_id, 'pars');
+      par_pname = pnames([1:3,5]);
+      par_pname = {par_pname{:},'om.1'};
+      par_idx = pk1_uidx(pk1_maps.p_idx([1:3,5,6]));
+      prob = coco_add_pars(prob, par_fname, ...
+        par_idx, par_pname);
+      
+      % Store first sample's info for glue
+      s1_pk1_data = pk1_data;
+      s1_pk1_uidx = pk1_uidx;
+      s1_pk1_maps = pk1_maps;
+
+      % Adjoints
+      if add_adjt
+        [chart, lidx] = coco_read_adjoint(par_fname, ...
+          last_run_name, lab, 'chart', 'lidx');
+        
+        prob = coco_add_adjt(prob, par_fname, ...
+          coco_get_id('d', par_pname), ...
+          'aidx', pk1_aidx(pk1_opt.p_idx([1:3,5,6])), ...
+          'l0', chart.x, 'tl0', cdata.v(lidx));
+        
+        s1_pk1_fdata = pk1_fdata;
+        s1_pk1_aidx  = pk1_aidx;
+        s1_pk1_opt   = pk1_opt;
+
+        adj_s_idx{j} = pk1_aidx(pk1_opt.p_idx);
+        r_aidx{j} = pk1_aidx(pk1_opt.x0_idx(1));
+      end
+    else
+      % Glue deterministic parameters together
+      s1_p_idx = s1_pk1_uidx(s1_pk1_maps.p_idx([1:3,5]));
+      p_idx = pk1_uidx(pk1_maps.p_idx([1:3,5]));
+
+      glue_name = coco_get_id(sample_id, 'glue_to_s1');
+      prob = coco_add_glue(prob, glue_name, s1_p_idx, ...
+        p_idx);
+      
+      % Frequency Names
+      om_fname = coco_get_id(sample_id, 'om');
+      om_pname = coco_get_id('om', int2str(j));
+      om_idx = pk1_uidx(pk1_maps.p_idx(6));
+      prob = coco_add_pars(prob, om_fname, ...
+        om_idx, om_pname);      
+
+      % Adjoints
+      if add_adjt
+        % For glue
+        [chart, lidx] = coco_read_adjoint(glue_name, ...
+          last_run_name, lab, 'chart', 'lidx');        
+        s1_p_aidx = s1_pk1_aidx(s1_pk1_opt.p_idx([1:3,5]));
+        p_aidx = pk1_aidx(pk1_opt.p_idx([1:3,5]));
+        prob = coco_add_adjt(prob, glue_name, ...
+          'aidx', [s1_p_aidx; p_aidx], 'l0', chart.x, ...
+          'tl0', cdata.v(lidx));
+
+        % For frequency
+        [chart, lidx] = coco_read_adjoint(om_fname, ...
+          last_run_name, lab, 'chart', 'lidx'); 
+
+        prob = coco_add_adjt(prob, om_fname, ...
+          coco_get_id('d', om_pname), ...
+          'aidx', pk1_aidx(pk1_opt.p_idx(6)), ...
+          'l0', chart.x, 'tl0', cdata.v(lidx));
+
+        adj_s_idx{j} = pk1_aidx(sj_pk1_opt.p_idx);
+        r_aidx{j} = pk1_aidx(sj_pk1_opt.x0_idx(1));        
+      end
+    end
+
+    % Parameterize Amplitude Peak (Is this necessary?)
+    pk1_r_sname = coco_get_id(pk1_sname, 'R');
+    prob = coco_add_pars(prob, pk1_r_sname, pk1_x0(1), ...
+      pk1_r_sname, 'active');
+
+    % Adjoint
+    if add_adjt
+      [chart, lidx] = coco_read_adjoint(pk1_r_sname, ...
+        last_run_name, lab, 'chart', 'lidx');
+      [pk1_fdata, pk1_aidx] = coco_get_adjt_data(prob, ...
+        pk1_coll_sname, 'data', 'axidx');
+      sj_pk1_opt = pk1_fdata.coll_opt;
+      
+      prob = coco_add_adjt(prob, pk1_r_sname, ...
+        coco_get_id('d', pk1_r_sname), ...
+        'aidx', pk1_aidx(sj_pk1_opt.x0_idx(1)), ...
+        'l0', chart.x, 'tl0', cdata.v(lidx));
+    end
+
+    % Maintain velocity constraint (could also be done with a
+    % boundary condition)
+    pk1_v0_sname = coco_get_id(pk1_sname, 'v0');
+    prob = coco_add_pars(prob, pk1_v0_sname, pk1_x0(2), ...
+      pk1_v0_sname, 'inactive');
+    
+    % Adjoint
+    if add_adjt
+      [chart, lidx] = coco_read_adjoint(pk1_v0_sname, ...
+        last_run_name, lab, 'chart', 'lidx');
+      dv10_sname = coco_get_id('d', pk1_v0_sname);
+      prob = coco_add_adjt(prob, pk1_v0_sname, ...
+        dv10_sname, ...
+        'aidx', pk1_aidx(pk1_opt.x0_idx(2)), ...
+        'l0', chart.x, 'tl0', cdata.v(lidx));
+    end
+
+    
+    % Maintain velocity constraint (could also be done with a
+    % boundary condition)
+    pk2_v0_sname = coco_get_id(pk2_sname, 'v0');
+    prob = coco_add_pars(prob, pk2_v0_sname, pk2_x0(2), ...
+      pk2_v0_sname, 'inactive');
+
+    % Glue Parameters together (except forcing frequency)
+    parglue_sname = coco_get_id(sample_id, ...
+      'par_glue_to_PK1');
+    prob = coco_add_glue(prob, parglue_sname, ...
+      pk2_uidx(pk2_maps.p_idx(1:5)), ...
+      pk1_uidx(pk1_maps.p_idx(1:5)));
+
+    pk_r_glue_sname = coco_get_id(sample_id, ...
+      'R_glue_to_PK1');
+    prob = coco_add_glue(prob, pk_r_glue_sname, ...
+      pk2_x0(1), pk1_x0(1));
+
+    % Lock in the frequency difference
+    pk_om_diff_sname = coco_get_id(sample_id, ...
+      'om_diff');
+    prob = coco_add_func(prob, pk_om_diff_sname, ...
+      @udiff, @udiff_dU, @udiff_dUdU, [], ...
+      'inactive', pk_om_diff_sname, 'uidx', ...
+      [pk2_uidx(pk2_maps.p_idx(6)), ...
+       pk1_uidx(pk1_maps.p_idx(6))]);
+     
+    % Adjoints
+    if add_adjt
+      % velocity constraint
+      [chart, lidx] = coco_read_adjoint(pk2_v0_sname, ...
+        last_run_name, lab, 'chart', 'lidx');
+      
+      dv20_sname = coco_get_id('d', pk2_v0_sname);
+      prob = coco_add_adjt(prob, pk2_v0_sname, ...
+        dv20_sname, ...
+        'aidx', pk2_aidx(pk2_opt.x0_idx(2)),...
+        'l0', chart.x, 'tl0', cdata.v(lidx));
+
+      % glue
+      [chart, lidx] = coco_read_adjoint(parglue_sname, ...
+        last_run_name, lab, 'chart', 'lidx');
+
+      prob = coco_add_adjt(prob, parglue_sname, ...
+        'aidx', [pk2_aidx(pk2_opt.p_idx(1:5)); ...
+        pk1_aidx(pk1_opt.p_idx(1:5))], ...
+        'l0', chart.x, 'tl0', cdata.v(lidx));
+      
+      [chart, lidx] = coco_read_adjoint(pk_r_glue_sname, ...
+        last_run_name, lab, 'chart', 'lidx');
+      
+      prob = coco_add_adjt(prob, pk_r_glue_sname, ...
+        'aidx', [pk2_aidx(pk2_opt.x0_idx(1)); ...
+        pk1_aidx(pk1_opt.x0_idx(1))], ...
+        'l0', chart.x, 'tl0', cdata.v(lidx));
+
+      % om constraint
+      [chart, lidx] = coco_read_adjoint(pk_om_diff_sname, ...
+        last_run_name, lab, 'chart', 'lidx');
+
+      prob = coco_add_adjt(prob, pk_om_diff_sname, ...
+        coco_get_id('d', pk_om_diff_sname), ...
+        'aidx', [pk2_aidx(pk2_opt.p_idx(6)), ...
+        pk1_aidx(pk1_opt.p_idx(6))], ...
+        'l0', chart.x, 'tl0', cdata.v(lidx));
+
+    end
+    
+    for i=1:4
+      om_coll_sname = coco_get_id(om_sname{i}, 'bvp', ...
+        'seg1', 'coll');
+      [om_data{i}, om_uidx{i}] = coco_get_func_data(prob, ...
+        om_coll_sname, 'data', 'uidx');
+      om_maps{i} = om_data{i}.coll_seg.maps;
+      
+      % Maintain velocity constraint
+      v0sname = coco_get_id(om_sname{i},'v0');
+      om_x0{i} = om_uidx{i}(om_maps{i}.x0_idx);
+      prob = coco_add_pars(prob, v0sname, om_x0{i}(2), v0sname, 'inactive');    
+
+      if add_adjt
+        [om_fdata{i}, om_aidx{i}] = coco_get_adjt_data(prob, ...
+          om_coll_sname, 'data', 'axidx');
+        om_opt{i} = om_fdata{i}.coll_opt;
+        om_x0a{i} = om_aidx{i}(om_opt{i}.x0_idx);
+        
+        [chart, lidx] = coco_read_adjoint(v0sname, ...
+          last_run_name, lab, 'chart', 'lidx');
+
+        dv0sname = coco_get_id('d', v0sname);
+        prob = coco_add_adjt(prob, v0sname, dv0sname, ...
+          'aidx', om_x0a{i}(2),...
+          'l0', chart.x, 'tl0', cdata.v(lidx));
+      end
+      
+      switch i
+        case 1
+          gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+            int2str(i), '_to_PK1']);
+          prob = coco_add_glue(prob, gluename, ...
+            pk2_uidx(pk2_maps.p_idx(1:5)), ...
+            om_uidx{i}(om_maps{i}.p_idx(1:5)));
+
+          if add_adjt
+            [chart, lidx] = ...
+              coco_read_adjoint(gluename, ...
+              last_run_name, lab, 'chart', 'lidx');
+
+            prob = coco_add_adjt(prob, gluename, ...
+              'aidx', [pk1_aidx(pk1_opt.p_idx(1:5)), ...
+              om_aidx{i}(om_opt{i}.p_idx(1:5))], ...
+              'l0', chart.x, 'tl0', cdata.v(lidx));
+          end          
+        case 2
+          % The fold approximants share all parameter values.
+          % They differ only in response amplitude 
+
+          gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+            int2str(i), '_to_OM1']);
+          prob = coco_add_glue(prob, gluename, ...
+            om_uidx{1}(om_maps{1}.p_idx), ...
+            om_uidx{i}(om_maps{i}.p_idx));
+
+          % Parameterize Response Amplitude Difference
+          rdiffname = ['OM', int2str(i-1), 'R_minus_OM', int2str(i), 'R'];
+          rdiffname = coco_get_id(sample_id, rdiffname);
+          prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+            [], 'inactive', rdiffname, 'uidx', [om_x0{i-1}(1), om_x0{i}(1)]);
+
+          if add_adjt
+            [chart, lidx] = ...
+              coco_read_adjoint(gluename, ...
+              last_run_name, lab, 'chart', 'lidx');
+
+            prob = coco_add_adjt(prob, gluename, ...
+              'aidx', [om_aidx{1}(om_opt{1}.p_idx), ...
+              om_aidx{i}(om_opt{i}.p_idx)], ...
+              'l0', chart.x, 'tl0', cdata.v(lidx));
+
+            drdiffname = coco_get_id('d', rdiffname);
+            drdiffnames12{j} = drdiffname;
+
+            [chart, lidx] = ...
+              coco_read_adjoint(rdiffname, ...
+              last_run_name, lab, 'chart', 'lidx');
+
+            prob = coco_add_adjt(prob, rdiffname, drdiffname, ...
+              'aidx', [om_x0a{i-1}(1), om_x0a{i}(1)], ...
+              'l0', chart.x, 'tl0', cdata.v(lidx));
+          end
+        case 3
+          gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+            int2str(i), '_to_PK1']);
+          prob = coco_add_glue(prob, gluename, ...
+            pk2_uidx(pk2_maps.p_idx(1:5)), ...
+            om_uidx{i}(om_maps{i}.p_idx(1:5)));
+
+          if add_adjt
+            [chart, lidx] = ...
+              coco_read_adjoint(gluename, ...
+              last_run_name, lab, 'chart', 'lidx');
+
+            prob = coco_add_adjt(prob, gluename, ...
+              'aidx', [pk1_aidx(pk1_opt.p_idx(1:5)), ...
+              om_aidx{i}(om_opt{i}.p_idx(1:5))], ...
+              'l0', chart.x, 'tl0', cdata.v(lidx));
+          end
+        case 4
+          gluename = coco_get_id(sample_id, ['par_glue_OM', ...
+            int2str(i), '_to_OM1']);
+          prob = coco_add_glue(prob, gluename, ...
+            om_uidx{i-1}(om_maps{i-1}.p_idx), ...
+            om_uidx{i}(om_maps{i}.p_idx));
+
+          % Parameterize Response Amplitude Difference
+          rdiffname = ['OM', int2str(i-1), 'R_minus_OM', int2str(i), 'R'];
+          rdiffname = coco_get_id(sample_id, rdiffname);      
+          prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+            [], 'inactive', rdiffname, 'uidx', [om_x0{i-1}(1), om_x0{i}(1)]);
+          if add_adjt
+            [chart, lidx] = ...
+              coco_read_adjoint(gluename, ...
+              last_run_name, lab, 'chart', 'lidx');
+
+            prob = coco_add_adjt(prob, gluename, ...
+              'aidx', [om_aidx{i-1}(om_opt{i-1}.p_idx), ...
+              om_aidx{i}(om_opt{i}.p_idx)], ...
+              'l0', chart.x, 'tl0', cdata.v(lidx));
+
+            drdiffname = coco_get_id('d', rdiffname);
+            drdiffnames34{j} = drdiffname;
+            [chart, lidx] = ...
+              coco_read_adjoint(rdiffname, ...
+              last_run_name, lab, 'chart', 'lidx');
+
+            prob = coco_add_adjt(prob, rdiffname, drdiffname, ...
+              'aidx', [om_x0a{i-1}(1), om_x0a{i}(1)], ...
+              'l0', chart.x, 'tl0', cdata.v(lidx));
+          end          
+      end
+    end
+    
+    % Indices and Guesses for later functions
+    s_idx{j} = pk1_uidx(pk1_maps.p_idx);
+    r_igs{j} = pk1_u0(pk1_maps.x0_idx(1));
+    r_idx{j} = pk1_uidx(pk1_maps.x0_idx(1));
+  
+  hyst_fname = coco_get_id(sample_id, 'hyst');
+  hyst_pname = coco_get_id('hyst', int2str(j));
+
+  prob = coco_add_func(prob, hyst_fname, @udiff, ...
+    @udiff_dU, @udiff_dUdU, [], 'active', hyst_pname, ...
+    'uidx', [om_uidx{1}(om_maps{1}.p_idx(6)), ...
+             om_uidx{3}(om_maps{3}.p_idx(6))]);
+  
+  [hyst_idx{j}, oms{j}] = coco_get_func_data(prob, hyst_fname, 'uidx', 'u0');
+  
+  if add_adjt
+    [chart, lidx] = ...
+      coco_read_adjoint(hyst_fname, ...
+      last_run_name, lab, 'chart', 'lidx');
+
+    dhyst_pname = coco_get_id('d', hyst_pname);
+    prob = coco_add_adjt(prob, hyst_fname, dhyst_pname, ...
+      'aidx', [om_aidx{1}(om_opt{1}.p_idx(6)), ...
+      om_aidx{3}(om_opt{3}.p_idx(6))], ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+    
+    hyst_aidx{j} = coco_get_adjt_data(prob, hyst_fname, 'axidx');
+  end
+
+  end
+  
+  psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.Pt, uq_data.spdists);
+  uq_data.wtd_psi_mat = psi_mat*diag(uq_data.wts);
+ 
+  uq_data.s_idx = s_idx;
+  if add_adjt
+    uq_data.adj_s_idx = adj_s_idx;
+  end
+  uq_data.addadjt=add_adjt;
+  [prob, uq_data] = uq_add_sample_nodes(prob, ...
+    coco_func_data(uq_data), adjt_args);
+  
+  igs = zeros(uq_data.nsamples,1);
+  idx = zeros(3, uq_data.nsamples);
+  for i=1:uq_data.nsamples
+    omi = oms{i};
+    igs(i) = r_igs{i} - 5*abs(omi(1) - omi(2));
+    idx(:,i) = [r_idx{i}; hyst_idx{i}];
+  end
+  
+  alpha_ig = uq_data.wtd_psi_mat*igs;
+  response_id = 'resp';
+  prob = coco_add_func(prob, response_id, ...
+    @resp_pce, @resp_pce_dU, @resp_pce_dUdU, ...
+    coco_func_data(uq_data), 'zero', 'uidx', idx(:), 'u0', alpha_ig);
+  
+  if add_adjt
+    aidx = zeros(3, uq_data.nsamples);
+    for i=1:uq_data.nsamples
+      aidx(:,i) = [r_aidx{i}; hyst_aidx{i}];
+    end
+    
+    [chart, lidx] = ...
+      coco_read_adjoint(response_id, ...
+      last_run_name, lab, 'chart', 'lidx');
+    
+    prob = coco_add_adjt(prob, response_id, ...
+      'aidx', aidx(:), ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+
+  end
+
+  alpha_idx = coco_get_func_data(prob, response_id, 'uidx');
+
+  % Grab the last Nt parameters. This will only work for single output
+  % response function.  Leaving it for now, would like to generalize this to
+  % multiple output response functions.
+  alpha_idx = alpha_idx(end-uq_data.Nt+1:end);
+  if add_adjt
+    alpha_aidx = coco_get_adjt_data(prob, response_id, 'axidx');
+    alpha_aidx = alpha_aidx(end-uq_data.Nt+1:end);
+  end
+
+  % Calculate statistics from the PCE
+  % Add zero functions for the mean and variance along with
+  % inactive continuation parameters for tracking their
+  % values.
+
+  % Mean Zero Function
+  mean_id = coco_get_id(response_id, 'pce_mean');
+  prob = coco_add_func(prob, mean_id, ...
+    @uq_pce_mean, @uq_pce_mean_dU, @uq_pce_mean_dUdU, ...
+    uq_data, 'zero', 'uidx', alpha_idx, 'u0', alpha_ig(1));
+
+  % Mean Continuation Parameter
+  mean_par_id = coco_get_id(response_id, 'mean');
+  mean_idx = coco_get_func_data(prob, mean_id, 'uidx');
+  mean_name = coco_get_id(response_id, 'mean');
+  prob = coco_add_pars(prob, mean_par_id, mean_idx(end), mean_name);
+  
+  if add_adjt
+    [chart, lidx] = ...
+      coco_read_adjoint(mean_id, ...
+      last_run_name, lab, 'chart', 'lidx');    
+    
+    prob = coco_add_adjt(prob, mean_id, 'aidx', ...
+      alpha_aidx, ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+    
+    [chart, lidx] = ...
+      coco_read_adjoint(mean_par_id, ...
+      last_run_name, lab, 'chart', 'lidx');
+
+    mean_aidx = coco_get_adjt_data(prob, mean_id, 'axidx');
+    dmean_name = coco_get_id('d', mean_name);
+    prob = coco_add_adjt(prob, mean_par_id, dmean_name, ...
+      'aidx', mean_aidx(end), ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+  end
+
+  % Variance Zero Function
+  var_id = coco_get_id(response_id, 'pce_variance');
+  prob = coco_add_func(prob, var_id, ...
+    @uq_pce_variance, @uq_pce_variance_dU, @uq_pce_variance_dUdU,...
+    uq_data, 'zero', 'uidx', alpha_idx, 'u0', sum(alpha_ig(2:end).^2));
+
+  % Variance Parameter
+  var_par_id = coco_get_id(response_id, 'variance');
+  var_idx = coco_get_func_data(prob, var_id, 'uidx');
+  var_name = coco_get_id(response_id, 'var');
+  prob = coco_add_pars(prob, var_par_id, var_idx(end), var_name);
+  
+  if add_adjt
+    [chart, lidx] = ...
+      coco_read_adjoint(var_id, ...
+      last_run_name, lab, 'chart', 'lidx');
+    
+    prob = coco_add_adjt(prob, var_id, 'aidx', ...
+      alpha_aidx, ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+    
+    [chart, lidx] = ...
+      coco_read_adjoint(var_par_id, ...
+      last_run_name, lab, 'chart', 'lidx');
+
+    var_aidx = coco_get_adjt_data(prob, var_id, 'axidx');
+    dvar_name = coco_get_id('d', var_name);
+    prob = coco_add_adjt(prob, var_par_id, dvar_name, ...
+      'aidx', var_aidx(end), ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+  end
+
+  obj_id = 'obj';
+  prob = coco_add_func(prob, obj_id, ...
+    @obj, @obj_du, @obj_dudu, [], ...
+    'inactive', obj_id, 'uidx', ...
+    [mean_idx(end); var_idx(end)]);
+  
+  if add_adjt
+    [chart, lidx] = ...
+      coco_read_adjoint(obj_id, ...
+      last_run_name, lab, 'chart', 'lidx');
+
+    dobj_id = coco_get_id('d', obj_id);
+    prob = coco_add_adjt(prob, obj_id, dobj_id, ...
+      'aidx', [mean_aidx(end); var_aidx(end)], ...
+      'l0', chart.x, 'tl0', cdata.v(lidx));
+  end
+
+  [uidx, data] = coco_get_func_data(prob, 's1.PK1.bvp.seg1.coll', 'uidx', 'data');
+  mk_idx = uidx(data.coll_seg.maps.p_idx([1,3]));
+  prob = coco_add_func(prob, 'km_constraint', ...
+    @km_const, @km_const_du, @km_const_dudu, [], ...
+    'zero', 'uidx', mk_idx);
+  
+  if add_adjt
+    [aidx, fdata] = coco_get_adjt_data(prob, ...
+      's1.PK1.bvp.seg1.coll', 'axidx', 'data');
+    [chart, lidx] = coco_read_adjoint('km_constraint', ...
+      last_run_name, lab, 'chart', 'lidx');
+
+    mk_aidx = aidx(fdata.coll_opt.p_idx([1,3]));
+
+    prob = coco_add_adjt(prob, 'km_constraint', 'aidx', ...
+      mk_aidx, 'l0', chart.x, 'tl0', cdata.v(lidx));
+  end   
+
+  dnames = coco_get_id('d', pnames([1:3,5]));
+  alnames = uq_get_sample_par_names('alpha', 1:uq_data.nsamples);
+  dalnames = coco_get_id('d', alnames);
+
+  omnames = uq_get_sample_par_names('om', 1:uq_data.nsamples);
+  domnames = coco_get_id('d', omnames);
+  hyst_names = uq_get_sample_par_names('hyst', 1:uq_data.nsamples);
+  pk1_ids = cell(1,uq_data.nsamples);
+  pk2_ids = cell(1,uq_data.nsamples);
+  om1_ids = cell(1,uq_data.nsamples);
+  om2_ids = cell(1,uq_data.nsamples);
+  om3_ids = cell(1,uq_data.nsamples);
+  om4_ids = cell(1,uq_data.nsamples);
+
+  for i=1:uq_data.nsamples
+    pk1_ids{i} = coco_get_id(['s', int2str(i)], 'PK1', 'v0');
+    pk2_ids{i} = coco_get_id(['s', int2str(i)], 'PK2', 'v0');
+    om1_ids{i} = coco_get_id(['s', int2str(i)], 'OM1', 'v0');
+    om2_ids{i} = coco_get_id(['s', int2str(i)], 'OM2', 'v0');
+    om3_ids{i} = coco_get_id(['s', int2str(i)], 'OM3', 'v0');
+    om4_ids{i} = coco_get_id(['s', int2str(i)], 'OM4', 'v0');    
+  end
+  
+  dv10_snames = coco_get_id('d', pk1_ids);
+  dv20_snames = coco_get_id('d', pk2_ids);
+  dv30_snames = coco_get_id('d', om1_ids);
+  dv40_snames = coco_get_id('d', om2_ids);
+  dv50_snames = coco_get_id('d', om3_ids);
+  dv60_snames = coco_get_id('d', om4_ids);
+  
+
+  
+  if add_adjt
+    prob = coco_add_event(prob, 'OPT', 'd.A', 0);
+    pars2free = {obj_id, dnames{4}, 'k', 'm', 'A', mean_name, var_name, omnames{:}, dnames{2}, domnames{:}, dv10_snames{:}, dv20_snames{:}, dv30_snames{:}, dv40_snames{:}, drdiffnames12{:}, dv50_snames{:}, dv60_snames{:},  drdiffnames34{:}, 'd.lo.alpha', 'd.up.alpha'};
+    bd = coco(prob, run_name, [], 1, pars2free);
+  else
+    bd = coco(prob, 'test', [], 1, {'obj', 'A', 'k', omnames{:}, 'resp.mean', 'resp.var'});
+  end
+
+else
+%   bd = coco_bd_read(run_name);
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_freq_sweep.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_freq_sweep.m
new file mode 100644
index 0000000000000000000000000000000000000000..8c41f2dd841242743fa40abfb7cd1c6d1bd8becf
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_freq_sweep.m
@@ -0,0 +1,68 @@
+% Path to vector field, Jacobians, and Response Function
+addpath('../duff')
+addpath('../linode')
+
+% Initialize problem instance and set options
+prob_init = coco_prob();
+
+prob_init = coco_set(prob_init, 'coll', 'NTST', 50, 'NCOL', 6);
+prob_init = coco_set(prob_init, 'cont', 'PtMX', 200);%, ...
+%   'h', 0.5, 'almax', 30, 'h_max', 1000);
+% prob_init = coco_set(prob_init, 'cont', 'NAdapt', 5, 'NPR', 10);
+
+% % Temporarily allow really bad results for some checking of
+% % Jacobians.
+% prob_init = coco_set(prob_init, 'coll', 'TOL', 5);
+
+
+% Let Transients die out
+eps = 0.001;
+%     m, eps*c, k, eps*alpha, eps*F, omega
+cs = eps*(2+0.1*gauss_hermite_nodes(4));
+index=0;
+for c=cs
+  index = index + 1;
+  p0 = [1; c;1;eps*5;eps*5;1];
+  [~, x0]   = ode45(@(t,x) duff(x, p0), ...
+    [0 24*pi], [1; 0; 0]);
+
+  % Initial Solution Guess
+  [t0, x0]   = ode45(@(t,x) duff(x, p0), ...
+    [0 2*pi], [x0(end,1:3)']);
+
+  % 'coll'-toolbox arguments
+  coll_args = {@duff, @duff_dx, @duff_dp, ...
+    @duff_dxdx, @duff_dxdp, @duff_dpdp, ...
+    t0, x0, p0};
+
+  % parameter names
+  pnames = {'m', 'c', 'k', 'eps', 'A', 'om'};
+
+  % 'bvp'-toolbox arguments
+  bvp_args = {@duff_bc, @duff_bc_du, @duff_bc_dudu};
+
+  uq_args = {
+    {'c'}, ...        % Stochastic Parameter
+    {'Normal'}, ...   % Distribution Type
+    [[eps*2,eps*0.01]], ...    % Distribution Parameters
+    {}};%, ...
+  %   '-add-adjt'};   % Option to add the adjoint
+                    % equations to the uq probs
+
+  % prob = uq_isol2bvp_sample(prob_init, 'duff', coll_args{:}, pnames, bvp_args{:}, uq_args{:});
+  % prob = uq_coll_add_response(prob, 'duff', 'resp', 'bv', @x10, @x10_du, @x10_dudu);
+  % prob = uq_coll_add_response_adjoint(prob, 'duff', 'resp');
+  % prob = coco_set(prob, 'cont', 'PtMX', 5000);%, ...
+  % bd = coco(prob, 'duff', [], 1, {'om', 'duff.resp.mean', 'duff.resp.var'}, [0.5, 3]);
+  % bd = coco(prob, 'duff', [], 1, {'duff.resp.mean', 'om', 'duff.resp.var', ...
+  %   'd.duff.resp.mean', 'd.duff.resp.var', 'd.om', 'd.k', 'd.m', 'd.eps', 'd.A'});
+
+  % Deterministic:
+  prob = ode_isol2bvp(prob_init, '', coll_args{:}, pnames, bvp_args{:});
+  [data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
+  maps = data.coll_seg.maps;
+  x0 = uidx(maps.x0_idx);
+  prob = coco_add_pars(prob, 'A', x0(1), 'x01', 'inactive');
+
+  bd = coco(prob, coco_get_id('duff', int2str(index)), [], 1, {'om', 'x01'});
+end
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_uq_nds.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_uq_nds.m
new file mode 100644
index 0000000000000000000000000000000000000000..9e0cf41b18d0006527ea45861e02d0fef0befb2b
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_uq_nds.m
@@ -0,0 +1,106 @@
+last_run_name = 'fold_find_btm';
+run_name = 'uq_nds';
+bd = coco_bd_read(last_run_name);
+labs = coco_bd_labs(bd, 'UZ');
+lab = labs(1);
+prob = coco_prob();
+prob = coco_set(prob, 'coll', 'NTST', 30);
+prob = ode_bvp2bvp(prob, 'PK1', last_run_name, lab);
+bvp_data = coco_get_func_data(prob, 'PK1.bvp', 'data');
+
+[pk1_data, pk1_uidx] = coco_get_func_data(prob, ...
+  'PK1.bvp.seg1.coll', 'data', 'uidx');
+pk1_maps = pk1_data.coll_seg.maps;
+pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+% Maintain velocity constraint (could also be done with a
+% boundary condition)
+prob = coco_add_pars(prob, 'PK1.v0', pk1_x0(2), ...
+  'PK1.v0', 'inactive');
+
+prob = ode_coll2coll(prob, 'PK2', last_run_name, lab);
+
+% Boundary conditions for PK2
+[pk2_data, pk2_uidx] = coco_get_func_data(prob, 'PK2.coll', 'data', 'uidx');
+pk2_maps = pk2_data.coll_seg.maps;
+
+args = pk2_uidx([pk2_maps.T0_idx; pk2_maps.T_idx; pk2_maps.x0_idx; ...
+  pk2_maps.x1_idx; pk2_maps.p_idx]);
+prob = coco_add_func(prob, 'PK2.bvp', @duff_bc_caf, ...
+  @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+  'zero', 'uidx', args);
+
+pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+
+% Maintain velocity constraint (could also be done with a
+% boundary condition)
+prob = coco_add_pars(prob, 'PK2.v0', pk2_x0(2), ...
+  'PK2.v0', 'inactive');
+
+% Glue Parameters together (except forcing frequency)
+prob = coco_add_glue(prob, 'par_glue', pk2_uidx(pk2_maps.p_idx(1:5)), ...
+  pk1_uidx(pk1_maps.p_idx(1:5)));
+prob = coco_add_glue(prob, 'PK.R.glue', pk2_x0(1), pk1_x0(1));
+
+% Parameterize frequency difference
+prob = coco_add_func(prob, 'om_diff', @udiff, @udiff_dU, @udiff_dUdU, ...
+  [], 'inactive', 'eps_om', 'uidx', [pk2_uidx(pk2_maps.p_idx(6)), ...
+  pk1_uidx(pk1_maps.p_idx(6))]);
+
+for i=1:3
+  OMi_name = strcat('OM', int2str(i));
+  prob = ode_bvp2bvp(prob, OMi_name, last_run_name, lab);
+  % Boundary conditions for OMi
+  [om_data{i}, om_uidx{i}] = coco_get_func_data(prob, ...
+    coco_get_id(strcat('OM', int2str(i)),'bvp', 'seg1', 'coll'), 'data', 'uidx');
+  om_maps{i} = om_data{i}.coll_seg.maps;
+
+  % Maintain velocity constraint
+  v0name = coco_get_id(strcat('OM', int2str(i)),'v0');
+  om_x0{i} = om_uidx{i}(om_maps{i}.x0_idx);
+  prob = coco_add_pars(prob, v0name, om_x0{i}(2), v0name, 'inactive');
+
+  % Glue Parameters together
+  if i > 1
+    % The fold approximants share all parameter values.
+    % They differ only in response amplitude 
+    % {'OM1.R', 'OM2.R', 'OM3.R'}
+
+    gluename = ['OM', int2str(i), '.to.OM1'];
+    prob = coco_add_glue(prob, gluename, ...
+      om_uidx{1}(om_maps{1}.p_idx), ...
+      om_uidx{i}(om_maps{i}.p_idx));
+
+    % Parameterize Response Amplitude Difference
+    rdiffname = ['eps_R', int2str(i-1)];
+    prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+      [], 'inactive', rdiffname, 'uidx', [om_x0{i-1}(1), om_x0{i}(1)]);
+
+  else
+    gluename = ['OM', int2str(i), '.to.PK1'];
+    prob = coco_add_glue(prob, gluename, ...
+      pk2_uidx(pk2_maps.p_idx(1:5)), ...
+      om_uidx{1}(om_maps{1}.p_idx(1:5)));
+  end
+end
+
+pars_to_release = {'om'};
+%% UQ Toolbox Arguments
+args = struct();
+args.spdists = {'Uniform'};
+args.spnames = {'c'};
+args.spdp = [0.1, 0.5];
+args.dpdtpars = {'A'};
+opts=struct();
+opts.addadjt = 1;
+%% Initialize UQ Data Structure
+bvp_id = coco_get_id('PK1', 'bvp');
+bc_data = coco_get_func_data(prob, bvp_id, 'data');  
+uq_data = bvp_uq_init_data(bc_data, 'PK1');
+% Calculates Integration nodes and weights for the
+% continuation problem.
+uq_data = uq_init_data(prob, uq_data, args, opts);
+
+% Mark the integration node locations with the label 'UQ'
+prob = coco_add_event(prob, 'UQ', 'c', uq_data.nds);
+bd = coco(prob, run_name, [], 1, {'c', 'om', 'A'},[0.1,0.5]);
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_uq_nds_func.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_uq_nds_func.m
new file mode 100644
index 0000000000000000000000000000000000000000..c608cc11415684caa342fa60fa7bfe1938e53c1a
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/demo_uq_nds_func.m
@@ -0,0 +1,108 @@
+function uq_data = demo_uq_nds_func(M,Pt)
+last_run_name = 'fold_find_btm';
+run_name = 'uq_nds_M_P_vary';
+bd = coco_bd_read(last_run_name);
+labs = coco_bd_labs(bd, 'UZ');
+lab = labs(1);
+prob = coco_prob();
+prob = coco_set(prob, 'coll', 'NTST', 30);
+prob = coco_set(prob, 'cont', 'h', 5, 'h_min', 1e-5, 'h_max', 1e5);
+prob = ode_bvp2bvp(prob, 'PK1', last_run_name, lab);
+bvp_data = coco_get_func_data(prob, 'PK1.bvp', 'data');
+
+[pk1_data, pk1_uidx] = coco_get_func_data(prob, ...
+  'PK1.bvp.seg1.coll', 'data', 'uidx');
+pk1_maps = pk1_data.coll_seg.maps;
+pk1_x0 = pk1_uidx(pk1_maps.x0_idx);
+
+% Maintain velocity constraint (could also be done with a
+% boundary condition)
+prob = coco_add_pars(prob, 'PK1.v0', pk1_x0(2), ...
+  'PK1.v0', 'inactive');
+
+prob = ode_coll2coll(prob, 'PK2', last_run_name, lab);
+
+% Boundary conditions for PK2
+[pk2_data, pk2_uidx] = coco_get_func_data(prob, 'PK2.coll', 'data', 'uidx');
+pk2_maps = pk2_data.coll_seg.maps;
+
+args = pk2_uidx([pk2_maps.T0_idx; pk2_maps.T_idx; pk2_maps.x0_idx; ...
+  pk2_maps.x1_idx; pk2_maps.p_idx]);
+prob = coco_add_func(prob, 'PK2.bvp', @duff_bc_caf, ...
+  @duff_bc_caf_du, @duff_bc_caf_dudu, bvp_data, ...
+  'zero', 'uidx', args);
+
+pk2_x0 = pk2_uidx(pk2_maps.x0_idx);
+
+% Maintain velocity constraint (could also be done with a
+% boundary condition)
+prob = coco_add_pars(prob, 'PK2.v0', pk2_x0(2), ...
+  'PK2.v0', 'inactive');
+
+% Glue Parameters together (except forcing frequency)
+prob = coco_add_glue(prob, 'par_glue', pk2_uidx(pk2_maps.p_idx(1:5)), ...
+  pk1_uidx(pk1_maps.p_idx(1:5)));
+prob = coco_add_glue(prob, 'PK.R.glue', pk2_x0(1), pk1_x0(1));
+
+% Parameterize frequency difference
+prob = coco_add_func(prob, 'om_diff', @udiff, @udiff_dU, @udiff_dUdU, ...
+  [], 'inactive', 'eps_om', 'uidx', [pk2_uidx(pk2_maps.p_idx(6)), ...
+  pk1_uidx(pk1_maps.p_idx(6))]);
+prob = coco_set_parival(prob, 'eps_om', 1e-2);
+for i=1:3
+  OMi_name = strcat('OM', int2str(i));
+  prob = ode_bvp2bvp(prob, OMi_name, last_run_name, lab);
+  % Boundary conditions for OMi
+  [om_data{i}, om_uidx{i}] = coco_get_func_data(prob, ...
+    coco_get_id(strcat('OM', int2str(i)),'bvp', 'seg1', 'coll'), 'data', 'uidx');
+  om_maps{i} = om_data{i}.coll_seg.maps;
+
+  % Maintain velocity constraint
+  v0name = coco_get_id(strcat('OM', int2str(i)),'v0');
+  om_x0{i} = om_uidx{i}(om_maps{i}.x0_idx);
+  prob = coco_add_pars(prob, v0name, om_x0{i}(2), v0name, 'inactive');
+
+  % Glue Parameters together
+  if i > 1
+    % The fold approximants share all parameter values.
+    % They differ only in response amplitude 
+    % {'OM1.R', 'OM2.R', 'OM3.R'}
+
+    gluename = ['OM', int2str(i), '.to.OM1'];
+    prob = coco_add_glue(prob, gluename, ...
+      om_uidx{1}(om_maps{1}.p_idx), ...
+      om_uidx{i}(om_maps{i}.p_idx));
+
+    % Parameterize Response Amplitude Difference
+    rdiffname = ['eps_R', int2str(i-1)];
+    prob = coco_add_func(prob, rdiffname, @udiff, @udiff_dU, @udiff_dUdU, ...
+      [], 'inactive', rdiffname, 'uidx', [om_x0{i-1}(1), om_x0{i}(1)]);
+    prob = coco_set_parival(prob, rdiffname, 1e-2);
+  else
+    gluename = ['OM', int2str(i), '.to.PK1'];
+    prob = coco_add_glue(prob, gluename, ...
+      pk2_uidx(pk2_maps.p_idx(1:5)), ...
+      om_uidx{1}(om_maps{1}.p_idx(1:5)));
+  end
+end
+
+pars_to_release = {'om'};
+%% UQ Toolbox Arguments
+args = struct(); opts=struct();
+args.spnames = {'c'};
+args.spdists = {'Uniform'};
+args.spdp = [0.1, 0.5];
+args.dpdtpars = {'A'};
+opts.addadjt = 1;
+%% Initialize UQ Data Structure
+bvp_id = coco_get_id('PK1', 'bvp');
+bc_data = coco_get_func_data(prob, bvp_id, 'data');  
+uq_data = bvp_uq_init_data(bc_data, 'PK1');
+prob = coco_set(prob, 'uq', 'M', M, 'Pt', Pt);
+uq_data = uq_init_data(prob, uq_data, args, opts);
+
+% Mark the integration node locations with the label 'UQ'
+prob = coco_add_event(prob, 'UQ', 'c', uq_data.nds);
+bd = coco(prob, run_name, [], 1, ...
+  {'c', 'A', pars_to_release{:}},[0.1,0.5]);
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/dwdk.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/dwdk.m
new file mode 100644
index 0000000000000000000000000000000000000000..d5cb5713f5d361bf4279ee1bbf8491acce0185f3
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/dwdk.m
@@ -0,0 +1,3 @@
+function y = dwdk(k)
+y = 1./(2*sqrt(k)) + (3*25*5*0.001)./(15*4*k.^2.*sqrt(k))-(3*5^2*sqrt(k)*5*0.001)./((4*2^2)*k.^3);
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/k-m-obj.png b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/k-m-obj.png
new file mode 100644
index 0000000000000000000000000000000000000000..a6d8124c262afbf1ebdcc275534ec619f5ac28d0
Binary files /dev/null and b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/k-m-obj.png differ
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/km_const.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/km_const.m
new file mode 100644
index 0000000000000000000000000000000000000000..34b06c9849720a2e0bc3661f511919b24768a4ca
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/km_const.m
@@ -0,0 +1,12 @@
+function [data, y] = km_const(prob, data, u)
+%KM_CONST Summary of this function goes here
+%   Detailed explanation goes here
+
+m = u(1);
+k = u(2);
+
+y = 1 - (k-2)^2 - (m-2)^2;
+
+
+end
+
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/km_const_du.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/km_const_du.m
new file mode 100644
index 0000000000000000000000000000000000000000..71b6fa7cc856d8142df8642da614a22cff8aee65
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/km_const_du.m
@@ -0,0 +1,12 @@
+function [data, J] = km_const_du(prob, data, u)
+%KM_CONST Summary of this function goes here
+%   Detailed explanation goes here
+
+m = u(1);
+k = u(2);
+
+J = [-2*(m-2), -2*(k-2)];
+
+
+end
+
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/km_const_dudu.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/km_const_dudu.m
new file mode 100644
index 0000000000000000000000000000000000000000..e9dcebef27c117bbbf1f812395b624126a4b0a3d
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/km_const_dudu.m
@@ -0,0 +1,14 @@
+function [data, dJ] = km_const_dudu(prob, data, u)
+%KM_CONST Summary of this function goes here
+%   Detailed explanation goes here
+
+m = u(1);
+k = u(2);
+
+dJ = zeros(1,2,2);
+dJ(:,1,1) = -2;
+dJ(:,2,2) = -2;
+
+
+end
+
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/obj.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/obj.m
new file mode 100644
index 0000000000000000000000000000000000000000..efdae46ace2919bb4338b424e4ce69bb864d069f
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/obj.m
@@ -0,0 +1,9 @@
+function [data, y] = obj(prob, data, u)
+
+mu = u(1);
+var = u(2);
+m = 1;
+n=1;
+y = m*mu - n*sqrt(var);
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/obj_du.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/obj_du.m
new file mode 100644
index 0000000000000000000000000000000000000000..e15f4a93eb4c5a687c08d8c97cccc8b5e086fca6
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/obj_du.m
@@ -0,0 +1,10 @@
+function [data, J] = obj_du(prob, data, u)
+
+mu = u(1);
+var = u(2);
+
+m = 1;
+n = 1;
+J = [m, n*(-1/2)*(var)^(-1/2)];
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/obj_dudu.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/obj_dudu.m
new file mode 100644
index 0000000000000000000000000000000000000000..7ff6d45928afac3ff69000a667ae6477481e2c82
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/obj_dudu.m
@@ -0,0 +1,11 @@
+function [data, dJ] = obj_dudu(prob, data, u)
+
+dJ = zeros(1,2,2);
+var = u(2);
+
+m=1;
+n=1;
+dJ(1,2,2) = n*(1/4)*(var)^(-3/2);
+% Checked with
+% [data, dJd] = coco_ezDFDX('f(o,d,x)', prob, data, @obj_du, u);
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_duff_freq_sweep.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_duff_freq_sweep.m
new file mode 100644
index 0000000000000000000000000000000000000000..1b860d39ffccbe8c9c49da4f4f6a99233a274bf7
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_duff_freq_sweep.m
@@ -0,0 +1,55 @@
+bd4 = coco_bd_read('duff_freq_sweep_M=4_P=4');
+% bd8 = coco_bd_read('duff_freq_sweep_M=8_P=4');
+% bd10 = coco_bd_read('duff_freq_sweep_M=10_P=4');
+% bd12 = coco_bd_read('duff_freq_sweep_M=12_P=4');
+% 
+figure(1)
+hold on
+
+mu.R = cell2mat(bd4(2:end, 31));
+om = cell2mat(bd4(2:end, 24));
+[~, min_idx] = min(abs(om - 0.95));
+[~, max_idx] = min(abs(om - 1.05));
+semilogx(om([min_idx:max_idx]), mu.R([min_idx:max_idx]));
+% 
+% mu.R = cell2mat(bd8(2:end, 47));
+% om = cell2mat(bd8(2:end, 36));
+% [~, min_idx] = min(abs(om - 0.95));
+% [~, max_idx] = min(abs(om - 1.05));
+% semilogx(om([min_idx:max_idx]), mu.R([min_idx:max_idx]));
+% 
+% mu.R = cell2mat(bd10(2:end, 55));
+% om = cell2mat(bd10(2:end, 42));
+% [~, min_idx] = min(abs(om - 0.95));
+% [~, max_idx] = min(abs(om - 1.05));
+% semilogx(om([min_idx:max_idx]), mu.R([min_idx:max_idx]));
+% 
+% mu.R = cell2mat(bd12(2:end, 63));
+% om = cell2mat(bd12(2:end, 48));
+% [~, min_idx] = min(abs(om - 0.95));
+% [~, max_idx] = min(abs(om - 1.05));
+% semilogx(om([min_idx:max_idx]), mu.R([min_idx:max_idx]));
+
+% axis([0.95 1.05 0 4])
+% legend('M=4', 'M=8', 'M=10')
+
+
+M=4;
+run_name = 'duff_freq_sweep_M=4_P=4';
+% bd = coco_bd_read(run_name);
+labs = coco_bd_labs(bd4);
+data_mat = zeros(size(labs,2), M+1);
+j = 1;
+for lab=labs
+  for i=1:M
+    curve_name = strcat('duff.uq.sample', int2str(i));    
+    sol = coll_read_solution(curve_name, run_name, lab);
+    data_mat(j, i+1) = sol.xbp(1,1);
+  end
+  data_mat(j,1) = sol.p(6);
+  j = j + 1;
+end
+legend('show')
+axis([0.98 1.02 0 3])
+set(gca, 'xscale', 'log')
+grid on
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_samples.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_samples.m
new file mode 100644
index 0000000000000000000000000000000000000000..ed07e96d5e4f80c57fee33807922ef30e3d46899
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_samples.m
@@ -0,0 +1,71 @@
+bd = coco_bd_read('uq_sweep');
+
+A_idx      = strcmpi('A', bd(1,:));
+k_idx      = strcmpi('k', bd(1,:));
+m_idx      = strcmpi('m', bd(1,:));
+s1pk1r_idx = strcmpi('s1.PK1.R', bd(1,:));
+s2pk1r_idx = strcmpi('s2.PK1.R', bd(1,:));
+s3pk1r_idx = strcmpi('s3.PK1.R', bd(1,:));
+s4pk1r_idx = strcmpi('s4.PK1.R', bd(1,:));
+hyst1_idx  = strcmpi('hyst.1', bd(1,:));
+hyst2_idx  = strcmpi('hyst.2', bd(1,:));
+hyst3_idx  = strcmpi('hyst.3', bd(1,:));
+hyst4_idx  = strcmpi('hyst.4', bd(1,:));
+om1_idx    = strcmpi('om.1', bd(1,:));
+
+% mu_idx = strcmpi('resp.mean', bd(1,:));
+% sig_idx = strcmpi('resp.var', bd(1,:));
+
+A     = cell2mat(bd(2:end, A_idx));
+k     = cell2mat(bd(2:end, k_idx));
+m     = cell2mat(bd(2:end, m_idx));
+om1   = cell2mat(bd(2:end, om1_idx));
+
+o = coco_bd_col(bd, 'obj');
+mag = 5;
+mag2 = 1;
+s1pk1 = cell2mat(bd(2:end, s1pk1r_idx));
+hyst1 = cell2mat(bd(2:end, hyst1_idx));
+s1 = s1pk1 - mag*abs(hyst1);
+
+s2pk1 = cell2mat(bd(2:end, s2pk1r_idx));
+hyst2 = cell2mat(bd(2:end, hyst2_idx));
+s2 = s2pk1 - mag*abs(hyst2);
+
+s3pk1 = cell2mat(bd(2:end, s3pk1r_idx));
+hyst3 = cell2mat(bd(2:end, hyst3_idx));
+s3 = s3pk1 - mag*abs(hyst3);
+
+s4pk1 = cell2mat(bd(2:end, s4pk1r_idx));
+hyst4 = cell2mat(bd(2:end, hyst4_idx));
+s4 = s4pk1 - mag*abs(hyst4);
+alphas = uq_data.wtd_psi_mat*[s1,s2,s3,s4]';
+
+mu = alphas(1,:);
+var = sum(alphas(2:end,:).^2);
+
+% o = coco_bd_col(bd, 'resp.mean') - mag2*sqrt(coco_bd_col(bd, 'resp.var'));
+o0 = mu;
+o1 = mu - 1*sqrt(var);
+o2 = mu - 2*sqrt(var);
+o3 = mu - 3*sqrt(var);
+[~, idx0] = max(o0);
+[~, idx1] = max(o1);
+[~, idx2] = max(o2);
+[~, idx3] = max(o3);
+
+figure(1)
+plot(k, o1)
+plot(A, s1, A, s2, A, s3, A, s4)
+hold on
+plot(A, o0, 'r--', A, o1, 'k--', A, o2, 'g--', A, o3, 'b--', 'LineWidth', 2)
+plot(A(idx0), o0(idx0), 'ro', A(idx1), o1(idx1), 'ko', A(idx2), o2(idx2), 'go', A(idx3), o3(idx3), 'bo', 'LineWidth', 2)
+
+figure(2)
+plot([A,A,A,A], [s1pk1, s2pk1, s3pk1, s4pk1])
+
+hold on
+plot([A,A,A,A], mag*abs([hyst1, hyst2, hyst3, hyst4]))
+
+figure(4)
+plot(A, o)
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_swp.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_swp.m
new file mode 100644
index 0000000000000000000000000000000000000000..32bbf9c3725a5de0a9e10e49f7f900e9fd6c88f3
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_swp.m
@@ -0,0 +1,37 @@
+
+function plot_swp(run_name, lab)
+  prob = coco_prob();
+  prob = coco_set(prob, 'coll', 'NTST', 20);
+  prob = ode_bvp2bvp(prob, '', run_name, 'PK1', lab);
+  
+  [data, uidx] = coco_get_func_data(prob, 'bvp.seg1.coll', 'data', 'uidx');
+  maps = data.coll_seg.maps;
+  x0 = uidx(maps.x0_idx);
+%   pnames = {'m', 'c', 'k', 'alpha', 'A', 'om'};
+%   prob = coco_add_pars(prob, 's1.PK1.pars', maps.p_idx, pnames, 'inactive');
+  prob = coco_add_pars(prob, 'R', x0(1), 'R', 'inactive');
+  % Maintain velocity constraint
+  prob = coco_add_pars(prob, 'v0', x0(2), 'v0', 'inactive');
+
+  bd_swp = coco(prob, 'plot_swp', [], 1, {'om', 'R'}, {[0.01, 10]});
+  om_idx = strcmpi('om', bd_swp(1,:));
+  r_idx = strcmpi('R', bd_swp(1,:));
+  semilogx(cell2mat(bd_swp(2:end, om_idx)), ...
+           cell2mat(bd_swp(2:end, r_idx)));
+  hold on
+  bd = coco_bd_read(run_name);
+  lab_idx = strcmpi('LAB', bd(1,:));
+  om_idx = strcmpi('om', bd(1,:));
+  pk1r_idx = strcmpi('PK1.R', bd(1,:));
+  pk2r_idx = strcmpi('PK2.R', bd(1,:));
+  omdiff_idx = strcmpi('om_diff', bd(1,:));
+  tf = cellfun('isempty', bd(:, lab_idx));
+  bd(tf, lab_idx)={0};
+  lab_idx = find(cell2mat(bd(2:end,lab_idx))==lab)+1;
+  om1 = cell2mat(bd(lab_idx, om_idx));
+  pk1 = cell2mat(bd(lab_idx, pk1r_idx));
+  om2 = om1 + cell2mat(bd(lab_idx, omdiff_idx));
+  pk2 = cell2mat(bd(lab_idx, pk2r_idx));
+  
+  plot([om1, om2], [pk1, pk2],'ro')
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_testing.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_testing.m
new file mode 100644
index 0000000000000000000000000000000000000000..aedad211423293160406550e8bcb9b754500ba34
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/plot_testing.m
@@ -0,0 +1,10 @@
+figure(1)
+hold on
+
+for i=1:4
+  bd = coco_bd_read(strcat('duff.', int2str(i)));
+  plot(cell2mat(bd(2:end, 16)), cell2mat(bd(2:end, 17)));
+end
+legend('show')
+axis([0.98 1.02 0 3])
+set(gca, 'xscale', 'log')
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/res_freq.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/res_freq.m
new file mode 100644
index 0000000000000000000000000000000000000000..5838319574edf9abe498d558a4b62f5052de353e
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/res_freq.m
@@ -0,0 +1,11 @@
+function w0 = res_freq(m)
+  eps = 0.01;
+  c = 2;
+  k = 1;
+  alpha = 5;
+  F = 5;
+  
+%  Rm = F/c Sqrt[m/k]
+% \[Omega] = Sqrt[k/m] + \[Epsilon] (3 \[Alpha])/(8 k) Sqrt[k/m] Rm^2;
+  w0 = sqrt(k./m) + eps*(3*alpha/(8*k))*sqrt(k./m).*((F/c)*sqrt(m./k)).^2;
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/res_peak.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/res_peak.m
new file mode 100644
index 0000000000000000000000000000000000000000..32f68acfeec5cbaddeadbce11d8ac4d98a2b2b81
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/res_peak.m
@@ -0,0 +1,5 @@
+function rm = res_peak(m)
+
+rm = (F/c)*sqrt(m/k);
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/res_sens.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/res_sens.m
new file mode 100644
index 0000000000000000000000000000000000000000..30a386b8f25bbcef9ab3f963cb4fd81747b99157
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/res_sens.m
@@ -0,0 +1,15 @@
+function dwdm = res_sens(m, F)
+
+% -(k/(2 Sqrt[k/m] m^2)) + (3 F^2 Sqrt[k/m] \[Alpha] \[Epsilon])/(
+%  8 c^2 k^2) - (3 F^2 \[Alpha] \[Epsilon])/(16 c^2 k Sqrt[k/m] m)
+
+eps = 0.001;
+c = 2;
+k = 1;
+alpha = 5;
+F = 20;
+
+dwdm = -k./(2*sqrt(k./m).*m.^2) + (3*F^2*sqrt(k./m)*alpha*eps)./(8*c^2*k^2) - ...
+  3*F^2*alpha*eps./(16*c^2*k*sqrt(k./m).*m);
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/resp_pce.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/resp_pce.m
new file mode 100644
index 0000000000000000000000000000000000000000..5525de924cb77659c7c6042971819b26dfdd167e
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/resp_pce.m
@@ -0,0 +1,13 @@
+function [data, y] = resp_pce(prob, data, u)
+%UQ_PCE_COEFFICIENTS Summary of this function goes here
+%   Evaluate Response function and calculate coefficients of polynomial
+%   chaos expansion.
+
+r = u(1:end-data.Nt);
+
+alphas = u(end-data.Nt+1:end);
+R = data.wtd_psi_mat*r;
+
+y = alphas - R;
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/resp_pce_dU.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/resp_pce_dU.m
new file mode 100644
index 0000000000000000000000000000000000000000..3061bf1d16cb93e30e59fdd7e012b0af8d2d8d87
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/resp_pce_dU.m
@@ -0,0 +1,18 @@
+function [data, J] = resp_pce_dU(prob, data, u)
+% UQ_PCE_COEFFICIENTS_DU Jacobian of the Polynomial Chaos
+% Expansion (PCE) coefficient Evaluation function
+
+x = reshape(u(1:end-data.Nt), [], data.nsamples);
+
+r = (x(1,:))';
+dr = -data.wtd_psi_mat*eye(numel(r));
+
+J = [dr, ...       % dr/du
+     eye(data.Nt)];  % alphas are linear
+
+%% Test Jacobian with following sequence:
+% [data, Jd] = coco_ezDFDX('f(o,d,x)', prob, data, @resp_pce, u);
+% diff_J = abs(J-Jd);
+% max(max(diff_J))
+% fprintf('test')
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/resp_pce_dUdU.m b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/resp_pce_dUdU.m
new file mode 100644
index 0000000000000000000000000000000000000000..e0dc549b2b788831768beb41fb390a343ee8d526
--- /dev/null
+++ b/coco_example_runs/ch_5_duff_robust_optimization/duff_v2/resp_pce_dUdU.m
@@ -0,0 +1,12 @@
+function [data, dJ] = resp_pce_dUdU(prob, data, u)
+% UQ_PCE_COEFFICIENTS_DU Jacobian of the Polynomial Chaos
+% Expansion (PCE) coefficient Evaluation function
+
+dJ = zeros(data.Nt, numel(u), numel(u));
+   
+%% Test Jacobian with following sequence:
+% [data, dJd] = coco_ezDFDX('f(o,d,x)', prob, data, @resp_pce_dU, u);
+% diff_dJ = abs(dJ-dJd);
+% max(max(diff_dJ))
+% fprintf('test')
+end
\ No newline at end of file
diff --git a/coco_example_runs/ch_5_duff_robust_optimization/nla/demo_uq_2.m b/coco_example_runs/ch_5_duff_robust_optimization/nla/demo_uq_2.m
index 8fc441cbd8020ccab32cfdd70e4bd232887dbd42..966179733d29b3340e613fbb59ae39762e12bdc6 100644
--- a/coco_example_runs/ch_5_duff_robust_optimization/nla/demo_uq_2.m
+++ b/coco_example_runs/ch_5_duff_robust_optimization/nla/demo_uq_2.m
@@ -575,7 +575,7 @@ if not(coco_exist(run_name, 'run')) || true
   end
   end
 
-  psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.P, uq_data.spdists);
+  psi_mat = uq_make_psi_mat(uq_data.nds_grid, uq_data.uq.Pt, uq_data.spdists);
   uq_data.wtd_psi_mat = psi_mat*diag(uq_data.wts);
   uq_data.s_idx = s_idx;  
   prob = uq_add_sample_nodes(prob, uq_data);
diff --git a/coco_example_runs/duff/duff_bc_v2.m b/coco_example_runs/duff/duff_bc_v2.m
new file mode 100644
index 0000000000000000000000000000000000000000..7fcb92930031978951b89b139f803b8ef26e6d8a
--- /dev/null
+++ b/coco_example_runs/duff/duff_bc_v2.m
@@ -0,0 +1,6 @@
+function y = duff_bc(data, T, x0, x1, p)
+
+y = [x1(1)-x0(1); x1(2)-x0(2); x1(3)-x0(3)-2*pi; x0(2)];
+
+end
+
diff --git a/coco_example_runs/duff/duff_bc_v2_du.m b/coco_example_runs/duff/duff_bc_v2_du.m
new file mode 100644
index 0000000000000000000000000000000000000000..af0ceaa70bb5f73c543d6cea80a668028e5356b1
--- /dev/null
+++ b/coco_example_runs/duff/duff_bc_v2_du.m
@@ -0,0 +1,9 @@
+function J = duff_bc_du(data, T, x0, x1, p)
+
+%     T  x01 x02 x03 x11 x12 x13  m   c   k  eps  A   w
+J = [ 0  -1   0   0   1   0   0   0   0   0   0   0   0;
+      0   0  -1   0   0   1   0   0   0   0   0   0   0;
+      0   0   0  -1   0   0   1   0   0   0   0   0   0;
+      0   0   1   0   0   0   0   0   0   0   0   0   0;
+     ];
+end
\ No newline at end of file
diff --git a/coco_example_runs/duff/duff_bc_v2_dudu.m b/coco_example_runs/duff/duff_bc_v2_dudu.m
new file mode 100644
index 0000000000000000000000000000000000000000..c9871510ce37d39641c37a2118644387153820d2
--- /dev/null
+++ b/coco_example_runs/duff/duff_bc_v2_dudu.m
@@ -0,0 +1,5 @@
+function dJ = duff_bc_dudu(data, T, x0, x1, p)
+
+dJ = zeros(4,13,13);
+
+end
\ No newline at end of file
diff --git a/coco_example_runs/linode/linode_het.m b/coco_example_runs/linode/linode.m
similarity index 87%
rename from coco_example_runs/linode/linode_het.m
rename to coco_example_runs/linode/linode.m
index fd4c3e493764c18a0391aebbee0cb454b14a2959..62aee1bf4c5bf7d0e0a13b52deac31b53d623446 100644
--- a/coco_example_runs/linode/linode_het.m
+++ b/coco_example_runs/linode/linode.m
@@ -1,4 +1,4 @@
-function y = linode_het(t, x, p)
+function y = linode(t, x, p)
 %LINODE_HET   'coll'-compatible encoding of linode vector field.
 %
 % Encoding is of a non-autonomous vector field.
diff --git a/coco_example_runs/linode/linode_bc.m b/coco_example_runs/linode/linode_bc.m
new file mode 100644
index 0000000000000000000000000000000000000000..c2eac7005271ba493a5c191889658367b90eaaf4
--- /dev/null
+++ b/coco_example_runs/linode/linode_bc.m
@@ -0,0 +1,11 @@
+function [data, y] = linode_bc(prob, data, u) %#ok<INUSL>
+
+x0 = u(1:2);
+x1 = u(3:4);
+T0 = u(5);
+T  = u(6);
+om = u(7);
+
+y = [x1(1:2)-x0(1:2); T0; T-2*pi./om];
+
+end
diff --git a/coco_example_runs/linode/linode_het_bc_dU.m b/coco_example_runs/linode/linode_bc_du.m
similarity index 86%
rename from coco_example_runs/linode/linode_het_bc_dU.m
rename to coco_example_runs/linode/linode_bc_du.m
index 378ecec5e84443e19c38d1545a196cd2499e2dca..05247669a8466b3b3cf53301790dcba54dedf1bf 100644
--- a/coco_example_runs/linode/linode_het_bc_dU.m
+++ b/coco_example_runs/linode/linode_bc_du.m
@@ -1,4 +1,4 @@
-function [data, J] = linode_het_bc_dU(prob, data, u) %#ok<INUSL>
+function [data, J] = linode_bc_du(prob, data, u) %#ok<INUSL>
 %LINODE_HET_BC   'bvp'-compatible encoding of linode boundary conditions
 %
 % Encoding is of a non-autonomous vector field.
diff --git a/coco_example_runs/linode/linode_het_bc_dUdU.m b/coco_example_runs/linode/linode_bc_dudu.m
similarity index 86%
rename from coco_example_runs/linode/linode_het_bc_dUdU.m
rename to coco_example_runs/linode/linode_bc_dudu.m
index 20211c710b2dc55df203a2c2bbff9b0e42c7a179..f25f0f309250b338aa1eeb62efe4996b8accd0e1 100644
--- a/coco_example_runs/linode/linode_het_bc_dUdU.m
+++ b/coco_example_runs/linode/linode_bc_dudu.m
@@ -1,4 +1,4 @@
-function [data, dJ] = linode_het_bc_dUdU(prob, data, u) %#ok<INUSL>
+function [data, dJ] = linode_bc_dudu(prob, data, u) %#ok<INUSL>
 %LINODE_HET_BC   'bvp'-compatible encoding of linode boundary conditions
 %
 % Encoding is of a non-autonomous vector field.
diff --git a/coco_example_runs/linode/linode_het_DFDP.m b/coco_example_runs/linode/linode_dp.m
similarity index 80%
rename from coco_example_runs/linode/linode_het_DFDP.m
rename to coco_example_runs/linode/linode_dp.m
index 4de33498c9977fc0400481fb977556170fd02d15..219b283746121e3320988273416624f2aaa28a95 100644
--- a/coco_example_runs/linode/linode_het_DFDP.m
+++ b/coco_example_runs/linode/linode_dp.m
@@ -1,4 +1,4 @@
-function J = linode_het_DFDP(t, x, p)
+function J = linode_dp(t, x, p)
 
 x1 = x(1,:);
 phi = p(2,:);
diff --git a/coco_example_runs/linode/linode_het_DFDPDP.m b/coco_example_runs/linode/linode_dpdp.m
similarity index 87%
rename from coco_example_runs/linode/linode_het_DFDPDP.m
rename to coco_example_runs/linode/linode_dpdp.m
index ebc094018988c2ee15506fecf04f652ea9a3e9b0..928ed0e7ae612cae4190c9da482856eabc09cb9a 100644
--- a/coco_example_runs/linode/linode_het_DFDPDP.m
+++ b/coco_example_runs/linode/linode_dpdp.m
@@ -1,4 +1,4 @@
-function dJ = linode_het_DFDPDP(t, x, p)
+function dJ = linode_dpdp(t, x, p)
 
 x1 = x(1,:);
 phi = p(2,:);
diff --git a/coco_example_runs/linode/linode_het_DFDPDT.m b/coco_example_runs/linode/linode_dpdt.m
similarity index 83%
rename from coco_example_runs/linode/linode_het_DFDPDT.m
rename to coco_example_runs/linode/linode_dpdt.m
index b6705eb5a7fe73fb57747ff5417bb14e30a33f71..cbde46af2df3dd9b52be28b93004b46c66a708c7 100644
--- a/coco_example_runs/linode/linode_het_DFDPDT.m
+++ b/coco_example_runs/linode/linode_dpdt.m
@@ -1,4 +1,4 @@
-function dJ = linode_het_DFDPDT(t, x, p)
+function dJ = linode_dpdt(t, x, p)
 
 x1 = x(1,:);
 phi = p(2,:);
diff --git a/coco_example_runs/linode/linode_het_DFDPDX.m b/coco_example_runs/linode/linode_dpdx.m
similarity index 62%
rename from coco_example_runs/linode/linode_het_DFDPDX.m
rename to coco_example_runs/linode/linode_dpdx.m
index afd2a0ab34c5961e09756451fb355cf4dd3af1bf..532661d91bd028724cfcad0431d38bc7346f1548 100644
--- a/coco_example_runs/linode/linode_het_DFDPDX.m
+++ b/coco_example_runs/linode/linode_dpdx.m
@@ -1,4 +1,4 @@
-function dJ = linode_het_DFDPDX(t, x, p)
+function dJ = linode_dpdx(t, x, p)
 
 x1 = x(1,:);
 
diff --git a/coco_example_runs/linode/linode_het_DFDT.m b/coco_example_runs/linode/linode_dt.m
similarity index 73%
rename from coco_example_runs/linode/linode_het_DFDT.m
rename to coco_example_runs/linode/linode_dt.m
index 0dd9f55daeef4d4d85eeb55ac13a655d25879790..a3f06646c03c2877a51b0b211a88e2a0bf94b444 100644
--- a/coco_example_runs/linode/linode_het_DFDT.m
+++ b/coco_example_runs/linode/linode_dt.m
@@ -1,4 +1,4 @@
-function J = linode_het_DFDT(t, x, p)
+function J = linode_dt(t, x, p)
 
 x1 = x(1,:);
 phi = p(2,:);
diff --git a/coco_example_runs/linode/linode_het_DFDTDP.m b/coco_example_runs/linode/linode_dtdp.m
similarity index 82%
rename from coco_example_runs/linode/linode_het_DFDTDP.m
rename to coco_example_runs/linode/linode_dtdp.m
index a0b98e8b16d24ef5b86108e3c08d0d46cac43c17..895ff62b041698b261c8bfeb6e24668ebaa7238e 100644
--- a/coco_example_runs/linode/linode_het_DFDTDP.m
+++ b/coco_example_runs/linode/linode_dtdp.m
@@ -1,4 +1,4 @@
-function dJ = linode_het_DFDTDP(t, x, p)
+function dJ = linode_dtdp(t, x, p)
 
 
 phi = p(2,:);
diff --git a/coco_example_runs/linode/linode_het_DFDTDT.m b/coco_example_runs/linode/linode_dtdt.m
similarity index 77%
rename from coco_example_runs/linode/linode_het_DFDTDT.m
rename to coco_example_runs/linode/linode_dtdt.m
index 4c35061057482e70beb43449829316876552ee9e..661ea2f40eadf6a543f9abe8a2790359a5addb38 100644
--- a/coco_example_runs/linode/linode_het_DFDTDT.m
+++ b/coco_example_runs/linode/linode_dtdt.m
@@ -1,4 +1,4 @@
-function dJ = linode_het_DFDTDT(t, x, p)
+function dJ = linode_dtdt(t, x, p)
 
 x1 = x(1,:);
 phi = p(2,:);
diff --git a/coco_example_runs/linode/linode_dtdx.m b/coco_example_runs/linode/linode_dtdx.m
new file mode 100644
index 0000000000000000000000000000000000000000..68afe1275a328f281b32ea9b4c38f89b5f9b0532
--- /dev/null
+++ b/coco_example_runs/linode/linode_dtdx.m
@@ -0,0 +1,5 @@
+function J = linode_dtdx(t, x, p)
+
+J = zeros(2,2,numel(t));
+
+end
diff --git a/coco_example_runs/linode/linode_het_DFDX.m b/coco_example_runs/linode/linode_dx.m
similarity index 72%
rename from coco_example_runs/linode/linode_het_DFDX.m
rename to coco_example_runs/linode/linode_dx.m
index ac15a754e81d3808128dd4b58e5de87a3848dcb4..26657e9f34fb619348d7abc8ce6a15ed6f873a64 100644
--- a/coco_example_runs/linode/linode_het_DFDX.m
+++ b/coco_example_runs/linode/linode_dx.m
@@ -1,4 +1,4 @@
-function J = linode_het_DFDX(t, x, p)
+function J = linode_dx(t, x, p)
 
 x1 = x(1,:);
 k = p(1,:);
diff --git a/coco_example_runs/linode/linode_het_DFDXDP.m b/coco_example_runs/linode/linode_dxdp.m
similarity index 65%
rename from coco_example_runs/linode/linode_het_DFDXDP.m
rename to coco_example_runs/linode/linode_dxdp.m
index 77689d716e5a02a85a042a5b33f5d8d12a9e8a65..c1e47cead7dc586b39a7d8c20aea386901acd0d8 100644
--- a/coco_example_runs/linode/linode_het_DFDXDP.m
+++ b/coco_example_runs/linode/linode_dxdp.m
@@ -1,4 +1,4 @@
-function J = linode_het_DFDXDP(t, x, p)
+function J = linode_dxdp(t, x, p)
 
 x1 = x(1,:);
 k = p(1,:);
diff --git a/coco_example_runs/linode/linode_dxdt.m b/coco_example_runs/linode/linode_dxdt.m
new file mode 100644
index 0000000000000000000000000000000000000000..62d7fbc3505ad8b413b6054c1fdf8f086d6792cc
--- /dev/null
+++ b/coco_example_runs/linode/linode_dxdt.m
@@ -0,0 +1,5 @@
+function dJ = linode_dxdt(t, x, p)
+
+dJ = zeros(2,2,numel(t));
+
+end
diff --git a/coco_example_runs/linode/linode_dxdx.m b/coco_example_runs/linode/linode_dxdx.m
new file mode 100644
index 0000000000000000000000000000000000000000..e6b7bac090ae6a086550e8f1d144744b97cd603a
--- /dev/null
+++ b/coco_example_runs/linode/linode_dxdx.m
@@ -0,0 +1,5 @@
+function dJ = linode_dxdx(t, x, p)
+
+dJ = zeros(2,2,2,numel(t));
+
+end
diff --git a/coco_example_runs/linode/linode_het_DFDTDX.m b/coco_example_runs/linode/linode_het_DFDTDX.m
deleted file mode 100644
index 9e6f283b00cdba0e22177a34eab037fc723e61f4..0000000000000000000000000000000000000000
--- a/coco_example_runs/linode/linode_het_DFDTDX.m
+++ /dev/null
@@ -1,5 +0,0 @@
-function J = linode_het_DFDT(t, x, p)
-
-J = zeros(2,2,numel(t));
-
-end
diff --git a/coco_example_runs/linode/linode_het_DFDXDT.m b/coco_example_runs/linode/linode_het_DFDXDT.m
deleted file mode 100644
index 3c2f5741a7d63ab3584e5a04f252f8a00b15cf36..0000000000000000000000000000000000000000
--- a/coco_example_runs/linode/linode_het_DFDXDT.m
+++ /dev/null
@@ -1,5 +0,0 @@
-function dJ = linode_het_DFDXDT(t, x, p)
-
-dJ = zeros(2,2,numel(t));
-
-end
diff --git a/coco_example_runs/linode/linode_het_DFDXDX.m b/coco_example_runs/linode/linode_het_DFDXDX.m
deleted file mode 100644
index de496b0c3f146b3e2c0e90b7b6038e0593ba8701..0000000000000000000000000000000000000000
--- a/coco_example_runs/linode/linode_het_DFDXDX.m
+++ /dev/null
@@ -1,5 +0,0 @@
-function dJ = linode_het_DFDXDX(t, x, p)
-
-dJ = zeros(2,2,2,numel(t));
-
-end
diff --git a/coco_example_runs/linode/linode_het_bc.m b/coco_example_runs/linode/linode_het_bc.m
deleted file mode 100644
index 2f66f649b119cd9efa500e332011a6b3fed9335f..0000000000000000000000000000000000000000
--- a/coco_example_runs/linode/linode_het_bc.m
+++ /dev/null
@@ -1,14 +0,0 @@
-function [data, y] = linode_het_bc(prob, data, u) %#ok<INUSL>
-%LINODE_HET_BC   'bvp'-compatible encoding of linode boundary conditions
-%
-% Encoding is of a non-autonomous vector field.
-
-x0 = u(1:2);
-x1 = u(3:4);
-T0 = u(5);
-T  = u(6);
-om = u(7);
-
-y = [x1(1:2)-x0(1:2); T0; T-2*pi./om];
-
-end
diff --git a/matlab_development/uq/toolbox/__pycache__/comment_strip.cpython-35.pyc b/matlab_development/uq/toolbox/__pycache__/comment_strip.cpython-35.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..10d3f4fde1f41b3535c270c214d943e048bce79e
Binary files /dev/null and b/matlab_development/uq/toolbox/__pycache__/comment_strip.cpython-35.pyc differ
diff --git a/matlab_development/uq/toolbox/bvp_uq_init_data.m b/matlab_development/uq/toolbox/bvp_uq_init_data.m
index b13c1c9bb0b72d54b28e0f2f05cdd5e38d431119..ed3951a9b255aa06fb3f9721fb32f167409941ae 100644
--- a/matlab_development/uq/toolbox/bvp_uq_init_data.m
+++ b/matlab_development/uq/toolbox/bvp_uq_init_data.m
@@ -1,4 +1,4 @@
-function data = bvp_uq_init_data(prob, src_data, oid, varargin)
+function data = bvp_uq_init_data(src_data, oid, varargin)
 % Works for a single cid
 % data = coco_func_data('protect');
 data.oid = oid;
diff --git a/matlab_development/uq/toolbox/comment_strip.py b/matlab_development/uq/toolbox/comment_strip.py
new file mode 100644
index 0000000000000000000000000000000000000000..5d3f2f5ee9cffa6f3e55ac31856009ce216e42ca
--- /dev/null
+++ b/matlab_development/uq/toolbox/comment_strip.py
@@ -0,0 +1,28 @@
+import os
+
+def matlab_comment_strip(filepath):
+    comment_free_code = ""
+    with open(filepath, 'r') as f:
+        for line in f:
+            keep = ''
+            comment_split = line.split('%')
+            if len(comment_split) > 1 and comment_split[0].strip() != "":
+                # Handles in line comments
+                keep = comment_split[0] +'\n'
+            elif len(comment_split) == 1:
+                keep = comment_split[0]
+            comment_free_code += keep
+
+    path, name = os.path.split(filepath)
+    name, ext = os.path.splitext(name)
+    new_path = os.path.join(path, 'no_comment_for_thesis', name + '_no_comment' + ext)
+    
+    with open(new_path, 'w') as f:
+        f.write(comment_free_code)
+
+
+if __name__ == "__main__":
+    for filename in os.listdir('.'):
+        name, ext = os.path.splitext(filename)
+        if ext == '.m':
+            matlab_comment_strip(filename)
\ No newline at end of file
diff --git a/matlab_development/uq/toolbox/private/uq_get_settings.m b/matlab_development/uq/toolbox/private/uq_get_settings.m
index 094cb000fe12a6f91d89ebe7a958cd20ff6608cf..064b2e9a65f1bfe9a5b6e4316584ffc4b14ef322 100644
--- a/matlab_development/uq/toolbox/private/uq_get_settings.m
+++ b/matlab_development/uq/toolbox/private/uq_get_settings.m
@@ -1,10 +1,9 @@
 function [uq, spec] = uq_get_settings(prob, tbid, uq)
 
-spec = {% Name   Type  Default  Action  Args  Description
-          'M',  'int',      4, 'read',   {},  'Numerical Integration Order'
-          'P',  'int',      4, 'read',   {},  'Max Polynomial Order for Polynomial Chaos Expansion'
+spec = {  'M',   '[int]',   4, 'read',   {},  'Numerical Integration Order'
+          'Pt',  'int',     3, 'read',   {},  'Max Polynomial Order for Polynomial Chaos Expansion'
  };
 
 uq = coco_parse_settings(prob, spec, uq, tbid);
 
-end
+end
\ No newline at end of file
diff --git a/matlab_development/uq/toolbox/transform_uniform_sample.m b/matlab_development/uq/toolbox/transform_uniform_sample.m
index 0394b1179f9ca24263df62e3c77d9e90e6a37ad2..975f293a3b6fafa055a3a777d6597ac5a7718e2b 100644
--- a/matlab_development/uq/toolbox/transform_uniform_sample.m
+++ b/matlab_development/uq/toolbox/transform_uniform_sample.m
@@ -30,4 +30,5 @@ function sample = transform_uniform_sample(sample, mu, CoV)
 %      1.8660    2.7321    3.5981    4.4641
 %      5.3301    6.1962    7.0622    7.9282
 
-sample = (1+sqrt(3)*sample*CoV)*mu;
\ No newline at end of file
+sample = (1+sqrt(3)*sample*CoV)*mu;
+end
\ No newline at end of file
diff --git a/matlab_development/uq/toolbox/uq_BP2bvp.m b/matlab_development/uq/toolbox/uq_BP2bvp.m
index 6b26f116358236142fa520b1d4ee82b1df6aa372..24982ef05d53425e8eff0ba1bc2a7b56c94cb93f 100644
--- a/matlab_development/uq/toolbox/uq_BP2bvp.m
+++ b/matlab_development/uq/toolbox/uq_BP2bvp.m
@@ -80,7 +80,7 @@ data = uq_gen_nds(data);
 % weights get re-ordered as part of uq_BP2bvpsamples
 % Need to rethink psi_mat construction to handle different integration
 % orders and polynomial degrees... another time.
-psi_mat = uq_make_psi_mat(data.nds_grid, data.uq.P, data.spdists);
+psi_mat = uq_make_psi_mat(data.nds_grid, data.uq.Pt, data.spdists);
 data.wtd_psi_mat = psi_mat*diag(data.wts);
 
 prob = uq_add_sample_nodes(prob, data, args);
diff --git a/matlab_development/uq/toolbox/uq_BP2collsamples.m b/matlab_development/uq/toolbox/uq_BP2collsamples.m
index eaaea9affb052723ded05636eb914abcaa26500e..6e932d4716d1d5a05d99fd5a2a2a98daccac0f8a 100644
--- a/matlab_development/uq/toolbox/uq_BP2collsamples.m
+++ b/matlab_development/uq/toolbox/uq_BP2collsamples.m
@@ -1,5 +1,4 @@
 function [prob, data] = uq_BP2collsamples(prob, data, args, opts)
-%UQ_BP2COLLSAMPLES Summary of this function goes here
 %   
 % Add coll instances for each point in the sample parameter space.
 % Starting information for the points in parameter space are taken from
diff --git a/matlab_development/uq/toolbox/uq_add_sample_nodes.m b/matlab_development/uq/toolbox/uq_add_sample_nodes.m
index 900b2d591e10b255f7937586a151f5efa1fc0e6b..eaf02af754c0accc5e10000c5a6c02924f3e346d 100644
--- a/matlab_development/uq/toolbox/uq_add_sample_nodes.m
+++ b/matlab_development/uq/toolbox/uq_add_sample_nodes.m
@@ -1,4 +1,4 @@
-function [prob, data] = uq_add_sample_nodes(prob, data, args)
+function prob = uq_add_sample_nodes(prob, data, args)
 
 % This function ties the values of parameters in the
 % collocation zero problems to parameters that update when
@@ -8,6 +8,19 @@ if nargin < 3
   args = {};
 end
 
+% A kludge for checking if tangent diretions need to be
+% added.  This is only true if a run and label are passed
+% in varargin and then only if the type of point that the
+% run and label represent is a Branch Point ('BP')
+add_tl0 = 0;
+
+if isfield(args, 'run') && isfield(args, 'lab')
+  chart = coco_read_solution(args.run, args.lab, 'chart');
+  if strcmpi(chart.pt_type, 'BP')
+    add_tl0 = 1;
+  end
+end
+
 if data.num_normals > 0
     muid = coco_get_id(data.oid, 'mus');
     sigid = coco_get_id(data.oid, 'sigs');
@@ -36,31 +49,43 @@ if data.num_normals > 0
         [mu_chart, mu_lidx] = coco_read_adjoint(muid, args.run, args.lab, ...
           'chart', 'lidx');
         mu_l0 = mu_chart.x;
-        mu_tl0 = cdata.v(mu_lidx);
+        
         [sig_chart, sig_lidx] = coco_read_adjoint(sigid, args.run, args.lab, ...
           'chart', 'lidx');
         sig_l0 = sig_chart.x;
-        sig_tl0 = cdata.v(sig_lidx);
+
         [norm_chart, normal_lidx] = coco_read_adjoint(normal_sample_id, args.run, args.lab, ...
           'chart', 'lidx');
         norm_l0 = norm_chart.x;
-        norm_tl0 = cdata.v(normal_lidx);
+        if add_tl0
+          mu_tl0 = cdata.v(mu_lidx);
+          sig_tl0 = cdata.v(sig_lidx);
+          norm_tl0 = cdata.v(normal_lidx);
+        end
       else
         mu_l0 = zeros(size(mu));
-        mu_tl0 = zeros(size(mu));
         sig_l0 = zeros(size(sig));
-        sig_tl0 = zeros(size(sig));
         norm_l0 = zeros(size(data.normal_nds_idx'));
-        norm_tl0 = zeros(size(data.normal_nds_idx'));
       end
-      prob = coco_add_adjt(prob, muid, coco_get_id('d', munames), ...
-        'l0', mu_l0, 'tl0', mu_tl0);
-      prob = coco_add_adjt(prob, sigid, coco_get_id('d', signames), ...
-        'l0', sig_l0, 'tl0', sig_tl0);
-      amuidx = coco_get_adjt_data(prob, muid, 'axidx');
-      asigidx = coco_get_adjt_data(prob, sigid, 'axidx');
-      prob = coco_add_adjt(prob, normal_sample_id, 'aidx', ...
-        [amuidx; asigidx], 'l0', norm_l0, 'tl0', norm_tl0);
+      if add_tl0
+        prob = coco_add_adjt(prob, muid, coco_get_id('d', munames), ...
+          'l0', mu_l0, 'tl0', mu_tl0);
+        prob = coco_add_adjt(prob, sigid, coco_get_id('d', signames), ...
+          'l0', sig_l0, 'tl0', sig_tl0);
+        amuidx = coco_get_adjt_data(prob, muid, 'axidx');
+        asigidx = coco_get_adjt_data(prob, sigid, 'axidx');
+        prob = coco_add_adjt(prob, normal_sample_id, 'aidx', ...
+          [amuidx; asigidx], 'l0', norm_l0, 'tl0', norm_tl0);
+      else
+        prob = coco_add_adjt(prob, muid, coco_get_id('d', munames), ...
+          'l0', mu_l0);
+        prob = coco_add_adjt(prob, sigid, coco_get_id('d', signames), ...
+          'l0', sig_l0);
+        amuidx = coco_get_adjt_data(prob, muid, 'axidx');
+        asigidx = coco_get_adjt_data(prob, sigid, 'axidx');
+        prob = coco_add_adjt(prob, normal_sample_id, 'aidx', ...
+          [amuidx; asigidx], 'l0', norm_l0);
+      end
     end
     uidx = coco_get_func_data(prob, normal_sample_id, 'uidx');
     % Store the parameter index of the normal nodes for later use of
@@ -115,37 +140,47 @@ if data.num_uniforms > 0
       [lo_chart, lo_lidx] = coco_read_adjoint(loid, args.run, ...
         args.lab, 'chart', 'lidx');
       lo_l0 = lo_chart.x;
-      lo_tl0 = cdata.v(lo_lidx);
 
       [up_chart, up_lidx] = coco_read_adjoint(upid, args.run, ...
         args.lab, 'chart', 'lidx');
       up_l0 = up_chart.x;
-      up_tl0 = cdata.v(up_lidx);
 
       [unif_chart, unif_lidx] = coco_read_adjoint(uniform_sample_id, ...
         args.run, args.lab, 'chart', 'lidx');
       unif_l0 = unif_chart.x;
-      unif_tl0 = cdata.v(unif_lidx);
+      if add_tl0
+        lo_tl0 = cdata.v(lo_lidx);      
+        up_tl0 = cdata.v(up_lidx);
+        unif_tl0 = cdata.v(unif_lidx);
+      end
     else
       lo_l0 = zeros(size(lo));
-      lo_tl0 = zeros(size(lo));
       up_l0 = zeros(size(up));
-      up_tl0 = zeros(size(up));
       unif_l0 = zeros(size(data.uniform_nds_idx'));
-      unif_tl0 = zeros(size(data.uniform_nds_idx'));
     end
-    prob = coco_add_adjt(prob, loid, coco_get_id('d', lonames), ...
-      'l0', lo_l0, 'tl0', lo_tl0);
-    prob = coco_add_adjt(prob, upid, coco_get_id('d', upnames), ...
-      'l0', up_l0, 'tl0', up_tl0);
-    aloidx = coco_get_adjt_data(prob, loid, 'axidx');
-    aupidx = coco_get_adjt_data(prob, upid, 'axidx');
-    prob = coco_add_adjt(prob, uniform_sample_id, 'aidx', ...
-      [aloidx; aupidx], 'l0', unif_l0, 'tl0', unif_tl0);
-  end       
+    if add_tl0
+      prob = coco_add_adjt(prob, loid, coco_get_id('d', lonames), ...
+        'l0', lo_l0, 'tl0', lo_tl0);
+      prob = coco_add_adjt(prob, upid, coco_get_id('d', upnames), ...
+        'l0', up_l0, 'tl0', up_tl0);
+      aloidx = coco_get_adjt_data(prob, loid, 'axidx');
+      aupidx = coco_get_adjt_data(prob, upid, 'axidx');
+      prob = coco_add_adjt(prob, uniform_sample_id, 'aidx', ...
+        [aloidx; aupidx], 'l0', unif_l0, 'tl0', unif_tl0);
+    else
+      prob = coco_add_adjt(prob, loid, coco_get_id('d', lonames), ...
+        'l0', lo_l0);
+      prob = coco_add_adjt(prob, upid, coco_get_id('d', upnames), ...
+        'l0', up_l0);
+      aloidx = coco_get_adjt_data(prob, loid, 'axidx');
+      aupidx = coco_get_adjt_data(prob, upid, 'axidx');
+      prob = coco_add_adjt(prob, uniform_sample_id, 'aidx', ...
+        [aloidx; aupidx], 'l0', unif_l0);
+    end
+  end
   uidx = coco_get_func_data(prob, uniform_sample_id, 'uidx');
   % Store the parameter index of the uniform nodes for later use of
-  % gluing them to collocation parameters    
+  % gluing them to collocation parameters 
   data.sample_par_idx(data.uniform_nds_idx) = ...
       uidx((2*data.num_uniforms+1):end);
   if data.addadjt
@@ -158,52 +193,65 @@ end
 % This glues the values of the stochastic parameters in the collocation
 % segments to parameters created with uq_add_sample_nodes which update when 
 % the value of a Distribution Parameter is updated as part of continuation
-glue_idx_1 = data.sample_par_idx(data.idx);
-glue_idx_1 = glue_idx_1(:);
-glue_idx_2 = cell2mat(data.s_idx);
-glue_idx_2 = glue_idx_2(data.sp2p_idx, :);
-glue_idx_2 = glue_idx_2(:);
-seg2ndsid = coco_get_id(data.oid, 'uq.seg_pars_to_node_pars');
-
-prob = coco_add_glue(prob, seg2ndsid, glue_idx_1, glue_idx_2);
+seg2ndsid = coco_get_id(data.oid, 'uq.s_par_glue');
+% Parameter indices in the collocation segments:
+seg_par_idx = cell2mat(data.s_idx);
+% Only the stochastic parameters
+seg_par_idx = seg_par_idx(data.sp2p_idx, :);
+seg_par_idx = seg_par_idx(:);
+
+seg2ndsidx = [seg_par_idx; data.sample_par_idx];
+% Zero function to match parameters boundary value problems
+% to transformed random variables.
+prob = coco_add_func(prob, seg2ndsid, @uq_seg_to_nds, @uq_seg_to_nds_du, ...
+  @uq_seg_to_nds_dudu, data, 'zero', 'uidx', seg2ndsidx);
 pnames = uq_get_sample_par_names(data.pnames(data.sp2p_idx), 1:data.nsamples);
 nds2smplid = coco_get_id(data.oid, 'uq.nds2samples');
 
-prob = coco_add_pars(prob, nds2smplid, glue_idx_2, pnames, 'active');
+prob = coco_add_pars(prob, nds2smplid, seg_par_idx, pnames, 'active');
 
 if data.addadjt
-  adjt_glue_idx_1 = data.adjt_sample_par_idx(data.idx);
-  adjt_glue_idx_1 = adjt_glue_idx_1(:);
-  adjt_glue_idx_2 = cell2mat(data.adj_s_idx);
-  adjt_glue_idx_2 = adjt_glue_idx_2(data.sp2p_idx, :);
-  adjt_glue_idx_2 = adjt_glue_idx_2(:);
+  adjt_seg_par_idx = cell2mat(data.adj_s_idx);
+  adjt_seg_par_idx = adjt_seg_par_idx(data.sp2p_idx, :);
+  adjt_seg_par_idx = adjt_seg_par_idx(:);
+
   if isfield(args, 'run')
     chart = coco_read_solution(args.run, args.lab, 'chart');
     cdata = coco_get_chart_data(chart, 'lsol');        
     [s2n_chart, s2n_lidx] = coco_read_adjoint(seg2ndsid, args.run, args.lab, ...
       'chart', 'lidx');
     s2n_l0 = s2n_chart.x;
-    s2n_tl0 = cdata.v(s2n_lidx);
-    bd = coco_bd_read(args.run);
-    prob = coco_add_adjt(prob, seg2ndsid, ...
-      'aidx', [adjt_glue_idx_1;adjt_glue_idx_2], ...
-      'l0', s2n_l0, ...
-      'tl0', s2n_tl0);
-    
     [n2s_chart, n2s_lidx] = coco_read_adjoint(nds2smplid, args.run, args.lab, ...
       'chart', 'lidx');
     n2s_l0 = n2s_chart.x;
-    n2s_tl0 = cdata.v(n2s_lidx);
-    prob = coco_add_adjt(prob, nds2smplid, coco_get_id('d',pnames), ...
-      'aidx', adjt_glue_idx_2, ...
-      'l0', n2s_l0, ...
-      'tl0', n2s_tl0);
+    
+    if add_tl0
+      s2n_tl0 = cdata.v(s2n_lidx);
+      prob = coco_add_adjt(prob, seg2ndsid, ...
+        'aidx', [adjt_seg_par_idx; data.adjt_sample_par_idx], ...
+        'l0', s2n_l0, ...
+        'tl0', s2n_tl0);
+      
+      n2s_tl0 = cdata.v(n2s_lidx);
+      prob = coco_add_adjt(prob, nds2smplid, coco_get_id('d',pnames), ...
+        'aidx', adjt_seg_par_idx, ...
+        'l0', n2s_l0, ...
+        'tl0', n2s_tl0);
+    else
+      prob = coco_add_adjt(prob, seg2ndsid, ...
+        'aidx', [adjt_seg_par_idx; data.adjt_sample_par_idx], ...
+        'l0', s2n_l0);
+      
+      prob = coco_add_adjt(prob, nds2smplid, coco_get_id('d',pnames), ...
+        'aidx', adjt_seg_par_idx, ...
+        'l0', n2s_l0);
+    end
   else
     prob = coco_add_adjt(prob, seg2ndsid, 'aidx', ...
-      [adjt_glue_idx_1;adjt_glue_idx_2]);
+      [adjt_seg_par_idx; data.adjt_sample_par_idx]);
     prob = coco_add_adjt(prob, nds2smplid, coco_get_id('d',pnames), ...
-      'aidx', adjt_glue_idx_2);
+      'aidx', adjt_seg_par_idx);
   end
 end
-prob.uq.samples.(data.oid) = data;
+
 end
\ No newline at end of file
diff --git a/matlab_development/uq/toolbox/uq_bvp2bvp.m b/matlab_development/uq/toolbox/uq_bvp2bvp.m
index 59c7e01a633ff6f12bda0ab447d54070c08fea3d..b5a2d7b0f981c2d8cb4a39a888e4b0807a7ecf49 100644
--- a/matlab_development/uq/toolbox/uq_bvp2bvp.m
+++ b/matlab_development/uq/toolbox/uq_bvp2bvp.m
@@ -80,7 +80,7 @@ data = uq_gen_nds(data);
 % weights get re-ordered as part of uq_BP2samples
 % Need to rethink psi_mat construction to handle different integration
 % orders and polynomial degrees... another time.
-psi_mat = uq_make_psi_mat(data.nds_grid, data.uq.P, data.spdists);
+psi_mat = uq_make_psi_mat(data.nds_grid, data.uq.Pt, data.spdists);
 data.wtd_psi_mat = psi_mat*diag(data.wts);
 
 prob = uq_add_sample_nodes(prob, data, args, opts);
diff --git a/matlab_development/uq/toolbox/uq_bvp_add_samples.m b/matlab_development/uq/toolbox/uq_bvp_add_samples.m
index fcc13df3687f687b9044569145ad60991e70f553..a8e9296dcd6b67a86347c82b1a819c054031cd31 100644
--- a/matlab_development/uq/toolbox/uq_bvp_add_samples.m
+++ b/matlab_development/uq/toolbox/uq_bvp_add_samples.m
@@ -1,6 +1,6 @@
 function [prob, data] = uq_bvp_add_samples(prob, data, bc_data, args)
 
 [prob, data] = uq_coll_add_samples(prob, data);
-[prob, data] = uq_bvp_close_samples(prob, data, bc_data, args); % handles -add-adjt
+[prob, data] = uq_bvp_close_samples(prob, data, bc_data, args);
 
 end
\ No newline at end of file
diff --git a/matlab_development/uq/toolbox/uq_bvp_close_samples.m b/matlab_development/uq/toolbox/uq_bvp_close_samples.m
index 6c73da5cffc8d2ef5cbcf9a0a44450359eb0edb1..2093b3d2783ae18f1e07e387f65d575870e3bc9e 100644
--- a/matlab_development/uq/toolbox/uq_bvp_close_samples.m
+++ b/matlab_development/uq/toolbox/uq_bvp_close_samples.m
@@ -1,19 +1,5 @@
 function [prob, data] = uq_bvp_close_samples(prob, data, bc_data, args)
 
-% UQ_BVP_CLOSE_SAMPLES
-%
-% [PROB, DATA] = UQ_BVP_CLOSE_SAMPLES(PROB, DATA, VARARGIN)
-% VARARGIN = {BCND, [ARGS], [OPTS]}
-% ARGS = {ARGS.RUN, ARGS.LAB}
-% OPTS = { '-add-adjt' }
-%
-% PROB : Continuation problem structure.
-% DATA : UQ Continuation Problem data structure.
-% ARGS : Presence of ARGS.RUN field triggers initial
-%        values for Lagrange multipliers and tangencies to
-%        be read from a previous solution, ARGS.LAB, in
-%        ARGS.RUN.
-
 if nargin < 4
   args = {};
 end
@@ -23,8 +9,7 @@ bc   = bc_data.bvp_bc;
 nsamples  = data.nsamples;
 s_idx  = cell(1, nsamples);
 
-% Index of parameters that are deterministic and equal in all coll
-% instances
+% Index of parameters that are deterministic and equal in all coll instances
 fxd_p_idx = and(~data.sp2p_idx, ~data.dpar_idx);
 % Index of parameters that are deterministic and potentially different in
 % various coll instances
@@ -34,6 +19,19 @@ if has_unique_deterministic_parameters
   unq_p_idx = cell(1, nsamples);
 end
 
+% A kludge for checking if tangent diretions need to be
+% added.  This is only true if a run and label are passed
+% in varargin and then only if the type of point that the
+% run and label represent is a Branch Point ('BP')
+add_tl0 = 0;
+
+if isfield(args, 'run') && isfield(args, 'lab')
+  chart = coco_read_solution(args.run, args.lab, 'chart');
+  if strcmpi(chart.pt_type, 'BP')
+    add_tl0 = 1;
+  end
+end
+
 for i=1:nsamples
   fid  = coco_get_id(data.sids{i}, 'bc');
 
@@ -66,7 +64,9 @@ for i=1:nsamples
       [chart, lidx] = coco_read_adjoint(fid, args.run, args.lab, ...
         'chart', 'lidx');
       l0 = chart.x;
-      tl0 = cdata.v(lidx);
+      if add_tl0
+        tl0 = cdata.v(lidx);
+      end
     end
     
     [fdata, aidx] = coco_get_adjt_data(prob, coll_id, 'data', 'axidx');
@@ -82,7 +82,11 @@ for i=1:nsamples
     
     aidx = [T0_idx; T_idx; x0_idx; x1_idx; adj_s_idx{i}];
     if isfield(args, 'run') && isfield(args, 'lab')
-      prob = coco_add_adjt(prob, fid, 'aidx', aidx, 'l0', l0, 'tl0', tl0);
+      if add_tl0
+        prob = coco_add_adjt(prob, fid, 'aidx', aidx, 'l0', l0, 'tl0', tl0);
+      else
+        prob = coco_add_adjt(prob, fid, 'aidx', aidx, 'l0', l0);
+      end
     else
       prob = coco_add_adjt(prob, fid, 'aidx', aidx);
     end
@@ -111,16 +115,22 @@ if sum(fxd_p_idx) > 0
         [chart, lidx] = coco_read_adjoint(sfid, args.run, args.lab, ...
           'chart', 'lidx');
         l0 = chart.x;
-        tl0 = cdata.v(lidx);      
+        if add_tl0
+          tl0 = cdata.v(lidx);
+        end    
       else
         l0 = zeros([fxd_p_idx,1]);
-        tl0 = zeros([fxd_p_idx,1]);
       end
-
-      prob = coco_add_adjt(prob, sfid, ...
-        'aidx', [adj_s_idx1(fxd_p_idx); adj_s_idxi(fxd_p_idx)], ...
-        'l0', l0, ...
-        'tl0', tl0);
+      if add_tl0
+        prob = coco_add_adjt(prob, sfid, ...
+          'aidx', [adj_s_idx1(fxd_p_idx); adj_s_idxi(fxd_p_idx)], ...
+          'l0', l0, ...
+          'tl0', tl0);
+      else
+        prob = coco_add_adjt(prob, sfid, ...
+          'aidx', [adj_s_idx1(fxd_p_idx); adj_s_idxi(fxd_p_idx)], ...
+          'l0', l0);
+      end
     end
   end
 end
@@ -136,12 +146,19 @@ if ~isempty(data.pnames) && sum(fxd_p_idx) > 0
       [chart, lidx] = coco_read_adjoint(pfid, args.run, args.lab, ...
         'chart', 'lidx');
       l0 = chart.x;
-      tl0 = cdata.v(lidx);
-      prob = coco_add_adjt(prob, pfid, ...
-        coco_get_id('d', data.pnames(fxd_p_idx)), ...
-        'aidx', adj_s_idx1(fxd_p_idx), ...
-        'l0', l0, ...
-        'tl0', tl0);      
+      if add_tl0
+        tl0 = cdata.v(lidx);
+        prob = coco_add_adjt(prob, pfid, ...
+          coco_get_id('d', data.pnames(fxd_p_idx)), ...
+          'aidx', adj_s_idx1(fxd_p_idx), ...
+          'l0', l0, ...
+          'tl0', tl0);
+      else
+        prob = coco_add_adjt(prob, pfid, ...
+          coco_get_id('d', data.pnames(fxd_p_idx)), ...
+          'aidx', adj_s_idx1(fxd_p_idx), ...
+          'l0', l0); 
+      end
     else
       prob = coco_add_adjt(prob, pfid, ...
         coco_get_id('d', data.pnames(fxd_p_idx)), 'aidx', ...
@@ -163,13 +180,19 @@ if ~isempty(data.pnames) && sum(frd_p_idx) > 0
       [chart, lidx] = coco_read_adjoint(pfid, args.run, args.lab, ...
         'chart', 'lidx');
       l0 = chart.x;
-      tl0 = cdata.v(lidx);
-      
-      prob = coco_add_adjt(prob, pfid, ...
-        coco_get_id('d', pnames), ...
-        'aidx', adj_unq_p_idx, ...
-        'l0', l0, ...
-        'tl0', tl0);      
+      if add_tl0
+        tl0 = cdata.v(lidx);
+        prob = coco_add_adjt(prob, pfid, ...
+          coco_get_id('d', pnames), ...
+          'aidx', adj_unq_p_idx, ...
+          'l0', l0, ...
+          'tl0', tl0);
+      else
+        prob = coco_add_adjt(prob, pfid, ...
+          coco_get_id('d', pnames), ...
+          'aidx', adj_unq_p_idx, ...
+          'l0', l0);
+      end
     else
       prob = coco_add_adjt(prob, pfid, coco_get_id('d', pnames), ...
         'aidx', adj_unq_p_idx);
diff --git a/matlab_development/uq/toolbox/uq_bvp_gen_samples.m b/matlab_development/uq/toolbox/uq_bvp_gen_samples.m
index b2c10c0c8458d3a8f0672a060c50c161fe69c2b5..79283c5e113c1bd487aaa85ba03b51abfe37e2bb 100644
--- a/matlab_development/uq/toolbox/uq_bvp_gen_samples.m
+++ b/matlab_development/uq/toolbox/uq_bvp_gen_samples.m
@@ -7,6 +7,34 @@ runs_per_parameter = cumprod([1,data.uq.M(1:end-1)]);
 total_runs = sum(runs_per_parameter);
 run_names = cell(1, total_runs);
 
+% Kludge for getting 'important' coll and ode settings.
+% Was previously starting from the passed instance of prob,
+% which carried all of the problem settings with it.
+% Realized that leads to an ever increasing problem size if
+% you add more than one samples and the problems are
+% potentially not closed.  Changing to a temporary problem
+% instance which itself must be closed for continuation.
+% This allows for a degree of embedability, but seems
+% really shaky.  Would be nice if a utility function
+% existed for copying settings from another problem
+% instance, but I haven't found it.
+prob_init = coco_prob();
+% ODE settings
+for setting={'autonomous', 'vectorized'}
+  value = coco_get(prob, 'ode', setting{:});
+  if ~isempty(value)
+    prob_init = coco_set(prob_init, 'ode', setting{:}, value);
+  end
+end
+
+% COLL settings
+for setting={'NCOL', 'NTST', 'var'}
+  value = coco_get(prob, 'coll', setting{:});
+  if ~isempty(value)
+    prob_init = coco_set(prob_init, 'coll', setting{:}, value);
+  end
+end
+
 pnum = 1;
 k = 1;
 while pnum <= num_pars    
@@ -15,24 +43,27 @@ while pnum <= num_pars
     idx(pnum) = true;
     idx = repelem(idx, data.uq.M);
     vals = data.nds(idx);
+    low = min(vals);
+    high = max(vals);
     msg = sprintf('\n%s: Generating sample points for parameter %s\n', ...
                   tbid, data.spnames{pnum});    
     fprintf(msg)
     if pnum == 1
         run_names{k} = [tbid, '_samples_p', int2str(pnum), '_run', int2str(1)];
-        temp_prob2 = ode_isol2bvp(prob, 'sample', str);
+        temp_prob2 = prob_init;
+        temp_prob2 = ode_isol2bvp(temp_prob2, 'sample', str);       
         [~, opts] = uq_parse_str(str);
         pnames = {data.spnames{pnum}, data.pnames{data.dpar_idx}};
         
         if opts.addadjt
           temp_prob2 = adjt_isol2bvp(temp_prob2, 'sample');
-          dnames = coco_get_id('d', data.pnames);
+          dnames = coco_get_id('d', data.pnames(~data.dpar_idx));
           pnames = {pnames{:}, dnames{:}};
         end
         temp_prob2 = coco_add_event(temp_prob2, 'UQ', ...
             data.spnames{pnum}, vals);
         temp_bds{1} = coco(temp_prob2, run_names{k}, [], 1, pnames, ...
-            [vals(1)-0.01*abs(vals(1)), vals(end)+0.01*abs(vals(end))]);
+            [low, high]);
         k = k+1;
     else
         run_count = 1;
@@ -43,7 +74,8 @@ while pnum <= num_pars
                     '_run', int2str(run_count)];
                 previous_run_name = [tbid, '_samples_p', ...
                     int2str(pnum-1), '_run', int2str(run)];
-                temp_prob2 = ode_bvp2bvp(prob, 'sample', ...
+                temp_prob2 = prob_init;
+                temp_prob2 = ode_bvp2bvp(temp_prob2, 'sample', ...
                     previous_run_name, lab);
                 pnames = {data.spnames{pnum}};
                 pnames = {pnames{:}, data.pnames{data.dpar_idx}};
@@ -58,8 +90,8 @@ while pnum <= num_pars
                     data.spnames{pnum}, vals);
                 temp_bds{run_count} = coco(temp_prob2, run_names{k}, [], ...
                     1, pnames, ...
-                    [vals(1)-0.01*abs(vals(1)), ...
-                     vals(end)+0.01*abs(vals(end))]);
+                    [low, ...
+                     high]);
                 run_count = run_count + 1;
                 k = k+1;
             end
@@ -74,7 +106,7 @@ end
 % parameter.
 for i=1:(numel(run_names) - runs_per_parameter(end))
     try
-%         rmdir(['data/', run_names{i}], 's')
+        rmdir(['data/', run_names{i}], 's')
     catch
         % In case there is an access issue, just leave the folders
     end
diff --git a/matlab_development/uq/toolbox/uq_coll_add_response.m b/matlab_development/uq/toolbox/uq_coll_add_response.m
index f5ff59b27181dc71de90d1dd12e7009a1a0cf777..d905cd7617e69ffcf6ff04b252a42e037ede2da8 100644
--- a/matlab_development/uq/toolbox/uq_coll_add_response.m
+++ b/matlab_development/uq/toolbox/uq_coll_add_response.m
@@ -3,7 +3,7 @@ function prob = uq_coll_add_response(prob, oid, rid, varargin)
 % existing sample of coll instances
 
 % PROB = UQ_COLL_ADD_RESPONSE(PROB, OID, RID, VARARGIN)
-% VARARGIN = {TYPE, R [DR [DDR]]}
+% VARARGIN = {TYPE, R DR [DDR]}
 % TYPE     = { ('bv' | 'int') }
 % 
 % On input:
@@ -15,16 +15,18 @@ function prob = uq_coll_add_response(prob, oid, rid, varargin)
 %              sample to be used in the response function
 % RID        : Response Function object identifier.
 %              The problem instances 
-%              coco_get_id(RID, 'uq.pce'),
-%              coco_get_id(RID, 'uq.pce_mean')
-%              coco_get_id(RID, 'uq.pce_variance') as well
+%              coco_get_id(response_id, RID, 'uq.pce'),
+%              coco_get_id(response_id, RID, 'uq.pce_mean')
+%              coco_get_id(response_id, RID, 'uq.pce_variance') as well
 %              as inactive continuation parameters for the
 %              mean and variance of the response function
 %              whose names are given by
-%              coco_get_id(RID, 'mean') and
-%              coco_get_id(RID, 'variance') will be added
+%              coco_get_id(OID, RID, 'mean') and
+%              coco_get_id(OID, RID, 'variance') will be added
 %              to the continuation problem structure as a
-%              result of a call to this function
+%              result of a call to this function.
+%              The value of response_id is given by
+%              response_id = coco_get_id(oid, 'uq', 'responses');
 % R          : Function handle to the response function.
 %              Can either be a function on the boundary
 %              values of the coll instance 
@@ -34,9 +36,8 @@ function prob = uq_coll_add_response(prob, oid, rid, varargin)
 %              integrated over the segment period.
 % DR         : Jacobian of the response function. Either a
 %              single function DRDU for the boundary
-%              value case or a pair of functions [DRDX,
-%              [DRDP]] for the integral case. Optional, may
-%              be empty)
+%              value case or a pair of functions DRDX,
+%              DRDP for the integral case
 % DDR        : Second derivative of the response function
 %              with respect to its input variables.  Either
 %              DRDUDU for a boundary value response or
@@ -61,7 +62,6 @@ if ischar(varargin{1})
 else  
   assert(ischar(varargin{1}), err_string);
 end
-  
 
 if strcmp(response_type,'int')
   grammar   = 'R [DRDX [DRDP [DRDXDX [DRDXDP [DRDPDP]]]]] [OPTS]';
@@ -84,7 +84,8 @@ end
 
 [args, ~] = coco_parse(grammar, args_spec, {}, varargin{2:end});
 
-uq_data = prob.uq.samples.(oid);
+seg2ndsid = coco_get_id(oid, 'uq.s_par_glue');
+uq_data = coco_get_func_data(prob, seg2ndsid, 'data');
 uq_data.response_type = response_type;
 
 names = fieldnames(args);
@@ -109,8 +110,7 @@ if strcmp(uq_data.response_type, 'bv')
   % Provide the second derivative when the response is
   % evaluated on the boundary values because it uses
   % coco_add_adjt to construct the adjoint instead of
-  % providing an explicit Jacobian for the adjoint (which
-  % the integral response functions do).
+  % providing an explicit Jacobian for the adjoint.
   prob = coco_add_func(prob, pce_id, ...
       @uq_pce_coefficients, @uq_pce_coefficients_dU, ...
       @uq_pce_coefficients_dUdU, ...
@@ -130,9 +130,7 @@ prob = coco_add_slot(prob, pce_id, @coco_save_data, uq_data, 'save_full');
 
 alpha_idx = coco_get_func_data(prob, pce_id, 'uidx');
 
-% Grab the last Nt parameters. This will only work for single output
-% response function.  Leaving it for now, would like to generalize this to
-% multiple output response functions.
+% Grab the last Nt parameters.
 alpha_idx = alpha_idx(end-uq_data.Nt+1:end);
 
 % Calculate statistics from the PCE
diff --git a/matlab_development/uq/toolbox/uq_coll_add_response_adjoint.m b/matlab_development/uq/toolbox/uq_coll_add_response_adjoint.m
index 7b5c22a02f928ebb6d43a46416d4fa0be63401d3..b8375037a2345e392488b1d4f326418b30599568 100644
--- a/matlab_development/uq/toolbox/uq_coll_add_response_adjoint.m
+++ b/matlab_development/uq/toolbox/uq_coll_add_response_adjoint.m
@@ -10,19 +10,31 @@ response_id = coco_get_id(oid, 'uq', 'responses');
 pce_id = coco_get_id(response_id, rid, 'pce');
 uq_data = coco_get_func_data(prob, pce_id, 'data');
 
+% A kludge for checking if tangent diretions need to be
+% added.  This is only true if a run and label are passed
+% in varargin and then only if the type of point that the
+% run and label represent is a Branch Point ('BP')
+add_tl0 = 0;
+
 if isfield(args, 'run')
   % Collect the values of the Adjoint Variables for the PCE
   % coefficients if a run name is passed to the function.
   chart = coco_read_solution(args.run, args.lab, 'chart');
-  cdata = coco_get_chart_data(chart, 'lsol');        
-  [chart, lidx] = coco_read_adjoint(pce_id, args.run, args.lab, ...
-    'chart', 'lidx');
-  l0 = chart.x;
-  tl0 = cdata.v(lidx);
+  
+    cdata = coco_get_chart_data(chart, 'lsol');        
+    [chart, lidx] = coco_read_adjoint(pce_id, args.run, args.lab, ...
+      'chart', 'lidx');
+    l0 = chart.x;
+  if strcmpi(chart.pt_type,'BP')
+    % Check if the run and lab are from a branch point.  If
+    % they are, then get the tangent direction for branch
+    % switching and set a flag for later.
+    tl0 = cdata.v(lidx);
+    add_tl0 = 1;
+  end
 else
   % Otherwise initialize them to zero 
   l0 = zeros(uq_data.Nt,1);
-  tl0 = zeros(uq_data.Nt,1);
 end 
 
 if strcmp(uq_data.response_type, 'int')
@@ -45,11 +57,19 @@ if strcmp(uq_data.response_type, 'int')
   apidx = cell2mat(apidx);
   
   aidx = [aTidx;axidx;apidx];
-
-  prob = coco_add_adjt(prob, pce_id, ...
-    @uq_pce_coefficients_adjoint, ...
-    @uq_pce_coefficients_adjoint_dU, uq_data, ...
-    'aidx', aidx, 'l0', l0, 'tl0', tl0);
+  if add_tl0
+    % Tangent direction if from a Branch Point
+    prob = coco_add_adjt(prob, pce_id, ...
+      @uq_pce_coefficients_adjoint, ...
+      @uq_pce_coefficients_adjoint_dU, uq_data, ...
+      'aidx', aidx, 'l0', l0, 'tl0', tl0);
+  else
+    % No tangent direction if not
+    prob = coco_add_adjt(prob, pce_id, ...
+      @uq_pce_coefficients_adjoint, ...
+      @uq_pce_coefficients_adjoint_dU, uq_data, ...
+      'aidx', aidx, 'l0', l0);
+  end
 
 elseif strcmp(uq_data.response_type, 'bv')
 
@@ -75,9 +95,13 @@ elseif strcmp(uq_data.response_type, 'bv')
 
   aidx = aidx';
   aidx = aidx(:);
-
-  prob = coco_add_adjt(prob, pce_id, 'aidx', ...
-    aidx, 'l0', l0, 'tl0', tl0);
+  if add_tl0
+    prob = coco_add_adjt(prob, pce_id, 'aidx', ...
+      aidx, 'l0', l0, 'tl0', tl0);
+  else
+    prob = coco_add_adjt(prob, pce_id, 'aidx', ...
+      aidx, 'l0', l0);
+  end
 end
 
 dalpha_aidx = coco_get_adjt_data(prob, pce_id, 'axidx');
@@ -93,26 +117,38 @@ if isfield(args, 'run')
   [mean_chart, mean_lidx] = coco_read_adjoint(mean_id, args.run, ...
     args.lab, 'chart', 'lidx');
   mean_l0 = mean_chart.x;
-  mean_tl0 = cdata.v(mean_lidx);
 
   [mean_par_chart, mean_par_lidx] = coco_read_adjoint(mean_par_id, ...
     args.run, args.lab, 'chart', 'lidx');
   mean_par_l0 = mean_par_chart.x;
-  mean_par_tl0 = cdata.v(mean_par_lidx);
+  
+  if add_tl0
+    mean_tl0 = cdata.v(mean_lidx);  
+    mean_par_tl0 = cdata.v(mean_par_lidx);
+  end
 else
   mean_l0 = 0;
-  mean_tl0 = 0;
   mean_par_l0 = 0;
-  mean_par_tl0 = 0;    
 end
 
-prob = coco_add_adjt(prob, mean_id, 'aidx', dalpha_aidx, ...
-  'l0', mean_l0, 'tl0', mean_tl0);
+if add_tl0
+  prob = coco_add_adjt(prob, mean_id, 'aidx', dalpha_aidx, ...
+    'l0', mean_l0, 'tl0', mean_tl0);
+else
+  prob = coco_add_adjt(prob, mean_id, 'aidx', dalpha_aidx, ...
+    'l0', mean_l0);
+end
 mean_aidx = coco_get_adjt_data(prob, mean_id, 'axidx');
 mean_name = coco_get_id(uq_data.oid, rid, 'mean');
 dmean = coco_get_id('d', mean_name);
-prob = coco_add_adjt(prob, mean_par_id, dmean, 'aidx', mean_aidx(end),...
-  'l0', mean_par_l0, 'tl0', mean_par_tl0);
+
+if add_tl0
+  prob = coco_add_adjt(prob, mean_par_id, dmean, 'aidx', mean_aidx(end),...
+    'l0', mean_par_l0, 'tl0', mean_par_tl0);
+else
+  prob = coco_add_adjt(prob, mean_par_id, dmean, 'aidx', mean_aidx(end),...
+    'l0', mean_par_l0);
+end
 
 var_id = coco_get_id(response_id, rid, 'pce_variance');
 var_par_id = coco_get_id(response_id, rid, 'variance');
@@ -124,25 +160,36 @@ if isfield(args, 'run')
   [var_chart, var_lidx] = coco_read_adjoint(var_id, args.run, ...
     args.lab, 'chart', 'lidx');
   var_l0 = var_chart.x;
-  var_tl0 = cdata.v(var_lidx);
+
 
   [var_par_chart, var_par_lidx] = coco_read_adjoint(var_par_id, ...
     args.run, args.lab, 'chart', 'lidx');
   var_par_l0 = var_par_chart.x;
-  var_par_tl0 = cdata.v(var_par_lidx);
+  if add_tl0
+    var_tl0 = cdata.v(var_lidx);
+    var_par_tl0 = cdata.v(var_par_lidx);
+  end
 else
   var_l0 = 0;
-  var_tl0 = 0;
   var_par_l0 = 0;
-  var_par_tl0 = 0;    
 end
 
-prob = coco_add_adjt(prob, var_id, 'aidx', dalpha_aidx, ...
-  'l0', var_l0, 'tl0', var_tl0);
+if add_tl0
+  prob = coco_add_adjt(prob, var_id, 'aidx', dalpha_aidx, ...
+    'l0', var_l0, 'tl0', var_tl0);
+else
+  prob = coco_add_adjt(prob, var_id, 'aidx', dalpha_aidx, ...
+  'l0', var_l0);
+end
 var_aidx = coco_get_adjt_data(prob, var_id, 'axidx');
 var_name = coco_get_id(uq_data.oid, rid, 'var');
 dvar = coco_get_id('d', var_name);
-prob = coco_add_adjt(prob, var_par_id, dvar, 'aidx', var_aidx(end), ...
-  'l0', var_par_l0, 'tl0', var_par_tl0);
+if add_tl0
+  prob = coco_add_adjt(prob, var_par_id, dvar, 'aidx', var_aidx(end), ...
+    'l0', var_par_l0, 'tl0', var_par_tl0);
+else
+  prob = coco_add_adjt(prob, var_par_id, dvar, 'aidx', var_aidx(end), ...
+    'l0', var_par_l0);
+end
 
 end
\ No newline at end of file
diff --git a/matlab_development/uq/toolbox/uq_coll_response_get_idx.m b/matlab_development/uq/toolbox/uq_coll_response_get_idx.m
index 7a641880f6eb33bcefead959f0d261cf844f4872..9d3cfb69cb3081b614912a5720481463e28b8986 100644
--- a/matlab_development/uq/toolbox/uq_coll_response_get_idx.m
+++ b/matlab_development/uq/toolbox/uq_coll_response_get_idx.m
@@ -47,8 +47,7 @@ xbp_idx = cell(1, nsamples);
 p_idx = cell(1, nsamples);
 
 data.resp.T_idx = ones(nsamples,1);
-% Collect collocation node sizes in case they're needed for
-% an adjoint.
+% Collect collocation node sizes in case they're needed for an adjoint.
 data.resp.xcn_idx = ones(nsamples,2); 
 data.resp.xbp_idx = ones(nsamples,2);
 data.resp.p_idx = ones(nsamples, 2);
diff --git a/matlab_development/uq/toolbox/uq_gauss_nodes.m b/matlab_development/uq/toolbox/uq_gauss_nodes.m
index 9d2547a3198c5dceb6c430cf152458a120a5a3cf..9a8b6ee2d85b7c3db31a763d29f306e4754c207e 100644
--- a/matlab_development/uq/toolbox/uq_gauss_nodes.m
+++ b/matlab_development/uq/toolbox/uq_gauss_nodes.m
@@ -1,10 +1,11 @@
 function [nds, wts, idx] = uq_gauss_nodes(m, n, type)
-% Given a quadrature order, m, dimension, n, and quadrature type, type,
+% Given a quadrature order, m, dimension, n, and quadrature type,
 % return the tensor product of the quadrature node locations, nds, and 
-% appropriately multiplied quadrature weight, wts. 
+% appropriately multiplied quadrature weight, wts. Weights
+% are normalized so they add up to 1.
 %
 % m must either be a scalar (equal quadrature order in each dimension) or a
-%   vector with numel(m) = n allow each direction to be set independently.
+%   vector with numel(m) = n to allow each direction to be set independently.
 %
 % n is an integer value for the number of dimension
 %
@@ -12,9 +13,6 @@ function [nds, wts, idx] = uq_gauss_nodes(m, n, type)
 %      specify the quadrature rule for each dimension independently.
 %
 % https://www.mathworks.com/matlabcentral/answers/98191-how-can-i-obtain-all-possible-combinations-of-given-vectors-in-matlab
-%
-% Needs additional work to handle the trivial case of 1
-% sample point.
 
 if ischar(type)
     type = cellstr(type);
@@ -80,22 +78,16 @@ g = num.*sqrt(1./(4*num.^2-1));
 J = -diag(g,1)-diag(g,-1);
 [w, x] = eig(J);
 nds = diag(x)';
-% Normalizing the weights so they add up to one.
-% The weight function is 1/2 for a uniform distribution between -1 and 1
-% instead of the typical uniform distribution between 0 and 1.
 wts = (2*w(1,:).^2)/2;
 end
 
 function [nds, wts] = gauss_hermite_nodes(m)
-num = (1:m-1)';
-g = sqrt(num);
-J = diag(g,1)+diag(g,-1);
-[w, x] = eig(J);
-[nds, idx] = sort(diag(x));
-nds = nds';
-wts = sqrt(2*pi)*w(1,:).^2;
-% Normalizing the weights so they add up to one
-% The weight function is the pdf of the standard normal distribution
-% (1/sqrt(2*pi))*exp((-x.^2)/2).
-wts = wts(idx)/(sqrt(2*pi));
+  num = (1:m-1)';
+  g = sqrt(num);
+  J = diag(g,1)+diag(g,-1);
+  [w, x] = eig(J);
+  [nds, idx] = sort(diag(x));
+  nds = nds';
+  wts = sqrt(2*pi)*w(1,:).^2;
+  wts = wts(idx)/(sqrt(2*pi));
 end
\ No newline at end of file
diff --git a/matlab_development/uq/toolbox/uq_get_responses.m b/matlab_development/uq/toolbox/uq_get_responses.m
index 5bf29356693bf1a4079da2ff91d533cd6af42e9b..d3852fdaa8a9c85db5efa59a8e3714ec8bb3782b 100644
--- a/matlab_development/uq/toolbox/uq_get_responses.m
+++ b/matlab_development/uq/toolbox/uq_get_responses.m
@@ -1,6 +1,5 @@
 function responses = uq_get_responses(varargin)
-%UQ_GET_RESPONSES Get response functions associated with
-% given sample
+% Get response functions associated with given sample
 
 switch numel(varargin)
   case 1
diff --git a/matlab_development/uq/toolbox/uq_init_data.m b/matlab_development/uq/toolbox/uq_init_data.m
index d79f4915119f3ff8d6380a47eedcf0736ea72411..81233c17edf30ddac87e4ded02f47e2528484a49 100644
--- a/matlab_development/uq/toolbox/uq_init_data.m
+++ b/matlab_development/uq/toolbox/uq_init_data.m
@@ -7,30 +7,16 @@ function data = uq_init_data(prob, data, args, opts)
       data.(fields{i}) = args.(fields{i});
   end
   
-  if ~isempty(data.spnames)
-    if ischar(data.spnames)
-        % Convert a single passed parameter to a cell array so the below
-        % code works correctly.
-        data.spnames = cellstr(data.spnames);
-        data.spdists = cellstr(data.spdists);
-    end
-    data.s = length(data.spnames);
-    data.sp2p_idx = ismember(data.pnames, data.spnames);
-    data.dpar_idx = ismember(data.pnames, data.dpdtpars);
-    p_in_sp = ismember(data.spnames, data.pnames);    
-  else
-    % Added this code to handle situations where parameter
-    % names may not be passed, but have not finished it.
-    % Have not worked out how this would work when actually
-    % generating samples (temporary parameter names??)
-    data.s = numel(data.spidx);
-    p_in_sp = data.s;
-    data.sp2p_idx = zeros(1, data.pdim);
-    data.dpar_idx = zeros(1, data.pdim);
-    data.sp2p_idx(data.spidx) = 1;
-    data.dpar_idx(data.dpdtidx) = 1;
-    
+  if ischar(data.spnames)
+      % Convert a single passed parameter to a cell array so the below
+      % code works correctly.
+      data.spnames = cellstr(data.spnames);
+      data.spdists = cellstr(data.spdists);
   end
+  data.s = length(data.spnames);
+  data.sp2p_idx = ismember(data.pnames, data.spnames);
+  data.dpar_idx = ismember(data.pnames, data.dpdtpars);
+  p_in_sp = ismember(data.spnames, data.pnames);    
 
   if numel(data.uq.M) == 1
       % If integration order is equal for all variables, create an array with
@@ -40,8 +26,8 @@ function data = uq_init_data(prob, data, args, opts)
 
   % Nt = Total Number of columns of Psi matrix and number of terms in the PCE
   % expansion.
-  data.Nt = factorial(data.s + data.uq.P)/...
-       ((factorial(data.s))*(factorial(data.uq.P)));
+  data.Nt = factorial(data.s + data.uq.Pt)/...
+       ((factorial(data.s))*(factorial(data.uq.Pt)));
 
   [nds, wts, idx] = uq_gauss_nodes(data.uq.M, data.s, data.spdists);
   data.wts = wts;
@@ -59,6 +45,7 @@ function data = uq_init_data(prob, data, args, opts)
   % Node locations for standard distribution
   data.st_nds = nds';
   % Transformed Node locations for non-standard distribution
+  % Transformation happens in a later function.
   data.nds = nds';
   data.nds_grid = data.nds(data.idx);
   if data.s == 1
diff --git a/matlab_development/uq/toolbox/uq_isol2bvp_sample.m b/matlab_development/uq/toolbox/uq_isol2bvp_sample.m
index 5a50d43092e1c03adba865b8600a0145aeb12ba8..2437ede133f4c6b71cfb8fef9a5e5965d50691dc 100644
--- a/matlab_development/uq/toolbox/uq_isol2bvp_sample.m
+++ b/matlab_development/uq/toolbox/uq_isol2bvp_sample.m
@@ -1,9 +1,9 @@
-function [prob, data] = uq_isol2bvp_sample(prob, oid, varargin)
+function prob = uq_isol2bvp_sample(prob, oid, varargin)
 %UQ_ISOL2BVP_SAMPLE Generate a sample of trajectories from
 % a given initial solution guess. 
 % 
 % PROB = UQ_ISOL2BVP_SAMPLE(PROB, OID, VARARGIN)
-% VARARGIN = { COLL [PNAMES] BCND SPNAMES SPDIST SPDISTPARAMS [FPARS] [OPTS] }
+% VARARGIN = {COLL PNAMES BCND SPNAMES SPDIST SPDISTPARAMS [FPARS] [OPTS] }
 % COLL    = Argument string as would be passed to ode_isol2coll (without
 %           parameter names
 % PNAMES  = Parameter Names (Deterministic and Stochastic)
@@ -25,39 +25,30 @@ function [prob, data] = uq_isol2bvp_sample(prob, oid, varargin)
 % 
 % OPTS = { '-add-adjt' }
 
-tbid = coco_get_id(oid, 'uq');
-str  = coco_stream(varargin{:});
+  tbid = coco_get_id(oid, 'uq');
+  str  = coco_stream(varargin{:});
+  % Required for continuation to sample points
+  temp_str = coco_stream(varargin{:});
+  % This temporary instance is used to initialize the bvp data structure
+  temp_prob2 = ode_isol2bvp(prob, tbid, str);
+  [args, opts] = uq_parse_str(str);
+  bvp_id = coco_get_id(tbid, 'bvp');
+  bc_data = coco_get_func_data(temp_prob2, bvp_id, 'data');
+
+  data = bvp_uq_init_data(bc_data, oid);
+  data = uq_init_data(prob, data, args, opts);
+  data = uq_bvp_gen_samples(data, prob, temp_str);
+
+  [prob, data] = uq_bvp_add_samples(prob, data, bc_data, args);
+  % Waiting until after this function because the grid nodes
+  % and integration weights get re-orded as part of
+  % uq_bvp_add_samples.
+  % Psi_mat construction currently only handles equal
+  % integration order and max polynomial order for each
+  % random variable
+  psi_mat = uq_make_psi_mat(data.nds_grid, data.uq.Pt, data.spdists);
+  data.wtd_psi_mat = psi_mat*diag(data.wts);
+
+  prob  = uq_add_sample_nodes(prob, data, args);
 
-% Required for continuation to sample points
-% using prob instead of coco_prob() ensures that settings
-% applied outside of this function are carried through.
-temp_str = coco_stream(varargin{:});
-
-% The nominal instance may or may not be included in the final continuation
-% problem (depends on the node locations).  This temporary instance will be
-% used to initialize the data structure.  Probably a better way to do this.
-temp_prob2 = ode_isol2bvp(prob, tbid, str);
-[args, opts] = uq_parse_str(str);
-
-
-bvp_id = coco_get_id(tbid, 'bvp');
-bc_data = coco_get_func_data(temp_prob2, bvp_id, 'data');
-
-data = bvp_uq_init_data(prob, bc_data, oid);
-data = uq_init_data(prob, data, args, opts);
-data = uq_bvp_gen_samples(data, prob, temp_str); % handles -add-adjt
-
-if nargout > 1
-  data.bvp_str = coco_stream(varargin{:});
-end
-
-[prob, data] = uq_bvp_add_samples(prob, data, bc_data, args); % handles -add-adjt
-% Waiting until after this function because the grid nodes and integration 
-% weights get re-ordered as part of uq_bvp_add_samples
-% Need to rethink psi_mat construction to handle different integration
-% orders and polynomial degrees.
-psi_mat = uq_make_psi_mat(data.nds_grid, data.uq.P, data.spdists);
-data.wtd_psi_mat = psi_mat*diag(data.wts);
-
-[prob, data]  = uq_add_sample_nodes(prob, data, args); % handles -add-adjt
 end
\ No newline at end of file
diff --git a/matlab_development/uq/toolbox/uq_make_psi_mat.m b/matlab_development/uq/toolbox/uq_make_psi_mat.m
index c86737d4772372a39e3967dd875249f6ccef2469..d1680eea6a132aa98c3621bf96f8d7f351d76f1e 100644
--- a/matlab_development/uq/toolbox/uq_make_psi_mat.m
+++ b/matlab_development/uq/toolbox/uq_make_psi_mat.m
@@ -5,9 +5,8 @@ function psi = uq_make_psi_mat(sample, max_order, poly_type)
 %  ------------------------------------------------------------------------
 %  max_order = P = Maximum Total Polynomial Order (as described above)
 %  Number of Random Variables Describing the system, s = size(sample, 2)
-%  Number of Quadrature points, M = size(sample, 1) = Quadrature_Order^s
+%  Number of Quadrature points, M = size(sample, 1)
 %  psi is an Nt X M) matrix where Nt = (s + P)! / (s! P!).
-%  Quadrature_Order is set independently of this function.
 
 sample = sample';
 
diff --git a/matlab_development/uq/toolbox/uq_orthogonal_poly_vals.m b/matlab_development/uq/toolbox/uq_orthogonal_poly_vals.m
index 5dd182374325589df7a822fdcf62dc412fa05cc6..dd14decce39611b43e91b6c9b41ee640b2161f84 100644
--- a/matlab_development/uq/toolbox/uq_orthogonal_poly_vals.m
+++ b/matlab_development/uq/toolbox/uq_orthogonal_poly_vals.m
@@ -48,15 +48,15 @@ for j=1:s
       else
 
       end
-        if max_order==0
-          % Special code for trivial case to get matrix dimensions to agree
-          psi = psi(:,:,1);
-        else
-          % Three term recurrence for Hermite Orthogonal polynomials
-          for i=3:(max_order+1)
-            psi(:,j,i) = x(:,j).*psi(:,j,i-1) - (i-2)*psi(:,j,i-2);
-          end
+      if max_order==0
+        % Special code for trivial case to get matrix dimensions to agree
+        psi = psi(:,:,1);
+      else
+        % Three term recurrence for Hermite Orthogonal polynomials
+        for i=3:(max_order+1)
+          psi(:,j,i) = x(:,j).*psi(:,j,i-1) - (i-2)*psi(:,j,i-2);
         end
+      end
   end
 end
 psi = wts.*psi;
diff --git a/matlab_development/uq/toolbox/uq_parse_str.m b/matlab_development/uq/toolbox/uq_parse_str.m
index d5af7aa734568acf1344fcf90f2d7ace40ae9ff3..eddd22b24c016c1c60062b59d085c200d9864f08 100644
--- a/matlab_development/uq/toolbox/uq_parse_str.m
+++ b/matlab_development/uq/toolbox/uq_parse_str.m
@@ -1,38 +1,18 @@
 function [uqdata, opts] = uq_parse_str(str)
 
-% Added this code to handle situations where parameter
-% may not be named, but have not finished it.
-% Have not worked out how this would work when actually
-% generating samples (temporary parameter names??)
-% grammar   = '[SPNAMES] [SPIDX] SPDIST SPDP [DPARNAMES] [DPARIDX] [OPTS]';
-% args_spec = {
-%      'SPNAMES', 'cell', '{str}',    'spnames',       {}, 'read', {}
-%        'SPIDX',     '', '[num]',      'spidx',       {}, 'read', {}
-%       'SPDIST', 'cell', '{str}',    'spdists',       {}, 'read', {}
-%         'SPDP',     '', '[num]',       'spdp',       {}, 'read', {}
-%    'DPARNAMES', 'cell', '{str}',   'dpdtpars',       {}, 'read', {}
-%      'DPARIDX',     '', '[num]',    'dpdtidx',       {}, 'read', {}
-%   };
+  grammar   = 'SPNAMES SPDIST SPDP [DPARNAMES] [OPTS]';
+  args_spec = {
+       'SPNAMES', 'cell', '{str}',    'spnames',       {}, 'read', {}
+        'SPDIST', 'cell', '{str}',    'spdists',       {}, 'read', {}
+          'SPDP',     '', '[num]',       'spdp',       {}, 'read', {}
+     'DPARNAMES', 'cell', '{str}',   'dpdtpars',       {}, 'read', {}
+    };
 
-grammar   = 'SPNAMES SPDIST SPDP [DPARNAMES] [OPTS]';
-args_spec = {
-     'SPNAMES', 'cell', '{str}',    'spnames',       {}, 'read', {}
-      'SPDIST', 'cell', '{str}',    'spdists',       {}, 'read', {}
-        'SPDP',     '', '[num]',       'spdp',       {}, 'read', {}
-   'DPARNAMES', 'cell', '{str}',   'dpdtpars',       {}, 'read', {}
-  };
+  opts_spec = {
+    '-add-adjt', 'addadjt', false, 'toggle', {}
+    };
 
-opts_spec = {
-  '-add-adjt', 'addadjt', false, 'toggle', {}
-  };
-
-[uqdata, opts] = coco_parse(grammar, args_spec, opts_spec, str);
-
-% msg = ['Either a cell array of parameter names or a ', ...
-%        'numerical array of parameter indices must be ', ...
-%        'provided as the first UQ argument'];
-% 
-% assert(~isempty(uqdata.spnames) || ~isempty(uqdata.spidx), msg)
+  [uqdata, opts] = coco_parse(grammar, args_spec, opts_spec, str);
 
 end
 
diff --git a/matlab_development/uq/toolbox/uq_pce_mean.m b/matlab_development/uq/toolbox/uq_pce_mean.m
index b3f68d7fe9d028bf55103cf4d5e79e1190faa3bd..1a2b7964ef7e8c791ddf3af3ecdf38e3f82def85 100644
--- a/matlab_development/uq/toolbox/uq_pce_mean.m
+++ b/matlab_development/uq/toolbox/uq_pce_mean.m
@@ -3,9 +3,6 @@ function [data, y] = uq_pce_mean(prob, data, u)
 %  Given an array of PCE coefficients return the mean value of the
 %  expansion (first term in the expansion)
 
-% Currently works for only single output response functions.  Would like to
-% generalize this to multiple output response functions.
-
 alpha0 = u(1);
 mu = u(end);
 y = mu - alpha0;
diff --git a/matlab_development/uq/toolbox/uq_pce_mean_dU.m b/matlab_development/uq/toolbox/uq_pce_mean_dU.m
index 2f8309fe81770e729560335a0649a80bf46fd182..bf3a88fdd78cd7153e6dae08cbb04b31f0a3454c 100644
--- a/matlab_development/uq/toolbox/uq_pce_mean_dU.m
+++ b/matlab_development/uq/toolbox/uq_pce_mean_dU.m
@@ -3,18 +3,6 @@ function [data, J] = uq_pce_mean_dU(prob, data, u)
 %  Given an array of PCE coefficients return the Jacobian of the mean value
 %  with respect to the expansion coefficients
 
-% % Attempting to make this work for arbitrary response outputs, though
-% % currently not passing the u's to this function correctly in 
-% % uq_add_response_function.m to make that happen.
-% total_alphas = numel(u);
-% alphas_per_response_output = data.uq.Nt;
-% number_of_responses = total_alphas / alphas_per_response_output;
-% 
-% i = 1:number_of_responses;
-% j = 1 + [0:number_of_responses-1]*alphas_per_response_output;
-% J = sparse(i, j, ones(1,number_of_responses), ...
-%            number_of_responses, total_alphas);
-
 J = zeros(size(u'));
 J(1) = -1;
 J(end) = 1;
diff --git a/matlab_development/uq/toolbox/uq_pce_mean_dUdU.m b/matlab_development/uq/toolbox/uq_pce_mean_dUdU.m
index f9c43b1f677485c1c2853918d465274daf1fd4aa..e87f2878991dc3e05cab6cdb7e1be61b6018b5ff 100644
--- a/matlab_development/uq/toolbox/uq_pce_mean_dUdU.m
+++ b/matlab_development/uq/toolbox/uq_pce_mean_dUdU.m
@@ -3,17 +3,6 @@ function [data, dJ] = uq_pce_mean_dUdU(prob, data, u)
 %  Given an array of PCE coefficients return the Jacobian of the mean value
 %  with respect to the expansion coefficients
 
-% % Attempting to make this work for arbitrary response outputs, though
-% % currently not passing the u's to this function correctly in
-% % uq_add_response_function.m
-% total_alphas = numel(u);
-% alphas_per_response_output = data.uq.Nt;
-% number_of_responses = total_alphas / alphas_per_response_output;
-% 
-% dJ = zeros(number_of_responses, total_alphas, total_alphas);
-
 dJ = zeros(1, numel(u), numel(u));
 
-% Checked with
-% [data, dJd] = coco_ezDFDX('f(o,d,x)', prob, data, @uq_pce_mean_dU, u);
 end
diff --git a/matlab_development/uq/toolbox/uq_pce_variance.m b/matlab_development/uq/toolbox/uq_pce_variance.m
index 6cc750a99b890af8b8c84b3cdd2040a7a026571d..a66d401825cef41eb457696ceeecbf6b8092c3ff 100644
--- a/matlab_development/uq/toolbox/uq_pce_variance.m
+++ b/matlab_development/uq/toolbox/uq_pce_variance.m
@@ -3,11 +3,6 @@ function [data, y] = uq_pce_variance(prob, data, u)
 %  Given the coefficient of a polynomial chaos expansion, return the
 %  variance of the expansion.
 
-% Reshaping alphas for repsonse functions that may have
-% more than one output.  Initial assignment of alphas and
-% variance variable would also need to change to support 
-% this though.
-
 alphas = u(1:end-1);
 alphas = reshape(alphas, [], data.Nt);
 variance = u(end);
diff --git a/matlab_development/uq/toolbox/uq_pce_variance_dU.m b/matlab_development/uq/toolbox/uq_pce_variance_dU.m
index b744a6f197f9f571d0947f7d0baa1019826ea8c1..d92125880aea3c3e05138b2a4e921e015c3af5ce 100644
--- a/matlab_development/uq/toolbox/uq_pce_variance_dU.m
+++ b/matlab_development/uq/toolbox/uq_pce_variance_dU.m
@@ -3,26 +3,6 @@ function [data, J] = uq_pce_variance_dU(prob, data, u)
 %  Calculate the Jacobian of the variance of a Polynomial Chaos Expansion
 %  (PCE) with respect to the PCE coefficients.
 
-% This code is an attempt to generalize for response
-% functions with more than one output, but the code is not
-% currently ready for that.  Instead commenting this out
-% and handling cases for a single output response.  Also
-% not that the code commented out here was written for when
-% the variance was calculated as part of a monitor
-% function.  It has since been changed to a zero function
-% so that the variance can be used in a robust optimization
-% objective function.  Updates will need account for this
-% change.
-% total_alphas = numel(alphas);
-% alphas_per_response_output = data.uq.Nt;
-% number_of_responses = total_alphas / alphas_per_response_output;
-% alphas = reshape(2*alphas, alphas_per_response_output, []);
-% alphas(1,:) = 0;
-% [r,c] = size(alphas);
-% i = 1:numel(alphas);
-% j = repmat(1:c,r,1);
-% J = sparse(j(:),i',alphas(:));
-
 J = zeros(1, numel(u));
 J(2:end-1) = -2*u(2:end-1);
 J(end) = 1;
diff --git a/matlab_development/uq/toolbox/uq_pce_variance_dUdU.m b/matlab_development/uq/toolbox/uq_pce_variance_dUdU.m
index 38984930a68a18b7837d0b284779fdbb07627081..6a7808136b40b18519640030442a3766d9cd2cf3 100644
--- a/matlab_development/uq/toolbox/uq_pce_variance_dUdU.m
+++ b/matlab_development/uq/toolbox/uq_pce_variance_dUdU.m
@@ -1,26 +1,8 @@
 function [data, dJ] = uq_pce_variance_dUdU(prob, data, u)
 %UQ_PCE_VARIANCE_DUDU Jacobian of the variance of a PCE w/r/t alphas
 
-% total_alphas = numel(alphas);
-% alphas_per_response_output = data.uq.Nt;
-% number_of_responses = total_alphas / alphas_per_response_output;
-% 
-% i = repmat(1:number_of_responses, alphas_per_response_output-1, 1);
-% j = [repmat(2:alphas_per_response_output,number_of_responses,1)]' + ...
-%      repmat(alphas_per_response_output*(0:(number_of_responses-1)), ...
-%             alphas_per_response_output-1,1);
-% 
-% 
-% dJ = zeros(number_of_responses, total_alphas, total_alphas);
-% for k = 1:(number_of_responses*(alphas_per_response_output-1))
-%     dJ(i(k), j(k), j(k)) = 2;
-% end
-
 dJ = zeros(1, numel(u), numel(u));
 dJ(1, 2:end-1, 2:end-1) = -2*eye(data.Nt - 1);
 
-% Checked with
-% [data, dJd] = coco_ezDFDX('f(o,d,x)', prob, data, @uq_pce_variance_dU, u);
-
 end
 
diff --git a/matlab_development/uq/toolbox/uq_response_evaluation.m b/matlab_development/uq/toolbox/uq_response_evaluation.m
index 4fad3451a13dc0b8b811d424596d7f36290f2a18..462bd340a8d663a6e6e026bd42d21963beb9c800 100644
--- a/matlab_development/uq/toolbox/uq_response_evaluation.m
+++ b/matlab_development/uq/toolbox/uq_response_evaluation.m
@@ -3,20 +3,6 @@ function [data, r] = uq_response_evaluation(prob, data, u)
 
 if strcmp(data.response_type, 'int')
   for i=1:data.nsamples
-    % Thought:
-    % If trajectories have varying number of basis
-    % points, could construct a matrix that accomodates
-    % the one with the most basis points and then pad the
-    % others with zeros.  The resulting inner products
-    % for integration should come out the same
-    % x = [[---x_bp1--- 0 ... 0];
-    %      [---x_bp2----- 0...0];
-    %             |
-    %       [--x_bp(M^s)-------]];
-    %
-    % The weights matrix would be similarly padded
-    % wts = transpose([wts1, wts2, ... , wts(M^s)])
-    
     % Separate out components
     T = u(data.resp.T_idx(i,1));
     x = u(data.resp.xbp_idx(i,1):data.resp.xbp_idx(i,end));
@@ -80,7 +66,7 @@ r = T/(2*maps.NTST)*resp*wts1;
 end
 
 function r = int_resp_nu(uq_data, fdata, T, x, p) 
-
+% Incomplete!
 % For non-uniform mesh
 maps = fdata.coll_seg.maps;
 mesh = fdata.coll_seg.mesh;
@@ -89,7 +75,7 @@ xcn = reshape(maps.W*x, maps.x_shp);
 pp  = repmat(p, maps.p_rep);
 
 rcn = uq_data.rhan(xcn, pp);
-rcn = mesh.gka.*rcn;   % mesh here is related adaptive meshing
+rcn = mesh.gka.*rcn; % mesh here is related adaptive meshing
 
 
 r = (0.5*T/maps.NTST)*mesh.gwt*rcn';
diff --git a/matlab_development/uq/toolbox/uq_seg_to_nds.m b/matlab_development/uq/toolbox/uq_seg_to_nds.m
new file mode 100644
index 0000000000000000000000000000000000000000..459642ceac186a7f8fce51e518c649214e608ca5
--- /dev/null
+++ b/matlab_development/uq/toolbox/uq_seg_to_nds.m
@@ -0,0 +1,11 @@
+function [data, y] = uq_seg_to_nds(prob, data, u)
+
+seg_pars  = u(1:numel(data.idx));
+nds_start = numel(data.idx) + 1;
+node_pars = u(nds_start:end);
+node_pars = node_pars(data.idx);
+node_pars = node_pars(:);
+
+y = seg_pars - node_pars;
+
+end
\ No newline at end of file
diff --git a/matlab_development/uq/toolbox/uq_seg_to_nds_du.m b/matlab_development/uq/toolbox/uq_seg_to_nds_du.m
new file mode 100644
index 0000000000000000000000000000000000000000..961121d3ba20ec0b0b8dc5c10d8bf25a81d7d1d3
--- /dev/null
+++ b/matlab_development/uq/toolbox/uq_seg_to_nds_du.m
@@ -0,0 +1,10 @@
+function [data, J] = uq_seg_to_nds_du(prob, data, u)
+
+negs = data.idx+numel(data.idx);
+negs = negs(:);
+i = repmat(1:numel(data.idx),[1,2]);
+j = [1:numel(data.idx), negs'];
+v = [ones(1,numel(data.idx)), -ones(1,numel(data.idx))];
+J = sparse(i, j, v);
+
+end
\ No newline at end of file
diff --git a/matlab_development/uq/toolbox/uq_seg_to_nds_dudu.m b/matlab_development/uq/toolbox/uq_seg_to_nds_dudu.m
new file mode 100644
index 0000000000000000000000000000000000000000..c96bf5b74a547e3b06912d2e4315a35388db364f
--- /dev/null
+++ b/matlab_development/uq/toolbox/uq_seg_to_nds_dudu.m
@@ -0,0 +1,5 @@
+function [data, dJ] = uq_seg_to_nds_dudu(prob, data, u)
+
+dJ = zeros(numel(data.idx), numel(u), numel(u));
+
+end
\ No newline at end of file