Convert a string into mathematical function of x :f(x)? [closed]

拥有回忆 提交于 2019-12-13 05:24:26

问题


Hello I'm a beginner in Android programming. I'm working on a graphic calculator but i still have the problem of converting the function to math

For example :

y=cos(x^2)-ln(x)

should look like

y=Math.cos(x*x) - Math.log(x)

And than we plot it.

Thank You


回答1:


I assume you want to convert a String to a float or double?

String input = "3.14";
float x = Float.parseFloat(input);

This code converts the String "3.14" into a float. You can use this float in the function you described in the question.

EDIT: If you want to convert the full function String into Java code, you should limit the input to buttons. For example, add a button named "Cos", and remember in the code the user wants to use the Cosinus function. Then the user enters a value, and presses "Enter". The code knows it should use the cosinus function, and x is the value entered in an EditText. That value should be parsed using Float.parseFloat().



来源:https://stackoverflow.com/questions/21137526/convert-a-string-into-mathematical-function-of-x-fx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!