-e^(-5x)/5+k,最前的負號在方程式解析中不處理,解析程式 parser.php 比較複雜。直接改 question.php 的方程式解析函數 parse_expression,在解析前判斷如果方程式有負的變數開頭的方程式,就在最前面加上 0。
[root@dywang algebra]# diff -uN ../../../mod_tmp/algebra/question.php question.php
--- ../../../mod_tmp/algebra/question.php 2013-05-20 16:23:42.000000000 +0800
+++ question.php 2015-01-12 15:07:00.718534515 +0800
@@ -87,6 +87,7 @@
* @return top term of the parse tree or a string if an exception is thrown
*/
public function parse_expression($expr) {
+ $expr=preg_replace('/^(\-[a-zA-Z])/i','0$1',$expr);
// Check to see if this is already a parsed expression.
if (is_a($expr, 'qtype_algebra_parser_term')) {
// It is a parsed expression so simply return it.