| 1 | <style type='text/css'> |
| 2 | /*/*/ /*<![CDATA[*/ |
| 3 | @import "style.css"; |
| 4 | /*]]>*/ /* */ |
| 5 | </style> |
| 6 | |
| 7 | <h3>CONVENIENCE</h3> |
| 8 | |
| 9 | <p>The Convenience folder contains a number of convenience functions for checking information or manipulating math expressions.</p> |
| 10 | |
| 11 | <p>Function are:</p> |
| 12 | |
| 13 | <hr> |
| 14 | |
| 15 | <h4>y = CheckValidUnitKind(kind)</h4> |
| 16 | |
| 17 | <p>Takes</p> |
| 18 | |
| 19 | <ol> |
| 20 | <li>kind, a string representing a unit kind </li> |
| 21 | </ol> |
| 22 | |
| 23 | <p>Returns </p> |
| 24 | |
| 25 | <ol> |
| 26 | <li>y = |
| 27 | <ul> |
| 28 | <li>1 if the string represents a valid unit kind </li> |
| 29 | <li>0 otherwise</li> |
| 30 | </ul></li> |
| 31 | </ol> |
| 32 | |
| 33 | <p><em>NOTE:</em> This is identical to the function isValidUnitKind</p> |
| 34 | |
| 35 | <hr> |
| 36 | |
| 37 | <h4>newArray = LoseWhiteSpace(charArray)</h4> |
| 38 | |
| 39 | <p>Takes</p> |
| 40 | |
| 41 | <ol> |
| 42 | <li>charArray, an array of characters </li> |
| 43 | </ol> |
| 44 | |
| 45 | <p>Returns </p> |
| 46 | |
| 47 | <ol> |
| 48 | <li>the array with any white space removed</li> |
| 49 | </ol> |
| 50 | |
| 51 | <p><em>EXAMPLE:</em></p> |
| 52 | |
| 53 | <pre><code> newArray = LoseWhiteSpace(' exa mp le') |
| 54 | |
| 55 | newArray = 'example' |
| 56 | </code></pre> |
| 57 | |
| 58 | <hr> |
| 59 | |
| 60 | <h4>pairs = PairBrackets(expression)</h4> |
| 61 | |
| 62 | <p>Takes</p> |
| 63 | |
| 64 | <ol> |
| 65 | <li>expression, a string representation of a math expression</li> |
| 66 | </ol> |
| 67 | |
| 68 | <p>Returns</p> |
| 69 | |
| 70 | <ol> |
| 71 | <li>an array of the indices of each pair of brackets ordered from |
| 72 | the opening bracket index</li> |
| 73 | </ol> |
| 74 | |
| 75 | <p><em>EXAMPLE:</em></p> |
| 76 | |
| 77 | <pre><code> pairs = PairBrackets('(a+((b*c)/(a+b)))') |
| 78 | |
| 79 | pairs = |
| 80 | 1 17 |
| 81 | 4 16 |
| 82 | 5 9 |
| 83 | 11 15 |
| 84 | </code></pre> |
| 85 | |
| 86 | <hr> |
| 87 | |
| 88 | <h4>output = Rearrange(expression, name)</h4> |
| 89 | |
| 90 | <p>Takes</p> |
| 91 | |
| 92 | <ol> |
| 93 | <li>expression, a string representation of a math expression</li> |
| 94 | <li>name, a string representing the name of a variable</li> |
| 95 | </ol> |
| 96 | |
| 97 | <p>Returns</p> |
| 98 | |
| 99 | <ol> |
| 100 | <li>the expression rearranged in terms of the variable</li> |
| 101 | </ol> |
| 102 | |
| 103 | <p><em>EXAMPLE:</em></p> |
| 104 | |
| 105 | <pre><code> output = Rearrange('X + Y - Z', 'X') |
| 106 | |
| 107 | output = '-Y+Z' |
| 108 | </code></pre> |
| 109 | |
| 110 | <hr> |
| 111 | |
| 112 | <h4>newArray = RemoveDuplicates(array)</h4> |
| 113 | |
| 114 | <p>Takes</p> |
| 115 | |
| 116 | <ol> |
| 117 | <li>array, any array</li> |
| 118 | </ol> |
| 119 | |
| 120 | <p>Returns</p> |
| 121 | |
| 122 | <ol> |
| 123 | <li>the array with any duplicate entries removed </li> |
| 124 | </ol> |
| 125 | |
| 126 | <p><em>EXAMPLE:</em></p> |
| 127 | |
| 128 | <pre><code> newArray = RemoveDuplicates([2, 3, 4, 3, 2, 5]) |
| 129 | newArray = [2, 3, 4, 5] |
| 130 | </code></pre> |
| 131 | |
| 132 | <hr> |
| 133 | |
| 134 | <h4>value = Substitute(expression, SBMLModel)</h4> |
| 135 | |
| 136 | <p>Takes</p> |
| 137 | |
| 138 | <ol> |
| 139 | <li>expression, a string representation of a math expression</li> |
| 140 | <li>SBMLModel, an SBML Model structure</li> |
| 141 | </ol> |
| 142 | |
| 143 | <p>Returns</p> |
| 144 | |
| 145 | <ol> |
| 146 | <li>the value of the expression when all variables within the model have |
| 147 | been substituted</li> |
| 148 | </ol> |
| 149 | |
| 150 | <p><em>EXAMPLE:</em></p> |
| 151 | |
| 152 | <pre><code> Consider m to be an SBMLModel containing a species with |
| 153 | id = 'g' and initialConcentration = '3' |
| 154 | |
| 155 | value = Substitute('g*2', m) |
| 156 | |
| 157 | value = 6 |
| 158 | </code></pre> |
| 159 | |
| 160 | <hr> |
| 161 | |
| 162 | <h4>newExpression = SubstituteConstants(expression, SBMLModel)</h4> |
| 163 | |
| 164 | <p>Takes</p> |
| 165 | |
| 166 | <ol> |
| 167 | <li>expression, a string representation of a math expression</li> |
| 168 | <li>SBMLModel, an SBML Model structure</li> |
| 169 | </ol> |
| 170 | |
| 171 | <p>Returns</p> |
| 172 | |
| 173 | <ol> |
| 174 | <li>the string representation of the expression when all constants within the |
| 175 | model have been substituted</li> |
| 176 | </ol> |
| 177 | |
| 178 | <p><em>EXAMPLE:</em></p> |
| 179 | |
| 180 | <pre><code> Consider m to be an SBMLModel containing a parameter |
| 181 | with id = 'g', constant = '1' and value = 3' |
| 182 | |
| 183 | newExpression = SubstituteConstants('2 * g * S1', SBMLModel) |
| 184 | |
| 185 | newExpression = '2 * 3 * S1' |
| 186 | </code></pre> |
| 187 | |
| 188 | <hr> |
| 189 | |
| 190 | <h4>newExpression = SubstituteFunction(expression, SBMLFunctionDefinition)</h4> |
| 191 | |
| 192 | <p>Takes</p> |
| 193 | |
| 194 | <ol> |
| 195 | <li>expression, a string representation of a math expression</li> |
| 196 | <li>SBMLFunctionDefinition, an SBML FunctionDefinition structure</li> |
| 197 | </ol> |
| 198 | |
| 199 | <p>Returns</p> |
| 200 | |
| 201 | <ol> |
| 202 | <li>newExpression |
| 203 | <ul> |
| 204 | <li>the string representation of the expression when any instances of the |
| 205 | functionDefinition have been substituted</li> |
| 206 | <li>an empty string if the functiondefinition is not in the original |
| 207 | expression</li> |
| 208 | </ul></li> |
| 209 | </ol> |
| 210 | |
| 211 | <p><em>EXAMPLE:</em></p> |
| 212 | |
| 213 | <pre><code> Consider fD to be an SBMLFunctionDefinition |
| 214 | with id = 'g' and math = 'lambda(x,x+0.5)' |
| 215 | |
| 216 | formula = SubstituteFormula('g(y)', fD) |
| 217 | |
| 218 | formula = 'y+0.5' |
| 219 | |
| 220 | |
| 221 | formula = SubstituteFormula('h(y)', fD) |
| 222 | |
| 223 | formula = '' |
| 224 | </code></pre> |
| 225 | |
| 226 | <hr> |
| 227 | |
| 228 | <h4>y = isIntegralNumber(number)</h4> |
| 229 | |
| 230 | <p>Takes</p> |
| 231 | |
| 232 | <ol> |
| 233 | <li>number, any number</li> |
| 234 | </ol> |
| 235 | |
| 236 | <p>Returns</p> |
| 237 | |
| 238 | <ol> |
| 239 | <li>y = </li> |
| 240 | <li>1 if the number represents an integer </li> |
| 241 | <li>0 otherwise </li> |
| 242 | </ol> |
| 243 | |
| 244 | <p><em>EXAMPLE:</em></p> |
| 245 | |
| 246 | <pre><code> y = isIntegralNumber(int32(3)) |
| 247 | y = 1 |
| 248 | |
| 249 | y = isIntegralNumber(double(3.2)) |
| 250 | y = 0 |
| 251 | |
| 252 | y = isIntegralNumber(double(3)) |
| 253 | y = 1 |
| 254 | </code></pre> |
| 255 | |
| 256 | <p><em>NOTE:</em> The inbuilt 'isinteger' function only returns true if the number |
| 257 | has been declared as having an integer type, whereas the default type for numbers |
| 258 | in MATLAB is double. This function will return '1' if the number |
| 259 | represents an integer.</p> |
| 260 | |
| 261 | <hr> |
| 262 | |
| 263 | <h4>y = isValidUnitKind(kind)</h4> |
| 264 | |
| 265 | <p>Takes</p> |
| 266 | |
| 267 | <ol> |
| 268 | <li>kind, a string representing a unit kind </li> |
| 269 | </ol> |
| 270 | |
| 271 | <p>returns </p> |
| 272 | |
| 273 | <ol> |
| 274 | <li>y = |
| 275 | <ul> |
| 276 | <li>1 if the string represents a valid unit kind </li> |
| 277 | <li>0 otherwise</li> |
| 278 | </ul></li> |
| 279 | </ol> |
| 280 | |
| 281 | <p><em>NOTE:</em> This is identical to the function CheckValidUnitKind</p> |
| 282 | |
| 283 | <hr> |
| 284 | |
| 285 | <h4>index = matchFunctionName(expression, name)</h4> |
| 286 | |
| 287 | <p>Takes</p> |
| 288 | |
| 289 | <ol> |
| 290 | <li>expression, a string representation of a math expression</li> |
| 291 | <li>name, a string representing the name of a function</li> |
| 292 | </ol> |
| 293 | |
| 294 | <p>Returns</p> |
| 295 | |
| 296 | <ol> |
| 297 | <li>the index of the starting point of 'name' in the 'expression'</li> |
| 298 | </ol> |
| 299 | |
| 300 | <p><em>EXAMPLE:</em></p> |
| 301 | |
| 302 | <pre><code> index = matchFunctionName('f*g', 'g') |
| 303 | |
| 304 | index = [] |
| 305 | |
| 306 | |
| 307 | index = matchFunctionName('add(d,g_1)', 'add') |
| 308 | |
| 309 | index = 0 |
| 310 | |
| 311 | |
| 312 | index = matchFunctionName('add(add(a,b), c)', 'add') |
| 313 | |
| 314 | index = [1, 5] |
| 315 | </code></pre> |
| 316 | |
| 317 | <p><em>NOTE:</em> This differs from the 'strfind' function in that it checks |
| 318 | that the name is used as a function call.</p> |
| 319 | |
| 320 | <hr> |
| 321 | |
| 322 | <h4>index = matchName(expression, name)</h4> |
| 323 | |
| 324 | <p>Takes</p> |
| 325 | |
| 326 | <ol> |
| 327 | <li>expression, a string representation of a math expression</li> |
| 328 | <li>name, a string representing the name of a variable</li> |
| 329 | </ol> |
| 330 | |
| 331 | <p>Returns</p> |
| 332 | |
| 333 | <ol> |
| 334 | <li>the index of the starting point of 'name' in the 'expression'</li> |
| 335 | </ol> |
| 336 | |
| 337 | <p><em>EXAMPLE:</em></p> |
| 338 | |
| 339 | <pre><code> index = matchName('f*g', 'g') |
| 340 | |
| 341 | index = 3 |
| 342 | |
| 343 | |
| 344 | index = matchName('f*g_1', 'g') |
| 345 | |
| 346 | index = [] |
| 347 | |
| 348 | |
| 349 | index = matchName('f*g(a,g)', 'g') |
| 350 | |
| 351 | index = 7 |
| 352 | </code></pre> |
| 353 | |
| 354 | <p><em>NOTE:</em> This differs from the 'strfind' function in that it checks |
| 355 | that the name is used as a variable.</p> |
| 356 | |
| 357 | <hr> |
| 358 | |
| 359 | <h4>value = piecewise(value1, test, value2)</h4> |
| 360 | |
| 361 | <p>Takes</p> |
| 362 | |
| 363 | <ol> |
| 364 | <li>value1, the value to return if the test is true</li> |
| 365 | <li>test, a boolean test that will return true or false</li> |
| 366 | <li>value2, the value to return if the test is false</li> |
| 367 | </ol> |
| 368 | |
| 369 | <p>Returns</p> |
| 370 | |
| 371 | <ol> |
| 372 | <li>value = |
| 373 | <ul> |
| 374 | <li>value1, if test returns true</li> |
| 375 | <li>value2, if test returns false</li> |
| 376 | </ul></li> |
| 377 | </ol> |
| 378 | |
| 379 | <p><em>EXAMPLE:</em></p> |
| 380 | |
| 381 | <pre><code> value = piecewise(3, 1<2, 4) |
| 382 | value = 3 |
| 383 | |
| 384 | value = piecewise(3, 1>2, 4) |
| 385 | value = 4 |
| 386 | </code></pre> |
| 387 | |
| 388 | <p><em>NOTE:</em> This function provides the functionality of the MathML 'piecewise' function.</p> |
| 389 | |
| 390 | <hr> |
| 391 | |
| 392 | <h4>y = testmember(value, array)</h4> |
| 393 | |
| 394 | <p>Takes</p> |
| 395 | |
| 396 | <ol> |
| 397 | <li>value, any number/string</li> |
| 398 | <li>array, an array of objects </li> |
| 399 | </ol> |
| 400 | |
| 401 | <p>Returns </p> |
| 402 | |
| 403 | <ol> |
| 404 | <li>y = |
| 405 | <ul> |
| 406 | <li>1 if value is a member of the array </li> |
| 407 | <li>0 otherwise</li> |
| 408 | </ul></li> |
| 409 | </ol> |
| 410 | |
| 411 | <p><em>NOTE:</em> this function is necessary for octave to emulate the MATLAB |
| 412 | functionality of the 'ismember' function</p> |
| 413 | |
| 414 | <hr> |