From: Rainer M. <ra...@tb...> - 2006-06-16 15:09:41
|
hi just for the record, and if someone is interested: i have just commited a new processAST.c file a) repaired and generalized piecewise evaluation: a1) piecewise for the simple piece/otherwise case was implemented wrong a2) a general solution for multiple pieces w or w/o otherwise statements I have added the new code for piecewise evaluation below, in case someone finds the time to check this. b) repaired differentiation of abs function: f(x) = abs(a(x)) df/dx = sig(a(x)) * da/dx we have decided to set sig(a(x)) to 0 if a(x) = 0, i.e. sig(0) = 0, even though the signum function is actually not defined at 0. Alternatively we could either set sig(0) to +1 or forget about differentiation of abs and use CVODE's internal approximation instead. Any opinions? Rainer case AST_FUNCTION_PIECEWISE: /** Piecewise: */ found = 0; /** Go through n pieces with 2 AST children for each piece, */ for ( i=0; i<(childnum-1); i=i+2 ) { if ( evaluateAST(child(n, i+1), data) ) { found++; result = evaluateAST(child(n, i), data); } } /** odd number of AST children: if no piece was true, otherwise remains */ /* i should be equal to childnum for even number piecewise AST and equal to childnum-1 for odd numbered piecewise ASTs */ if ( i == childnum-1 && found == 0 ) { found++; result = evaluateAST(child(n, i), data); } if ( found == 0 ) SolverError_error(ERROR_ERROR_TYPE, SOLVER_ERROR_AST_EVALUATION_FAILED_PIECEWISE, "Piecewise function failed; no true piece"); if ( found > 1 ) SolverError_error(ERROR_ERROR_TYPE, SOLVER_ERROR_AST_EVALUATION_FAILED_PIECEWISE, "Piecewise function failed; several true pieces"); break; |