plotter_6.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. def getFuncExpr(exprTok, eqnVars, graphVars):
  2. """Allocates variables in equation to graph variables to give final function compatible for plotting
  3. Arguments:
  4. exprTok {list} -- expression tokens
  5. eqnVars {list} -- variables in equation
  6. graphVars {list} -- variables for plotting
  7. Returns:
  8. expr {numpy.array(2D)/function(3D)} -- expression converted to compatible data type for plotting
  9. """
  10. expr = 0
  11. coeff = 1
  12. for token in exprTok:
  13. if isinstance(token, Variable):
  14. varProduct = 1
  15. for value, power in zip(token.value, token.power):
  16. varProduct *= graphVars[eqnVars.index(value)]**power
  17. expr += coeff * token.coefficient * varProduct
  18. elif isinstance(token, Constant):
  19. expr += coeff * token.value
  20. elif isinstance(token, FuncOp):
  21. pass
  22. elif isinstance(token, Binary) and token.value == '-':
  23. coeff = -1
  24. elif isinstance(token, Binary) and token.value == '+':
  25. coeff = 1
  26. return expr
  27. #######
  28. # GUI #
  29. #######