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

Fix evalpoly docstring #35821

Merged
merged 1 commit into from
May 14, 2020
Merged

Conversation

sethaxen
Copy link
Contributor

@sethaxen sethaxen commented May 9, 2020

The equation in the evalpoly docstring is fine for scalar polynomials but out of order for matrix polynomials with matrix coefficients.
It gives the order as \sum_k p[k] x^{k-1}, but the code actually evaluates \sum_k x^{k-1} p[k].
The docstring for @horner uses the correct order.

An example:

julia> x = [1 2; 3 4];

julia> p1 = [3 4; 5 6];

julia> p = [p1, 2p1, 3p1];

julia> evalpoly(x, p)
2×2 Array{Int64,2}:
 242  300
 528  654

julia> p[1] + p[2] * x + p[3] * x^2 # what the equation claims evalpoly does
2×2 Array{Int64,2}:
 276  402
 426  620

julia> p[1] + x * p[2] + x^2 * p[3] # how the polynomial is actually evaluated
2×2 Array{Int64,2}:
 242  300
 528  654

@kshyatt kshyatt added the docs This change adds or pertains to documentation label May 13, 2020
@ViralBShah ViralBShah merged commit 686052b into JuliaLang:master May 14, 2020
@ViralBShah
Copy link
Member

Welcome @sethaxen!

Roger-luo pushed a commit to Roger-luo/julia that referenced this pull request May 14, 2020
KristofferC pushed a commit that referenced this pull request May 19, 2020
(cherry picked from commit 686052b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants