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

differentiation_matrix(p) for Chevbyshev2() returns negative of the original matrix in Julia 1.10.2. #8

Open
ay111 opened this issue Mar 24, 2024 · 4 comments

Comments

@ay111
Copy link

ay111 commented Mar 24, 2024

The differentiation_matrix(p) for Chevbyshev2() returns negative of the original matrix in Julia 1.10.2. My barycentricinterpolaton.jl version is 0.1.3.
The result for D is negative of the matrix in textbook. See the example below

using BarycentricInterpolation
N=3
p = Chebyshev2{N}()
D=differentiation_matrix(p) # incorrect
D=-differentiation_matrix(p) # correct

@dawbarton
Copy link
Owner

The sign of the differentiation matrix depends on the order of the mesh points you use. Many texts use the domain +1 to -1 (i.e. decreasing) but I’ve used -1 to +1 (i.e. increasing) because it fits more naturally with the application I use it for (collocation for differential equations). You can see this by looking at the mesh points returned by the library.

@ay111
Copy link
Author

ay111 commented Mar 25, 2024 via email

@ay111
Copy link
Author

ay111 commented Mar 25, 2024 via email

@dawbarton
Copy link
Owner

The signs are consistent with the mesh provided. For example

p = Chebyshev2{20}()           # create a Chebyshev type 2 polynomial of order 20
x = nodes(p)                   # get the nodes
y = sinpi.(x)                  # generate y values at the nodes
D = differentiation_matrix(p)  # get the differentiation matrix
@show -pi^2*sinpi.(x)  (D^2)*y  # check the second derivative matches the analytical version (true)

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