Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change of variable #343

Closed
s-celles opened this issue May 16, 2021 · 2 comments
Closed

change of variable #343

s-celles opened this issue May 16, 2021 · 2 comments

Comments

@s-celles
Copy link

Hello,

I have the following polynomial

julia> p=Polynomial([-1, 2, 1])
Polynomial(-1 + 2*x + x^2)

p(x) = a x^2 + b x + c

I can get
c = p[0]
b = p[1]
a = p[2]

I would like to change the variable from x to x - 2 for example and get the new polynomial

p2(x) = a2 x^2 + b2 x + c2

and get numerically a2, b2, c2.

I haven't find a way to do it with Polynomials.jl.

Is there a way to change variable?

I don't really need symbolic calculation... numeric calculation is fine to me.

Kind regards

@s-celles
Copy link
Author

s-celles commented May 16, 2021

Sorry for noise

julia> p=Polynomial([-1, 2, 1])
Polynomial(-1 + 2*x + x^2)

julia> x2=Polynomial([-2, 1])
Polynomial(-2 + x)

julia> p2 = p(x2)
Polynomial(-1 - 2*x + x^2)

@jverzani
Copy link
Member

This shift can be done different ways, though essentially this is the same idea as yours, only leveraging polynomial evaluation of other polynomials.

p = Polynomial([...])
x = variable(p)
q = p(x + c) # some c
coeffs(q)

There is also something like this that can be done which gets a bit more performance

function shift(p, c) # compute p(x+c)
    q = zero(p)
    for i ∈ degree(p):-1:0
        for j ∈ degree(p):-1:1
            q[j] = q[j]*c + q[j-1]
        end
        q[0] = q[0] * c + p[i]
    end
    q
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants