@@ -168,11 +168,11 @@ bool continuousSystem::setup( real_t *num,
168168{
169169 bool retValue = false ;
170170
171- if ( ( nullptr != num ) && ( nullptr != den ) && ( nullptr != x ) ) {
171+ if ( ( nullptr != num ) && ( nullptr != den ) && ( nullptr != x ) && ( nD >= 1U ) ) {
172172 b = &num[ 1 ];
173173 n = nD;
174174 nb = n;
175- na = nD + 1 ;
175+ na = nD + 1U ;
176176 xc = x;
177177 dt = dT;
178178 a = &den[ 1 ];
@@ -206,6 +206,7 @@ bool continuousSystem::setInitStates( const real_t *xi )
206206 return retValue;
207207}
208208/* ============================================================================*/
209+ #if defined( LTISYS_EVAL_MODEL_CONTROLLABLE )
209210real_t continuousSystem::update ( const real_t u )
210211{
211212 real_t y = 0 .0_re;
@@ -214,7 +215,6 @@ real_t continuousSystem::update( const real_t u )
214215 if ( 1U == n ) {
215216 dx0 = ( u - ( xc[ 0 ]*a[ 0 ] ) );
216217 (void )xc[ 0 ].integrate ( dx0, dt );
217- y = ( b[ 0 ] - ( a[ 0 ]*b0 ) )*xc[ 0 ];
218218 }
219219 else {
220220 /* compute states of the system by using the controllable canonical form*/
@@ -229,11 +229,42 @@ real_t continuousSystem::update( const real_t u )
229229 dx0 = u - ( dx0 + ( a[ 0 ]*xc[ 0 ] ) );
230230 (void )xc[ 0 ].integrate ( dx0, dt ); /* integrate to get the first state*/
231231 /* compute the remaining part of the output*/
232- y += ( b[ 0 ] - ( a[ 0 ]*b0 ) )*xc[ 0 ];
233232 }
233+ /* get the output of the system*/
234+ y += ( b[ 0 ] - ( a[ 0 ]*b0 ) )*xc[ 0 ];
234235
235236 return y;
236237}
238+ #elif defined( LTISYS_EVAL_MODEL_OBSERVABLE )
239+ /* ============================================================================*/
240+ real_t continuousSystem::update ( const real_t u )
241+ {
242+ real_t y = 0 .0_re;
243+ const real_t x0 = xc[ 0 ](); /* save first state for computation*/
244+ const size_t N = n - 1U ;
245+ /* compute the last derivative dx_{n}*/
246+ const real_t dxn = ( -a[ N ]*x0 ) + ( ( b[ N ] - a[ N ]*b0 )*u );
247+
248+ if ( 1U == n ) {
249+ xc[ 0 ].integrate ( dxn, dt );
250+ }
251+ else {
252+ /* compute states of the system by using the observable canonical form*/
253+ for ( size_t i = 0U ; i < N ; ++i ) {
254+ const real_t dxi = ( -a[ i ]*x0 ) + xc[ i + 1U ] + ( ( b[ i ] - a[ i ]*b0 )*u );
255+ (void )xc[ i ].integrate ( dxi , dt );
256+ }
257+ /* integrate the remaining last state*/
258+ (void )xc[ N ].integrate ( dxn, dt );
259+ }
260+ /* get the output of the system*/
261+ y = xc[ 0 ] + ( b0*u );
262+
263+ return y;
264+ }
265+ #else
266+ #error "LTISYS evaluation mode not defined"
267+ #endif
237268/* ============================================================================*/
238269bool continuousSystem::setIntegrationMethod ( integrationMethod m )
239270{
0 commit comments