mathematical-expressions

How to get the size of a number in .net?

前提是你 提交于 2019-12-04 11:12:44
I want with a given double number to return its "size" (known as |number|, or number of digit without the numbers after the dot), for example: 12.324654 -> 2 12 -> 2 0.99 -> 0 1.01 -> 1 901 -> 3 -0.99 -> 0 -9.999 -> 1 There must be a function is .net that I dont familiar with that does it.. Thanks. ((int)Math.Abs(12.324654)).ToString().Length Math.Abs will convert to positive number (don't want to count the negative sign) (int) will drop the digits following the decimal point ToString() converts to a string ===> "12" Length tells you how many characters there are there is an edge case where

Predicting price using previous prices with R and Neural Networks (neuralnet)

雨燕双飞 提交于 2019-12-03 08:52:46
Within the R Neural Network page, I am using the neural network function to attempt to predict stock price. Training data contains columns High,Low,Open,Close. myformula <- close ~ High+Low+Open neuralnet(myformula,data=train_,hidden=c(5,3),linear.output=T) My question, Given the below data example could you tell me what the formula would look like. I have a table with columns "High","Low","Open","Close" it has two rows of values, each row represents a candle stick for the day. So the two rows in the data are candle sticks for the previous two days.My aim is tp predict what the next candle

Evaluating mathematical expressions in Python

随声附和 提交于 2019-11-30 08:24:26
问题 I want to tokenize a given mathematical expression into a parse tree like this: ((3 + 4 - 1) * 5 + 6 * -7) / 2 '/' / \ + 2 / \ * * / \ / \ - 5 6 -7 / \ + 1 / \ 3 4 Is there any pure Python way to do this? Like passing as a string to Python and then get back as a tree like mentioned above. Thanks. 回答1: Yes, the Python ast module provides facilities to do this. You'll have to look up the exact interface for your version of Python, since the ast module seems to change regularly. In particular,

Python if-statement with variable mathematical operator

冷暖自知 提交于 2019-11-29 09:15:01
I'm trying to insert a variable mathematical operator into a if statement, an example of what I'm trying to achieve in parsing user-supplied mathematical expressions: maths_operator = "==" if "test" maths_operator "test": print "match found" maths_operator = "!=" if "test" maths_operator "test": print "match found" else: print "match not found" obviously the above fails with SyntaxError: invalid syntax . I've tried using exec and eval but neither work in an if statement, what options do I have to get around this? Use the operator package together with a dictionary to look up the operators

Evaluating mathematical expressions in Python

拟墨画扇 提交于 2019-11-29 06:14:06
I want to tokenize a given mathematical expression into a parse tree like this: ((3 + 4 - 1) * 5 + 6 * -7) / 2 '/' / \ + 2 / \ * * / \ / \ - 5 6 -7 / \ + 1 / \ 3 4 Is there any pure Python way to do this? Like passing as a string to Python and then get back as a tree like mentioned above. Thanks. Yes, the Python ast module provides facilities to do this. You'll have to look up the exact interface for your version of Python, since the ast module seems to change regularly. In particular, the ast.parse() method will be helpful for your application: >>> import ast >>> ast.parse("(1+2)*3", "",

Python if-statement with variable mathematical operator

二次信任 提交于 2019-11-28 02:40:07
问题 I'm trying to insert a variable mathematical operator into a if statement, an example of what I'm trying to achieve in parsing user-supplied mathematical expressions: maths_operator = "==" if "test" maths_operator "test": print "match found" maths_operator = "!=" if "test" maths_operator "test": print "match found" else: print "match not found" obviously the above fails with SyntaxError: invalid syntax . I've tried using exec and eval but neither work in an if statement, what options do I

Mathematical expression (string) to number in Java

允我心安 提交于 2019-11-27 07:00:07
问题 I'm trying to find something like Java Embedding Plugin (JEP) that can evaluate a mathematical formula (string) and give back the answer. But it should also calculate a variable, for example: (25+36+x)*2 = 25 should give: x = -11 A little like http://www.wolframalpha.com/, but it shouldn't be that versatile, and it should work off-line. Open source is preferred. I need it for my little calculator project, http://sourceforge.net/projects/calex/. 回答1: This is called Arithmetic evaluation . One

How can I add numbers in a bash script

孤人 提交于 2019-11-26 00:39:09
问题 I have this bash script and I had a problem in line 16. How can I take the previous result of line 15 and add it to the variable in line 16? #!/bin/bash num=0 metab=0 for ((i=1; i<=2; i++)); do for j in `ls output-$i-*`; do echo \"$j\" metab=$(cat $j|grep EndBuffer|awk \'{sum+=$2} END { print sum/120}\') (line15) num= $num + $metab (line16) done echo \"$num\" done 回答1: For integers : Use arithmetic expansion: $((EXPR)) num=$((num1 + num2)) num=$(($num1 + $num2)) # also works num=$((num1 + 2 +