Use square brackets for parenthesis in newton
This commit is contained in:
parent
35df61633c
commit
be3f334856
|
@ -80,14 +80,15 @@ getConfiguredClient()
|
||||||
validateExpression()
|
validateExpression()
|
||||||
{
|
{
|
||||||
local parsedExpression
|
local parsedExpression
|
||||||
parsedExpression=$(echo $1 | grep -Eo "[0-9 + -- / * ^ . a-z A-Z ~ :]*")
|
originalExpression=$(echo $1 | sed "s/\[/\(/g" | sed "s/\]/\)/g")
|
||||||
if [[ "$parsedExpression" != "$1" ]];then { echo "Error: Expression contains invalid characters"; return 1; }; fi
|
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()
|
encodeEquation()
|
||||||
{
|
{
|
||||||
originalEquation=$1
|
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()
|
validateOperation()
|
||||||
|
@ -112,7 +113,7 @@ printAnswer()
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
================================
|
================================
|
||||||
|Operation: $operation
|
|Operation: $operation
|
||||||
|Expression: $originalEquation
|
|Expression: $originalExpression
|
||||||
|Result: $result
|
|Result: $result
|
||||||
================================
|
================================
|
||||||
EOF
|
EOF
|
||||||
|
@ -130,7 +131,7 @@ Usage: newton [operation] [expression] or newton [flag]
|
||||||
===================================================
|
===================================================
|
||||||
|Operations Sample Expression Sample Result|
|
|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) |
|
|Factor x^2 + 2x x (x + 2) |
|
||||||
|Derive x^2+2x 2 x + 2 |
|
|Derive x^2+2x 2 x + 2 |
|
||||||
|Integrate x^2+2x 1/3 x^3 + x^2 +C|
|
|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 |
|
|Abs -2 2 |
|
||||||
|Log 2~8 3 | (Log base 2 of eight)
|
|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
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue