codac 2.0.0
Loading...
Searching...
No Matches
codac2_TrajBase_impl.h
Go to the documentation of this file.
1
9
10#pragma once
11
12namespace codac2
13{
14 template<typename T>
15 auto TrajBase<T>::nan_value() const
16 {
17 if constexpr(std::is_same_v<T,double> || std::is_same_v<typename ExprType<T>::Type,ScalarType>)
18 return std::numeric_limits<double>::quiet_NaN();
19
20 else
21 return T((*this)(tdomain().lb())) // we obtain the output dimension by an evalution...
22 .init(std::numeric_limits<double>::quiet_NaN());
23 }
24
25 template<typename T>
26 SampledTraj<T> TrajBase<T>::sampled(double dt) const
27 {
28 assert_release(dt > 0.);
29 assert_release(!is_empty());
30
31 auto tdom = tdomain();
32 SampledTraj<T> straj;
33 for(double t = tdom.lb() ; t < tdom.ub() ; t+=dt)
34 straj.set((*this)(t), t);
35 straj.set((*this)(tdom.ub()), tdom.ub());
36 return straj;
37 }
38
39 template<typename T>
40 template<typename Q>
41 SampledTraj<T> TrajBase<T>::sampled_as(const SampledTraj<Q>& x) const
42 {
43 assert_release(x.tdomain().is_subset(this->tdomain()));
44
45 SampledTraj<T> straj;
46 for(const auto& [ti,dump] : x)
47 straj.set((*this)(ti), ti);
48 return straj;
49 }
50
51 template<typename T>
52 SampledTraj<T> TrajBase<T>::primitive(double dt) const
53 {
54 assert_release(dt > 0.);
55 assert_release(!is_empty());
56
57 T s = [this]() {
58 if constexpr(std::is_same_v<T,double>)
59 return 0.;
60 else
61 return T((*this)(this->tdomain().lb())).init(0.);
62 }();
63
64 SampledTraj<T> p;
65 double t = tdomain().lb(), last_t = t;
66 p.set(s, t); t += dt;
67
68 while(t < tdomain().ub())
69 {
70 s += ((*this)(last_t)+(*this)(t))*dt/2.;
71 p.set(s, t);
72 last_t = t;
73 t += dt;
74 }
75
76 t = tdomain().ub();
77 s += ((*this)(last_t)+(*this)(t))*(t-last_t)/2.;
78 p.set(s, t);
79
80 return p;
81 }
82}
bool is_empty() const
Checks whether the interval matrix is empty.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:56
auto ub() const
Returns a matrix containing the upper bounds of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:103
auto lb() const
Returns a matrix containing the lower bounds of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:91
Definition codac2_OctaSym.h:21