|
12 | 12 | end
|
13 | 13 | cb = [];
|
14 | 14 |
|
| 15 | +%See if we can use [] in symbolic var names |
| 16 | +sqOK = true; |
| 17 | +try |
| 18 | + if (exist('str2sym','file') == 2) |
| 19 | + str2sym('x[1]'); |
| 20 | + else |
| 21 | + sym('x[1]'); |
| 22 | + end |
| 23 | +catch |
| 24 | + sqOK = false; |
| 25 | +end |
| 26 | + |
15 | 27 | %Determine callback type
|
16 | 28 | switch(mode)
|
17 | 29 | case 'new'
|
|
98 | 110 | %Need to rename all variables to x[0]...x[n]
|
99 | 111 | xvar = cell(length(svar),1);
|
100 | 112 | for i = 1:length(xvar)
|
101 |
| - xvar{i} = sprintf('x[%d]',i); |
| 113 | + if (sqOK) |
| 114 | + xvar{i} = sprintf('x[%d]',i); |
| 115 | + else |
| 116 | + xvar{i} = sprintf('x[%d]',i-1); |
| 117 | + end |
102 | 118 | end
|
103 | 119 | %Ensure both columns
|
104 | 120 | if(size(svar,1) > 1), svar = svar.'; end
|
105 | 121 | if(size(xvar,1) > 1), xvar = xvar'; end
|
106 | 122 | %Subs out individual symbolic variables into our indexed list and converts to normal numbers
|
107 |
| - wstate = warning('off','symbolic:sym:sym:DeprecateExpressions'); |
108 |
| - eq = vpa(subs(sobj,svar,xvar),16); %this takes too long - any suggestions? |
109 |
| - warning(wstate); |
| 123 | + if (sqOK) |
| 124 | + eq = vpa(SymBuilder.symsubs(sobj,svar,xvar),16); %this takes too long - any suggestions? |
| 125 | + else |
| 126 | + eq = vpa(sobj, 16); |
| 127 | + end |
| 128 | + |
| 129 | + % If we can't sub in c style indexed vars, explicit definition here |
| 130 | + if (~sqOK) |
| 131 | + fprintf(fp,' // Allocate C vars to Symbolic named vars\n'); |
| 132 | + for i = 1:length(svar) |
| 133 | + t = 'double'; |
| 134 | + if(cmode=='A') |
| 135 | + t = 'Type'; |
| 136 | + end |
| 137 | + fprintf(fp,' const %s %s = %s;\n',t,char(svar(i)),xvar{i}); |
| 138 | + end |
| 139 | + % Do the same if Hessian |
| 140 | + if (var=='H') |
| 141 | + for i = 1:ncon |
| 142 | + fprintf(fp,' const double lambda%d = lambda[%d];\n',i, i-1); |
| 143 | + end |
| 144 | + end |
| 145 | + fprintf(fp, '\n'); |
| 146 | + end |
| 147 | + |
110 | 148 | %Sub out Lambda if Hessian
|
111 | 149 | if(var=='H')
|
112 | 150 | l = cell(ncon,1);
|
113 | 151 | l2 = cell(ncon,1);
|
114 | 152 | for i = 1:ncon
|
115 | 153 | l{i} = sprintf('lambda(%d)',i);
|
116 |
| - l2{i} = sprintf('lambda[%d]',i); |
| 154 | + if (sqOK) |
| 155 | + l2{i} = sprintf('lambda[%d]',i); |
| 156 | + else |
| 157 | + l2{i} = sprintf('lambda%d',i); |
| 158 | + end |
117 | 159 | end
|
118 |
| - wstate = warning('off','symbolic:sym:sym:DeprecateExpressions'); |
119 |
| - eq = subs(eq,l,l2); |
120 |
| - warning(wstate); |
| 160 | + eq = SymBuilder.symsubs(eq,l,l2); |
121 | 161 | end
|
122 | 162 |
|
123 | 163 | %Enter Equations (Var Type Dictates Entry Type)
|
|
0 commit comments