diff options
author | siddhu8990 | 2017-02-07 16:16:31 +0530 |
---|---|---|
committer | siddhu8990 | 2017-02-07 16:16:31 +0530 |
commit | e59107e6bb2695fc20fd0ab229e296b9bf739fc4 (patch) | |
tree | 5bedc90e7bc88bb86b10a33839887eeb3e2f39cf /2.3-1/src/c/CACSD/syslin | |
parent | 1fef9b1edc2d4400e8ba6bb6fafb648963d6817d (diff) | |
download | Scilab2C-e59107e6bb2695fc20fd0ab229e296b9bf739fc4.tar.gz Scilab2C-e59107e6bb2695fc20fd0ab229e296b9bf739fc4.tar.bz2 Scilab2C-e59107e6bb2695fc20fd0ab229e296b9bf739fc4.zip |
Support for 'lqr' and 'lqe' added
Diffstat (limited to '2.3-1/src/c/CACSD/syslin')
-rw-r--r-- | 2.3-1/src/c/CACSD/syslin/dsyslina.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/2.3-1/src/c/CACSD/syslin/dsyslina.c b/2.3-1/src/c/CACSD/syslin/dsyslina.c index cd7fa6bc..3c20c65c 100644 --- a/2.3-1/src/c/CACSD/syslin/dsyslina.c +++ b/2.3-1/src/c/CACSD/syslin/dsyslina.c @@ -11,62 +11,70 @@ */ /*Function for declaring state space system*/ +/*output structure is as follows : + | A B X0 | + | C D dom| + where dom is 1 for 'c' and 2 for 'd' + Another column is appended with no_of_states and no_inputs as its elements */ + + #include <stdlib.h> -void dsyslina(double* A, int no_of_states, double* B, int no_of_inputs, \ +void dsyslina(char* dom, double* A, int no_of_states, double* B, int no_of_inputs, \ double* C, int no_of_outputs, double* D, double* X0, double* out) { int row = 0,col = 0; - int no_of_cols = no_of_states + no_of_inputs + 1; - + int no_of_cols = no_of_states + no_of_inputs + 2; + int no_of_rows = no_of_states + no_of_outputs; /*Copy matrix A into out matrix*/ - for(row = 0; row < no_of_states; row++) + for(col = 0; col < no_of_states; col++) { - for(col = 0; col < no_of_states; col++) + for(row = 0; row < no_of_states; row++) { - out[row*no_of_cols + col] = A[row*no_of_states + col]; + out[col*no_of_rows + row] = A[col*no_of_states + row]; } } /*Copy matrix B in out matrix*/ - for(row = 0; row < no_of_states; row++) + for(col=0; col < no_of_inputs; col++) { - for(col=0; col < no_of_inputs; col++) + for(row = 0; row < no_of_states; row++) { - out[row * no_of_cols + no_of_states + col] = B[row * no_of_inputs + col]; + out[col * no_of_rows + no_of_states*no_of_rows + row] \ + = B[col * no_of_states + row]; } } /*Copy matrix C in out matrix*/ - for(row = 0; row < no_of_outputs; row++) + for(col=0; col < no_of_states; col++) { - for(col=0; col < no_of_states; col++) + for(row = 0; row < no_of_outputs; row++) { - out[(no_of_states + row)*no_of_cols + col] = C[row * no_of_states + col]; + out[no_of_states + (col*no_of_rows) + row] = C[col * no_of_outputs + row]; } } /*Copy matrix D in out matrix*/ if( D != NULL) { - for(row = 0; row < no_of_outputs; row++) + for(col=0; col < no_of_inputs; col++) { - for(col=0; col < no_of_inputs; col++) + for(row = 0; row < no_of_outputs; row++) { - out[(no_of_states+row)*no_of_cols + no_of_states+col] = \ - D[row * no_of_inputs + col]; + out[(no_of_states+col)*no_of_rows + no_of_states + row] = \ + D[col * no_of_outputs + row]; } } } else { - for(row = 0; row < no_of_outputs; row++) + for(col=0; col < no_of_inputs; col++) { - for(col=0; col < no_of_inputs; col++) + for(row = 0; row < no_of_outputs; row++) { - out[(no_of_states+row)*no_of_cols + no_of_states+col] = 0; + out[(no_of_states+col)*no_of_rows + no_of_states + row] = 0; } } } @@ -76,19 +84,24 @@ void dsyslina(double* A, int no_of_states, double* B, int no_of_inputs, \ { for(row = 0; row < no_of_states; row++) { - out[(row+1)*(no_of_cols) - 1] = X0[row]; - + out[(no_of_rows*(no_of_cols-1))+row] = X0[row]; } } else { for(row = 0; row < no_of_states; row++) { - out[(row+1)*(no_of_cols) - 1] = 0; - + out[(no_of_rows*(no_of_cols-1))+row] = 0; } } + if(*dom == 'c') + out[(no_of_rows*(no_of_cols-2)) + no_of_states] = 1; + else if(*dom == 'd') + out[(no_of_rows*(no_of_cols-2)) + no_of_states] = 2; + /*Insert no of states and inputs in last column*/ + out[(no_of_rows*(no_of_cols-1))] = no_of_states; + out[(no_of_rows*(no_of_cols-1))+1] = no_of_inputs; }
\ No newline at end of file |