1 | initial version |
There is the hold option, which might can help:
z(x)=x.power(2).mul(x,hold=true)
view(z)
which evaluates to $x \mapsto x^2x$ For an easier typing one could use Infix opertors:
def hold_mult(a,b):
return a.mul(b,hold=true)
h = infix_operator('multiply')(hold_mult)
and then use x^2 *h* x
.
However in your case if you need just the initial equation to display it might be the easiest just to print it as a string. If you need this functionality more often, an (extendet version of a) function like this could be helpful:
def paranthese_match(prefix,str):
matches = []
while (str.find(prefix) != -1):
p = -1
for li in [str.find(prefix)+len(prefix)..len(str)-1]:
if str[li] == '(':
p -=1
if str[li] == ')':
p += 1
if p==0:
matches.append(str[str.find(prefix)+len(prefix):li])
str = str[li:]
return matches
def print_expression(str):
str = str.replace('*',' \cdot ')
str = str.replace('pi',' \pi ')
for sr in paranthese_match('sqrt(',str):
str = str.replace('sqrt('+sr+")",'\sqrt{'+sr+'}')
for sr in paranthese_match('exp(',str):
str = str.replace('exp('+sr+")",'e^{'+sr+'}')
html("$"+str+"$")
Then print_expresion("6/(5*pi*h*50*h*(x^2+25))*h*exp((-x+sqrt(x^2+25))/50)")
leads to
$6/(5 \cdot \pi \cdot h \cdot 50 \cdot h \cdot (x^2+25)) \cdot h \cdot e^{(-x+\sqrt{x^2+25})/50}$