Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
Loading...
Searching...
No Matches
interpolation.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//interpolation.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//interpolation.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with interpolation.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) 2015 - 2021 by Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22// individual authors of this file include:
23// silviana amethyst, university of wisconsin eau claire
24// Tim Hodges, Colorado State University
25
29
30#pragma once
31
32#include "bertini2/common/config.hpp"
33
34namespace bertini{
35 namespace endgame{
36
62template<typename CT>
63 Vec<CT> HermiteInterpolateAndSolve(CT const& target_time, const unsigned int num_sample_points, const TimeCont<CT> & times, const SampCont<CT> & samples, const SampCont<CT> & derivatives, ContStart shift_from = ContStart::Back)
64{
65 assert((times.size() >= num_sample_points) && "must have sufficient number of sample times");
66 assert((samples.size() >= num_sample_points) && "must have sufficient number of sample points");
67 assert((derivatives.size() >= num_sample_points) && "must have sufficient number of derivatives");
68
69
70 unsigned num_t, num_s, num_d;
71 if (shift_from == ContStart::Back)
72 {
73 num_t = times.size()-1;
74 num_s = samples.size()-1;
75 num_d = derivatives.size()-1;
76 }
77 else
78 {
79 num_t = num_s = num_d = num_sample_points-1;
80 }
81
82 Mat< Vec<CT> > space_differences(2*num_sample_points,2*num_sample_points);
83 Vec<CT> time_differences(2*num_sample_points);
84
85
86 for(unsigned int ii=0; ii<num_sample_points; ++ii)
87 {
88 space_differences(2*ii,0) = samples[ num_s-ii]; /* F[2*i][0] = samples[i]; */
89 space_differences(2*ii+1,0) = samples[ num_s-ii]; /* F[2*i+1][0] = samples[i]; */
90 space_differences(2*ii+1,1) = derivatives[num_d-ii]; /* F[2*i+1][1] = derivatives[i]; */
91 time_differences(2*ii) = times[ num_t-ii]; /* z[2*i] = times[i]; */
92 time_differences(2*ii+1) = times[ num_t-ii]; /* z[2*i+1] = times[i]; */
93 }
94
95 //Add first round of finite differences to fill out rest of matrix.
96 for(unsigned int ii=1; ii< num_sample_points; ++ii)
97 {
98 space_differences(2*ii,1) = (space_differences(2*ii,0) - space_differences(2*ii-1,0)) / (time_differences(2*ii) - time_differences(2*ii-1));
99
100 }
101
102 //Filling out finite difference matrix to get the diagonal for hermite interpolation polyonomial.
103 for(unsigned int ii=2; ii < 2*num_sample_points; ++ii)
104 {
105 for(unsigned int jj=2; jj <=ii; ++jj)
106 {
107 space_differences(ii,jj) =
108 (space_differences(ii,jj-1) - space_differences(ii-1,jj-1))
109 /
110 (time_differences(ii) - time_differences(ii-jj));
111 }
112 }
113
114 //Start of Result from Hermite polynomial, this is using the diagonal of the
115 //finite difference matrix.
116 Vec<CT> Result = space_differences(2*num_sample_points - 1,2*num_sample_points - 1);
117
118
119 //This builds the hermite polynomial from the highest term down.
120 //As we multiply the previous result we will construct the highest term down to the last term.
121 for (unsigned ii=num_sample_points-1; ii >= 1; --ii)
122 {
123 Result = ((Result*(target_time - time_differences(ii)) + space_differences(2*ii, 2*ii)) * (target_time - time_differences(ii-1)) + space_differences(2*ii-1, 2*ii-1)).eval();
124 }
125
126 // Last term in hermite polynomial.
127 return (Result * (target_time - time_differences(0)) + space_differences(0,0)).eval();
128} //re: HermiteInterpolateAndSolve
129
130}} // re: namespaces
Vec< CT > HermiteInterpolateAndSolve(CT const &target_time, const unsigned int num_sample_points, const TimeCont< CT > &times, const SampCont< CT > &samples, const SampCont< CT > &derivatives, ContStart shift_from=ContStart::Back)
Estimates the root to interpolating polynomial.
Definition interpolation.hpp:63