Use square brackets for parenthesis in newton
This commit is contained in:
parent
35df61633c
commit
be3f334856
|
@ -80,14 +80,15 @@ getConfiguredClient()
|
|||
validateExpression()
|
||||
{
|
||||
local parsedExpression
|
||||
parsedExpression=$(echo $1 | grep -Eo "[0-9 + -- / * ^ . a-z A-Z ~ :]*")
|
||||
if [[ "$parsedExpression" != "$1" ]];then { echo "Error: Expression contains invalid characters"; return 1; }; fi
|
||||
originalExpression=$(echo $1 | sed "s/\[/\(/g" | sed "s/\]/\)/g")
|
||||
parsedExpression=$(echo $1 | sed "s/\[/\(/g" | sed "s/\]/\)/g" | grep -Eo "[0-9 + -- / * ^ . a-z A-Z ~ : ( ) ]*")
|
||||
if [[ "$parsedExpression" != "$originalExpression" ]];then { echo "Error: Expression contains invalid characters"; return 1; }; fi
|
||||
}
|
||||
|
||||
encodeEquation()
|
||||
{
|
||||
originalEquation=$1
|
||||
equation=$(echo $originalEquation | sed "s:/:(over):g" | sed "s/~/|/g" | sed "s/-/%2D/g")
|
||||
equation=$(echo $originalEquation | sed "s:\[:\(:g" | sed "s:\]:\):g" | sed "s:/:(over):g" | sed "s/~/|/g" | sed "s/-/%2D/g")
|
||||
}
|
||||
|
||||
validateOperation()
|
||||
|
@ -112,7 +113,7 @@ printAnswer()
|
|||
cat <<EOF
|
||||
================================
|
||||
|Operation: $operation
|
||||
|Expression: $originalEquation
|
||||
|Expression: $originalExpression
|
||||
|Result: $result
|
||||
================================
|
||||
EOF
|
||||
|
@ -130,7 +131,7 @@ Usage: newton [operation] [expression] or newton [flag]
|
|||
===================================================
|
||||
|Operations Sample Expression Sample Result|
|
||||
|---------------------------------------------------|
|
||||
|Simplify 2^2+2(2) 8 |
|
||||
|Simplify [[2x^2]+7]*[4x^2] 8 x^4 + 28 x^2 |
|
||||
|Factor x^2 + 2x x (x + 2) |
|
||||
|Derive x^2+2x 2 x + 2 |
|
||||
|Integrate x^2+2x 1/3 x^3 + x^2 +C|
|
||||
|
@ -146,6 +147,16 @@ Usage: newton [operation] [expression] or newton [flag]
|
|||
|Abs -2 2 |
|
||||
|Log 2~8 3 | (Log base 2 of eight)
|
||||
===================================================
|
||||
Valid Symbols:
|
||||
+ add
|
||||
- subtract
|
||||
[ left parenthesis (you must use brackets bash has a bultin for parenthesis)
|
||||
] right parenthesis (you must use brackets bash has a bultin for parenthesis)
|
||||
* multiply
|
||||
/ divide
|
||||
^ power
|
||||
: between the range of left and right side (only for area under curve)
|
||||
~ parmeter on right side (only for area, tangent line and log)
|
||||
EOF
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue