diff options
author | Sandeep Gupta | 2017-07-05 12:41:25 +0530 |
---|---|---|
committer | Sandeep Gupta | 2017-07-05 12:41:25 +0530 |
commit | dd50e95a8193fb0faa846ccaa971a115ba69e71c (patch) | |
tree | 8d66abedd68dc5255ad323b95a16c9b592657f35 /2.3-1/src/c/CACSD/lqr/dlqra.c | |
parent | 3308ea7a973e2c1e1c8bea99ac7cc783ce8e8b06 (diff) | |
download | Scilab2C-dd50e95a8193fb0faa846ccaa971a115ba69e71c.tar.gz Scilab2C-dd50e95a8193fb0faa846ccaa971a115ba69e71c.tar.bz2 Scilab2C-dd50e95a8193fb0faa846ccaa971a115ba69e71c.zip |
LinearAlgebra and MatrixOperation Update
Diffstat (limited to '2.3-1/src/c/CACSD/lqr/dlqra.c')
-rw-r--r-- | 2.3-1/src/c/CACSD/lqr/dlqra.c | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/2.3-1/src/c/CACSD/lqr/dlqra.c b/2.3-1/src/c/CACSD/lqr/dlqra.c index 1440c3a8..02ac1504 100644 --- a/2.3-1/src/c/CACSD/lqr/dlqra.c +++ b/2.3-1/src/c/CACSD/lqr/dlqra.c @@ -22,8 +22,7 @@ #include "schur.h" #include "matrixDivision.h" -void dlqra(double* sys, int sys_rows, int sys_cols, double* Q, double* R, \ - double* S, double* K, double* X) +void dlqra(double* sys, int sys_rows, int sys_cols, double* X, double* K) { int no_of_states, no_of_inputs, no_of_outputs, dom = 1; int row,col; @@ -33,7 +32,7 @@ void dlqra(double* sys, int sys_rows, int sys_cols, double* Q, double* R, \ double *A, *B, *C, *D; double *B_t, *C_t, *D_t; - //double *Q, *R, *S; + double *Q, *R, *S; double *Ri, *LA, *LE; double *BRi, *StRi, *S_t; double *buf1, *buf2, *buf3, *buf4, *buf5, *buf6; @@ -91,29 +90,20 @@ void dlqra(double* sys, int sys_rows, int sys_cols, double* Q, double* R, \ dom = (int)sys[(sys_rows*(sys_cols-2)) + no_of_states]; + Q = (double*) malloc (no_of_states*no_of_states*sizeof(double)); + R = (double*) malloc (no_of_inputs*no_of_inputs*sizeof(double)); + S = (double*) malloc (no_of_inputs*no_of_states*sizeof(double)); + dtransposea(B,no_of_states,no_of_inputs,B_t); dtransposea(C,no_of_outputs,no_of_states,C_t); dtransposea(D,no_of_outputs,no_of_inputs,D_t); - if(Q == NULL) - {/*If Q is not provided*/ - Q = (double*) malloc (no_of_states*no_of_states*sizeof(double)); - dmulma(C_t,no_of_states,no_of_outputs,C,no_of_outputs,no_of_states,Q); - } - - if(R == NULL) - {/*If R is not provided*/ - R = (double*) malloc (no_of_inputs*no_of_inputs*sizeof(double)); - dmulma(D_t,no_of_inputs,no_of_outputs,D,no_of_outputs,no_of_inputs,R); - } - - if(S == NULL) - {/*If Q is not provided*/ - S = (double*) malloc (no_of_inputs*no_of_states*sizeof(double)); - dmulma(D_t,no_of_inputs,no_of_outputs,C,no_of_outputs,no_of_states,S); - } + dmulma(C_t,no_of_states,no_of_outputs,C,no_of_outputs,no_of_states,Q); + dmulma(D_t,no_of_inputs,no_of_outputs,D,no_of_outputs,no_of_inputs,R); + dmulma(D_t,no_of_inputs,no_of_outputs,C,no_of_outputs,no_of_states,S); /*Free up unwanted variables*/ + free(C); free(C_t); free(D); @@ -187,8 +177,8 @@ void dlqra(double* sys, int sys_rows, int sys_cols, double* Q, double* R, \ /*Freeup umwanted variables*/ free(A); - //free(Q); - //free(R); + free(Q); + free(R); free(BRi); free(S_t); free(StRi); @@ -288,7 +278,7 @@ void dlqra(double* sys, int sys_rows, int sys_cols, double* Q, double* R, \ } - //free(Q); + free(Q); free(BRi); free(S_t); free(StRi); @@ -326,7 +316,7 @@ void dlqra(double* sys, int sys_rows, int sys_cols, double* Q, double* R, \ /*inv(B'XB+R)*/ dmulma(B_t,no_of_inputs,no_of_states,X,no_of_states,no_of_states,buf3); - dmulma(buf3,no_of_inputs,no_of_states,B,no_of_states,no_of_inputs,buf6); + dmulma(buf3,no_of_inputs,no_of_states,B_t,no_of_states,no_of_inputs,buf6); dadda(buf6,no_of_inputs*no_of_inputs,R,no_of_inputs*no_of_inputs,buf5); dinverma(buf5,buf6,no_of_inputs); /*B'XA+S*/ @@ -343,14 +333,14 @@ void dlqra(double* sys, int sys_rows, int sys_cols, double* Q, double* R, \ free(A); free(B); - //free(R); + free(R); free(buf5); free(buf6); } free(B_t); - //free(S); + free(S); free(wsmall); free(X12); free(phi12); |