# Raising a Polynomial to the Nth Power?

**URL:** <https://discourse.julialang.org/t/raising-a-polynomial-to-the-nth-power/26309>\
**Category:** New to Julia\
**Created:** [July 13, 2019, 3:15am UTC](https://discourse.julialang.org/t/raising-a-polynomial-to-the-nth-power/26309 "2019-07-13T03:15:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alulushi](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@alulushi](https://discourse.julialang.org/u/alulushi)\
**Post date:** [July 13, 2019, 3:15am UTC](https://discourse.julialang.org/t/raising-a-polynomial-to-the-nth-power/26309/1 "2019-07-13T03:15:59Z")

</div>

Hi all,

I’m currently using Julia to perform utility optimization on an n-period model with one stock implementing a buy-and-hold strategy. I want to generalize my program to find the optimal number of shares for any general utility function U(x) of the form

```julia
U(x) = 1/\beta * x^\beta

```

Where x represents the terminal capital at time n. I’m using the PolynomialRoots packages to find the roots of the expected value of U(x) (E[U(x)], x is of type Polynomial), but I’m running into an issue where I can’t raise the Polynomial type to a power. I was able to work around this when using specific integer values (just by doing x \* x \* x instead of x^3, etc.), but now that I want to generalize it I’m stuck on how to do it for non-integer values like 1/2, 1/3, etc. Ideally, I would be able to do this for any rational value of \beta.

Any help/tips would be much appreciated! Thanks for your time.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 13, 2019, 3:33am UTC](https://discourse.julialang.org/t/raising-a-polynomial-to-the-nth-power/26309/2 "2019-07-13T03:33:07Z")

</div>

> [@alulushi](#):
>
> but I’m running into an issue where I can’t raise the Polynomial type to a power. I was able to work around this when using specific integer values (just by doing x \* x \* x instead of x^3, etc.), but now that I want to generalize it I’m stuck on how to do it for non-integer values like 1/2, 1/3, etc.

Integer exponents should work as-is with the [Polynomials package](https://github.com/JuliaMath/Polynomials.jl):

```julia
julia> using Polynomials

julia> Poly([1,0,3,4])
Poly(1 + 3*x^2 + 4*x^3)

julia> Poly([1,0,3,4])^6
Poly(1 + 18*x^2 + 24*x^3 + 135*x^4 + 360*x^5 + 780*x^6 + 2160*x^7 + 4095*x^8 + 7760*x^9 + 14418*x^10 + 21240*x^11 + 30489*x^12 + 40392*x^13 + 42480*x^14 + 40704*x^15 + 34560*x^16 + 18432*x^17 + 4096*x^18)

```

I don’t understand what you mean by computing non-integer powers. Polynomials raised to fractional powers are generally no longer polynomials. You’ll need to reformulate your problem a bit in order to exploit fast root-finding procedures, I’m guessing; I’m not completely clear on what you are doing, but maybe you can reformulate your problem to put it back in terms of positive integer powers of your polynomial.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 13, 2019, 5:58am UTC](https://discourse.julialang.org/t/raising-a-polynomial-to-the-nth-power/26309/3 "2019-07-13T05:58:59Z")

</div>

> [@alulushi](#):
>
> I can’t raise the Polynomial type to a power.

Can’t you just evaluate the polynomial, obtain the `x`, and raise that to a power to calculate `U`? This would, of course, require a general optimization algorithm like (L)BGFS in Optim.jl, but if your problem is well-behaved it should be fine.
