pyCBD.converters.latexify.rst 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. Generate LaTeX from CBD Models
  2. ==============================
  3. Bundled with the CBD simulator, there is a powerful CBD to equation converter.
  4. It transforms an input CBD model into a set of equations, which can be outputted as
  5. plaintext, or in LaTeX format.
  6. .. note::
  7. For educational purposes, it is also possible to output all intermediary steps that
  8. were obtained in the generation of the final simplified equations.
  9. As an example, the :doc:`examples/SinGen` will be used. It will be assumed the
  10. :class:`SinGen` class exists and a CBD model is created for this class, stored in the
  11. :code:`model` variable.
  12. Additionally, it is important to import the :class:`pyCBD.converters.latexify.CBD2Latex` class:
  13. .. code-block:: python
  14. # Create the model
  15. model = SinGen('model')
  16. # Import the latexify core unit
  17. from pyCBD.converters.latexify import CBD2Latex
  18. # OR, ALTERNATIVELY
  19. from pyCBD.converters.latexify.CBD2Latex import CBD2Latex
  20. Next, we will create a converter, which can tell us the system of equations. For more information
  21. about the keyword arguments of the class, take a look at the :class:`pyCBD.converters.latexify.CBD2Latex`
  22. documentation.
  23. .. code-block:: python
  24. cbd2latex = CBD2Latex(model, show_steps=True, render_latex=False)
  25. To simplify the system of equations, you can call the
  26. :func:`pyCBD.converters.latexify.CBD2Latex.CBD2Latex.simplify` method. When :code:`show_steps` was set to
  27. :code:`True`, all steps and additional information will be outputted to the console. If :code:`show_steps`
  28. was :code:`False`, you will see nothing in the console. After the simplification, you can obtain the
  29. string-representation of the equations using the :func:`pyCBD.converters.latexify.CBD2Latex.CBD2Latex.render`
  30. method.
  31. .. code-block:: python
  32. cbd2latex.simplify()
  33. # print the resulting equations
  34. print("RESULT IS:")
  35. print(cbd2latex.render())
  36. The output of this code is shown below:
  37. .. code-block:: text
  38. INITIAL SYSTEM:
  39. sin.OUT1(i) = sin(sin.IN1(i))
  40. time.OUT1(i) = time(i)
  41. OUT1(i) = sin.OUT1(i)
  42. sin.IN1(i) = time.OUT1(i)
  43. STEP 1: substituted all connections and constant values
  44. sin.OUT1(i) = sin(time(i))
  45. OUT1(i) = sin.OUT1(i)
  46. STEP 2:
  47. OUT1(i) = sin(time(i))
  48. RESULT IS:
  49. OUT1(i) = sin(time(i))
  50. Submodules
  51. ----------
  52. .. toctree::
  53. pyCBD.converters.latexify.CBD2Latex
  54. pyCBD.converters.latexify.functions