FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
Vectorfit.h
1#ifndef CVectorfit_h__
2#define CVectorfit_h__
3
4#include <complex>
5#include <Eigen/Eigen>
6
7namespace Ship{
8 typedef Eigen::Matrix< std::complex<double>,1,Eigen::Dynamic> vec_complex;
9 typedef Eigen::Matrix< double,1,Eigen::Dynamic> vec;
10 typedef Eigen::Matrix< double,Eigen::Dynamic,Eigen::Dynamic> mat ;
11 typedef Eigen::Matrix< std::complex<double>,Eigen::Dynamic,Eigen::Dynamic> mat_complex ;
12
26 {
27 public:
28 EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
32 int Fitoption() const { return m_Fitoption; }
33 void Fitoption(int val) { m_Fitoption = val; }
34
36 bool RelaxedConstraint() const { return m_RelaxedConstraint; }
37 void RelaxedConstraint(bool val) { m_RelaxedConstraint = val; }
39 bool FlipUnstable() const { return m_FlipUnstable; }
40 void FlipUnstable(bool val) { m_FlipUnstable = val; }
42 bool PoleIdentification() const { return m_PoleIdentification; }
43 void PoleIdentification(bool val) { m_PoleIdentification = val; }
45 bool ResidueIdentification() const { return m_ResidueIdentification; }
46 void ResidueIdentification(bool val) { m_ResidueIdentification = val; }
48 bool ComplexStateSpace() const { return m_ComplexStateSpace; }
49 void ComplexStateSpace(bool val) { m_ComplexStateSpace = val; }
50
53 mat_complex MatrixA() const { return matrixA; }
54 void MatrixA(mat_complex val) { matrixA = val; }
55 mat_complex MatrixB() const { return matrixB; }
56 void MatrixB(mat_complex val) { matrixB = val; }
57 mat_complex MatrixC() const { return matrixC; }
58 void MatrixC(mat_complex val) { matrixC = val; }
59 std::complex<double> MatrixD() const { return matrixD; }
60 void MatrixD(std::complex<double> val) { matrixD = val; }
61 std::complex<double> MatrixE() const { return matrixE; }
62 void MatrixE(std::complex<double> val) { matrixE = val; }
64
65 mat MatrixAreal() const ;
66 mat MatrixBreal() const ;
67 mat MatrixCreal() const ;
68 double MatrixDreal() const ;
69 double MatrixEreal() const ;
70
72 mat_complex Diff() const { return diff; }
74 double Rmserr() const { return rmserr;}
75
88 void Fit(const vec_complex &f, const vec_complex &s, vec_complex &poles, const vec & weight);
89
90 vec_complex LinSolveLS( mat &A, mat &B);
91 vec_complex LinSolve( mat &A, mat &B);
92 vec_complex MatrixPolynomial( const mat_complex &A );
93 vec_complex EigenValues( const mat_complex &ZER );
94
95 void QRFactor( mat &A_new, mat &Q, mat &R );
96 void TransferFunction( vec_complex& num, vec_complex &den);
97
98 private:
99 int m_Fitoption; // 1: Fitting with D=0, E=0, 2: Fitting with D~=0, E=0, 3: Fitting with D~=0, E~=0
100 bool m_RelaxedConstraint; // Use relaxed nontriviality constraint
101 bool m_FlipUnstable; // Unstable poles are kept unchanged
102 bool m_PoleIdentification; // The pole identification part is skipped, i.e (C,D,E)
103 bool m_ResidueIdentification; // The residue identification part is skipped, i.e. only the poles (A) are identified while C,D,E are returned as zero.
104 bool m_ComplexStateSpace; // The returned state-space model has real and complex parameters. Output variable A is diagonal (and sparse).
105
106 mat_complex diff;
107 double rmserr;
108
109 mat_complex matrixA;
110 mat_complex matrixB;
111 mat_complex matrixC;
112 std::complex<double> matrixD;
113 std::complex<double> matrixE;
117 static bool root_less_pred( std::complex<double> const& lh, std::complex<double> const &rh)
118 {
119 if( lh.real() != rh.real() )
120 return lh.real() < rh.real();
121 return lh.imag() < rh.imag();
122 }
123
124 };
125}
126
127
128#endif // CVectorfit_h__
Vector fitting of a rational transfer function to frequency data.
Definition Vectorfit.h:26
int Fitoption() const
The terms of the fit: 1 fits with D = 0 and E = 0, 2 fits with D free and E = 0 (default),...
Definition Vectorfit.h:32
bool RelaxedConstraint() const
Use the relaxed non-triviality constraint in the pole identification. Default false.
Definition Vectorfit.h:36
void Fit(const vec_complex &f, const vec_complex &s, vec_complex &poles, const vec &weight)
One iteration of vector fitting.
bool FlipUnstable() const
Mirror poles with a positive real part to the left half plane. Default true.
Definition Vectorfit.h:39
bool PoleIdentification() const
Do the pole identification. When false, that part of Fit() is skipped and the returned C,...
Definition Vectorfit.h:42
double Rmserr() const
Root mean square of Diff().
Definition Vectorfit.h:74
mat_complex Diff() const
Fit minus data at the points of the last Fit() (when the poles were identified).
Definition Vectorfit.h:72
bool ComplexStateSpace() const
Stored as an option; Fit() does not read it.
Definition Vectorfit.h:48
VectorFit()
Sets the defaults: Fitoption 2, RelaxedConstraint false, FlipUnstable true, PoleIdentification true,...
bool ResidueIdentification() const
Do the residue identification (C, D and E). When false, only the poles are identified....
Definition Vectorfit.h:45
Simple waypoint object.
Definition CableAttach.h:58