Are there any easy ways to convert mathematical formulas to Python code? Perhaps translators, web reference, specific book chapters, anythi开发者_如何学JAVAng ~
For regular expressions there are programs such as Kodos and sites such as pythonregex.com, so I was hoping there would be something similar for formula notation and Python.
No, this isn't possible in general. There are mathematical functions that aren't computable (for example, see wikipedia/Halting_problem). There are other mathematical functions where it's just not obvious how to code them up (consider a difficult integral or differential equations). There are many books written on finding numerical solutions to these sorts of problems (you can find some links here: wikipedia/Numerical_analysis).
For simple cases, you can transcribe mathematical formulae directly, but any automated means of translation would require a formal language for writing mathematical formulae in what would be a programming language in itself. This would beg the question, since you would be trading writing mathematical formulae in one language with writing them in another.
You could try to make your own with sympy and pyparsing.
so how to convert a math formula into python? well, i myself dont know pretty much of python (i am just a beginner) but i have got some tips to help you: first, you should like calculate the formula using x and y (or a and b) and write that down on a paper. lets say phythagoras theory ( which is kinda basic). c2 = a2 + b2; so you have to input those a and b and write this formula to calculate c (which will be c = sqrt a2 + b**2) now lets say you dont know this formulas (i can hear you). then? well, you should search it up on internet, listen to its explanation and try to transform them to python. this is like noobs advice, but you know - no easy ways in programming. (well, just search it on internet, i guess?)
精彩评论