I'd like to build myself a small app to get my homework done faster. I want the user to be able to enter any function like f(x)=x2-5x+3 or f(x)=x3/(2x-2) and then return a list of y-values for specific x-values. For f(x)=x2 it would look something like this:
- x=-2 y=4
- x=-1 y=1
- x=0 y=0
- x=1 y=1
- x=2 y=4
- x=3 y=9
- x=4 y=16
And so on. Is there any function in the math class of java that takes in a mathematical function and an x-value and outputs the according y-value or do I need to have some kind of parser of my own?
[exp4j] seems to be the right thing for me. This library is very small, fast and easy to use.
: http://www.objecthunter.net/exp4j/index.html You can build an expression parser in ANTLR: stackoverflow.com/questions/4589951/â€¦ or use the JVM's scripting facilities, as is shown here: stackoverflow.com/questions/4681959/â€¦
以上就是Calculating mathematical functions in Android的详细内容，更多请关注web前端其它相关文章！