Your question is somewhat vague and one can imagine lots of variations of
expression in which you are looking for this pattern, but since the x + 1/x
is hyperbolic-like if you think of the x as exp(x), the following is a
possibility:
def u(n):
return x**n+1/x**n
def unu(eq):
c = (eq.subs(x, exp(x))).simplify()/2
return c.subs(cosh, Function('u')).subs(x,1)
>>> u(3) + 3*u(1)
x**3 + 3*x + 3/x + x**(-3)
>>> unu(eq)
3*u(1) + u(3)
/c
On Saturday, August 28, 2021 at 11:05:25 AM UTC-5 [email protected]
wrote:
> Hi all,
>
> I am just a new user for SymPy. I am self learning this library for my
> undergrauate research. But in the middle of the process I am stucked with
> one code.
>
> So I have defined a function with a subscript.
>
> U_n= x^n + 1/x^n
>
> When I consider (U_1)^3 I get (substitute n=1)
>
> (U_1)^3 = (x+1/x)^3
>
> Then after simplifying this I get
>
> (U_1)^3 = (x^3 + 1/x^3) + 3(x+ 1/x)
>
> But one can see this answer as
>
> (U_1)^3 = U_3 + 3U_1
>
> How to get the output in terms of U_n 's ?
>
> Can someone please give an idea how to build this code using SymPy. It
> would be a very big help for my research.
>
> Thank you very much.
>
> Gayanath Chandrasena.
>
>
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/e9a06113-e96a-4752-84da-8644e2fc0966n%40googlegroups.com.