mvp (version 1.0-8)

series: Decomposition of multivariate polynomials by powers

Description

Power series of multivariate polynomials, in various forms

Usage

trunc(S,n)
trunc1(S,...)
series(S,v,showsymb=TRUE)
# S3 method for series
print(x,...)
onevarpow(S,...)
taylor(S,vx,va,debug=FALSE)
mvp_taylor_onevar(allnames,allpowers,coefficients, v, n)
mvp_taylor_allvars(allnames,allpowers,coefficients, n)
mvp_taylor_onepower_onevar(allnames, allpowers, coefficients, v, n)
mvp_to_series(allnames, allpowers, coefficients, v)

Arguments

S

Object of class mvp

n

Non-negative integer specifying highest order to be retained

v

Variable to take Taylor series with respect to. If missing, total power of each term is used (except for series() where it is mandatory)

x,...

Object of class series and further arguments, passed to the print method; in trunc1() a list of variables to truncate

showsymb

In function series(), Boolean, with default TRUE meaning to substitute variables like x_m_foo with (x-foo) for readability reasons

vx,va,debug

In function taylor(), names of variables to take series with respect to; and a Boolean with default FALSE meaning to return the mvp and TRUE meaning to return the string that is passed to eval()

allnames,allpowers,coefficients

Components of mvp objects

Details

Function onevarpow() returns just the terms in which symbol v appears with power n.

Function series returns a power series expansion of powers of variable v. The print method for series objects is sensitive to the value of getOption("mvp_mult_symbol"); set this to "*" to get mpoly-compatible output.

Function taylor() is a convenience wrapper for series().

Functions mvp_taylor_onevar(), mvp_taylor_allvars() and mvp_to_series() are low-level helper functions that are not intended for the user.

See Also

deriv

Examples

Run this code
# NOT RUN {
trunc(as.mvp("1+x")^6,2)

trunc(as.mvp("1+x+y")^3,2)      # neglects all terms with total power>2
trunc1(as.mvp("1+x+y")^3,x=2) # terms like y^3 are treated as constants

p <- horner("x+y",1:4)

onevarpow(p,x=2)   # coefficient of x^2
onevarpow(p,x=3)   # coefficient of x^3

onevarpow(as.mvp("1+x+x*y^2  + z*y^2*x"),x=1,y=2)

series(rmvp(10),"a")

# Works well with pipes:

f <- function(n){as.mvp(sub('n',n,'1+x^n*y'))}
Reduce(`*`,lapply(1:6,f)) %>% series('y')
Reduce(`*`,lapply(1:6,f)) %>% series('x')


p %>% trunc(2)
p %>% trunc1(x=2)
(p %>% subs(x="x+dx") -p) %>% trunc1(dx=2)


## Third order taylor expansion of f(x)=sin(x+y) for x=1.1, about x=1:
sinxpy <- horner("x+y",c(0,1,0,-1/6,0,+1/120,0,-1/5040,0,1/362880))  # sin(x+y)
dx <- as.mvp("dx")
t3 <- sinxpy  + aderiv(sinxpy,x=1)*dx + aderiv(sinxpy,x=2)*dx^2/2 + aderiv(sinxpy,x=3)*dx^3/6
t3 %<>% subs(x=1,dx=0.1)  # t3 = Taylor expansion of sin(y+1.1)
t3 %>% subs(y=0.3)  - sin(1.4)  # numeric; should be small
# }

Run the code above in your browser using DataLab