pade(p1, p2 = c(1), d1 = 5, d2 = 5)
p1/p2
.r1
and r2
for the numerator and
denominator polynomials, i.e. r1/r2
is the rational approximation
sought.p1
(and p2
)
and r1
and r2
is determined by a system of linear equations.
The system is then solved by applying the pseudo-inverse pinv
for
for the left-hand matrix.taylor
, ratInterp
## Exponential function
p1 <- c(1/24, 1/6, 1/2, 1.0, 1.0) # Taylor series of exp(x) at x=0
R <- pade(p1); r1 <- R$r1; r2 <- R$r2
f1 <- function(x) polyval(r1, x) / polyval(r2, x)
xs <- seq(-1, 1, length.out=51); ys1 <- exp(xs); ys2 <- f1(xs)
plot(xs, ys1, type = "l", col="blue")
lines(xs, ys2, col = "red")
grid()
Run the code above in your browser using DataLab