1 #ifndef CLASSIC_LinearMap_CC
2 #define CLASSIC_LinearMap_CC
37 template <
class T,
int N>
39 for(
int i = 0; i < N; ++i) data[i][i+1] = 1.0;
43 template <
class T,
int N>
45 for(
int i = 0; i < N; ++i) {
46 for(
int j = 0; j <= N; ++j) data[i][j] = rhs[i][j];
51 template <
class T,
int N>
53 for(
int i = 0; i < N; ++i) {
54 for(
int j = 0; j < N; j++) data[i][j+1] = x[i][j];
59 template <
class T,
int N>
61 for(
int i = 0; i < N; i++) data[i][0] = x[i];
65 template <
class T,
int N>
68 throw CLRangeError(
"LinearMap::getComponent()",
"Index out of range.");
75 template <
class T,
int N>
78 throw CLRangeError(
"LinearMap::setComponent()",
"Index out of range.");
85 template <
class T,
int N>
inline
90 template <
class T,
int N>
inline
96 template <
class T,
int N>
102 template <
class T,
int N>
105 for(
int i = 0; i < N; i++) z[i] = - data[i];
110 template <
class T,
int N>
112 for(
int i = 0; i < N; i++) data[i] *= rhs;
117 template <
class T,
int N>
120 for(
int i = 0; i < N; i++) data[i] *= t;
125 template <
class T,
int N>
127 for(
int i = 0; i < N; i++) data[i] *= rhs;
132 template <
class T,
int N>
134 for(
int i = 0; i < N; i++) data[i] /= rhs;
139 template <
class T,
int N>
141 for(
int i = 0; i < N; i++) data[i] += rhs[i];
146 template <
class T,
int N>
148 for(
int i = 0; i < N; i++) data[i] -= rhs[i];
153 template <
class T,
int N>
155 for(
int i = 0; i < N; i++) data[i] += rhs[i];
160 template <
class T,
int N>
162 for(
int i = 0; i < N; i++) data[i] -= rhs[i];
167 template <
class T,
int N>
169 is.flags(std::ios::skipws);
171 (is >> std::ws).get(head, 4);
173 if(strcmp(head,
"LinearMap") != 0) {
174 throw FormatError(
"LinearMap::get()",
"Flag word \"LinearMap\" missing.");
181 throw FormatError(
"LinearMap::get()",
"Invalid LinearMap dimension");
186 for(
int i = 0; i < N; i++) is >> z.
data[i];
192 template <
class T,
int N>
195 for(
int i = 0; i < N; i++) os << data[i];
200 template <
class T,
int N>
213 template <
class T,
int N>
215 for(
int i = 0; i < N; ++i) data[i] = LinearFun<T, N>::makeVariable(i);
219 template <
class T,
int N>
223 for(
int i = 0; i < N; ++i) {
225 for(
int j = 0; j < N; ++j) {
226 z[i] += data[i][j+1] * rhs[j];
234 template <
class T,
int N>
237 for(
int i = 0; i < N; i++) z[i] = data[i][0];
242 template <
class T,
int N>
246 for(
int i = 0; i < N; i++) {
247 for(
int j = 0; j < N; j++) {
248 z(i, j) = data[i][j+1];
256 template <
class T,
int N>
260 for(
int i = 0; i < N; ++i) {
261 z.
data[i][0] = data[i][0];
262 for(
int j = 0; j < N; ++j) {
263 for(
int k = 0; k <= N; ++k) {
264 z.
data[i][k] += data[i][j+1] * rhs.
data[j][k];
273 template <
class T,
int N>
277 for(
int i = 0; i < N; ++i) {
278 z.
data[i][0] = data[i][0];
279 for(
int j = 0; j < N; ++j) {
280 for(
int k = 0; k < N; ++k) {
281 z.
data[i][k+1] += data[i][j+1] * rhs[j][k];
290 template <
class T,
int N>
294 for(
int i = 0; i < N; ++i) {
295 for(
int j = 0; j < N; ++j) {
296 z[i] += lhs[i][j] * data[j];
307 template <
class T,
int N>
310 for(
int i = 0; i < N; ++i) z[i] = lhs[i] * rhs;
315 template <
class T,
int N>
318 for(
int i = 0; i < N; ++i) z[i] = lhs * rhs[i];
323 template <
class T,
int N>
326 for(
int i = 0; i < N; ++i) z[i] = lhs[i] * rhs;
331 template <
class T,
int N>
334 for(
int i = 0; i < N; ++i) z[i] = lhs * rhs[i];
338 template <
class T,
int N>
344 template <
class T,
int N>
347 for(
int i = 0; i < N; ++i) z[i] = lhs[i] / rhs;
352 template <
class T,
int N>
355 for(
int i = 0; i < N; ++i) z[i] = lhs[i] / rhs;
360 template <
class T,
int N>
363 for(
int i = 0; i < N; ++i) z[i] = lhs[i] + rhs[i];
368 template <
class T,
int N>
371 for(
int i = 0; i < N; ++i) z[i] = lhs[i] - rhs[i];
376 template <
class T,
int N>
379 for(
int i = 0; i < N; ++i) z[i] = lhs[i] + rhs[i];
384 template <
class T,
int N>
387 for(
int i = 0; i < N; ++i) z[i] = lhs[i] - rhs[i];
392 template <
class T,
int N>
395 for(
int i = 0; i < N; ++i) z[i] = lhs[i] + rhs[i];
400 template <
class T,
int N>
403 for(
int i = 0; i < N; ++i) z[i] = lhs[i] - rhs[i];
408 template <
class T,
int N>
414 template <
class T,
int N>
std::ostream & operator<<(std::ostream &os, const LinearMap< T, N > &vps)
Insert LinearMap to stream [b]os[/b].
LinearMap< T, N > operator*(const LinearMap< T, N > &lhs, const LinearFun< T, N > &rhs)
Multiply.
std::istream & operator>>(std::istream &is, LinearMap< T, N > &vps)
Extract LinearMap from stream [b]is[/b].
LinearMap< T, N > operator+(const LinearMap< T, N > &lhs, const LinearMap< T, N > &rhs)
Add.
LinearMap< T, N > operator-(const LinearMap< T, N > &lhs, const LinearMap< T, N > &rhs)
Subtract.
LinearMap< T, N > operator/(const LinearMap< T, N > &lhs, const LinearFun< T, N > &rhs)
Divide.
Inform & endl(Inform &inf)
Vector truncated power series in n variables.
A templated representation of a LU-decomposition.
FMatrix< T, N, N > inverse() const
Get inverse.
A templated representation for vectors.
Linear map with values of type [b]T[/b] in [b]N[/b] variables.
LinearMap substitute(const FMatrix< T, N, N > &rhs) const
Substitute matrix into map.
FVector< T, N > constantTerm() const
std::istream & get(std::istream &is)
Get a LinearMap from stream [b]is[/b].
const LinearFun< T, N > & getComponent(int n) const
Get component.
LinearMap operator+() const
Unary plus.
void identity()
Set to identity.
FMatrix< T, N, N > linearTerms() const
Extract linear terms at origin.
LinearMap inverse() const
Inverse.
LinearFun< T, N > data[N]
LinearMap & operator*=(const LinearFun< T, N > &rhs)
Multiply and assign.
LinearMap substituteInto(const FMatrix< T, N, N > &lhs) const
Substitute map into matrix.
LinearMap()
Default constructor.
std::ostream & put(std::ostream &os) const
Put a LinearMap to stream [b]os[/b].
LinearMap operator-() const
Unary minus.
LinearMap & operator/=(const LinearFun< T, N > &rhs)
Divide and assign.
LinearFun< T, N > & operator[](int)
Get component.
LinearMap & operator+=(const LinearMap &rhs)
Add.
LinearMap & operator-=(const LinearMap &rhs)
Subtract.
void setComponent(int, const LinearFun< T, N > &)
Set component.
Linear function in N variables of type T.
LinearFun inverse() const
Approximate reciprocal value 1/(*this).