Computational Science Asked by mhpedro on April 29, 2021
I have been using python to do algebraic calculations, but at many times when writing 1/2 Python writes 0.5, but I wanted you to write 1/2 and only when needed, convert it to a float.
I’m having a hard time imposing a simplification because Python doesn’t recognize 32.0 as being 32, in short example situation where I have.
$frac{(32.0-64x)^2}{4096}$
Since the answer could be
$frac{(1-2x)^2}{4}$
If you want to do symbolic math, there's a python-module called sympy.
In order the achive what you want here, you could do the following:
from sympy.abc import x
from sympy import simplify
f = (32 - 64 * x)**2 / 4096
print(f) # (32 - 64*x)**2/4096
print(simplify(f)) # (2*x - 1)**2/4
Correct answer by Dagon on April 29, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP