R Under development (unstable) (2023-11-08 r85496 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## > ## c h e b P o l y . R Test suite > ## > > > chebPoly <- pracma::chebPoly > chebCoeff <- pracma::chebCoeff > chebApprox <- pracma::chebApprox > > identical(chebPoly(6), + matrix( c(0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 2, 0, -1, + 0, 0, 0, 4, 0, -3, 0, + 0, 0, 8, 0, -8, 0, 1, + 0, 16, 0, -20, 0, 5, 0, + 32, 0, -48, 0, 18, 0, -1), + nrow = 7, ncol = 7, byrow=TRUE)) [1] TRUE > > f <- function(x) 1 + x/1 + x^2/2 + x^3/6 + x^4/24 + x^5/120 + x^6/720 > cC <- chebCoeff(f, -1, 1, 6) > cC[1] <- cC[1]/2 > all.equal(cC, + c(1.26606, 1.13021, 0.27148, 0.04427, 0.00547, 0.00052, 0.00004), + tol = 1e-5) [1] TRUE > > x <- seq(-1, 1, length.out=7) > y <- chebApprox(x, function(x) x^2, -1, 1, 6) > all.equal(x^2, y, tol = 1e-7) [1] TRUE > > proc.time() user system elapsed 0.10 0.12 0.18