dawbarton / BarycentricInterpolation.jl

A Julia implementation of Barycentric interpolation and differentiation formulae
Other
11 stars 2 forks source link

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

Open ay111 opened 5 months ago

ay111 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

Thanks.

On Mon, Mar 25, 2024 at 11:15 AM David Barton @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/dawbarton/BarycentricInterpolation.jl/issues/8#issuecomment-2017533566, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK4NBY4Q4GBXSOK4OYAQEADYZ7TMHAVCNFSM6AAAAABFGCXH56VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJXGUZTGNJWGY . You are receiving this because you authored the thread.Message ID: @.***>

ay111 commented 5 months ago

I can confirm now that the differentiation matrix is working. Please can you elaborate on the signs of the differentiation matrix. What are the signs on D^2, D^3, D^4 and D^6.

On Mon, 25 Mar 2024, 12:36 pm Rasheed Adetona, @.***> wrote:

Thanks.

On Mon, Mar 25, 2024 at 11:15 AM David Barton @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/dawbarton/BarycentricInterpolation.jl/issues/8#issuecomment-2017533566, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK4NBY4Q4GBXSOK4OYAQEADYZ7TMHAVCNFSM6AAAAABFGCXH56VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJXGUZTGNJWGY . You are receiving this because you authored the thread.Message ID: @.***>

dawbarton commented 5 months ago

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)