Polynomials-R

 Polynomials-R
> install.packages("ar.matrix")
 require("ggplot2")
> obs <- r.AR1(100, M=30, sigma=1, rho=.98)
> dim(obs)
[1] 100  30
> obs_adj <- obs - obs[,1]
> ar1_df <- data.frame(obs=c(t(obs_adj)), realization=rep(1:100, each=30),
+                      time=rep(1:30, 100))
> ggplot(data=ar1_df, aes(time, obs, group=realization, color=realization)) +
+     geom_line()
data science

> install.packages("mvp")
coeffs(a) <- 1
> coeffs(a) <- 0
> p <- rmvp(10,9,9,letters[1:4])
> deriv(p,letters[1:3])
mvp object algebraically equal to
2448 a^3 b^3 c^16 d^17  +  2145 a^4 b^12 c^10 d^7  +  4400 a^10 b^19 c d^18  +  14280 a^16 b^14 c^7 d^15  +  11628 a^18 b^5 c^16 d^4  +  2025 a^26 b^4 c^2 d
> deriv(p,rev(letters[1:3]))
> deriv(p,rev(letters[1:3]))
> x <- rmvp(7,symbols=6)
> v <- allvars(x)[1]
> s <- as.mvp("1  +  y  -  y^2 zz  +  y^3 z^2")
> LHS <- subsmvp(deriv(x,v)*deriv(s,"y"),v,s)
> RHS <- deriv(subsmvp(x,v,s),"y")
> LHS - RHS
mvp object algebraically equal to
0
> p <- as.mvp("1+a^2 + a*b^2 + c")
> p
mvp object algebraically equal to
1  +  a b^2  +  a^2  +  c
> f <- as.function(p)
> f(a=1)
mvp object algebraically equal to
2  +  b^2  +  c
> f(a=1,b=2)
mvp object algebraically equal to
6  +  c
> f(a=1,b=2,c=3)
[1] 9
> f(a=1,b=2,c=3,drop=FALSE)
mvp object algebraically equal to
9
> x == mpoly_to_mvp(mpoly::as.mpoly(x))
[1] TRUE
> kahle  <- mvp(
+     vars   = split(cbind(letters,letters[c(26,1:25)]),rep(seq_len(26),each=2)),
+     powers = rep(list(1:2),26),
+     coeffs = 1:26
+ )
library(mpoly)
> f<- mp("1-2x + x^2 + 100 x^2 y +100y^2")
> f <- as.function(f)
f(.) with . = (x, y)
> df <- expand.grid(x=seq(-2, 2,.01),y=seq(-1, 3, .01))
library(scales)
qplot(x , y, data = df,   geom = c("raster","contour"),fill = f+.001, z=f, colour= I("white"),bins=6) + scale_fill_gradient2(low = "blue",mid = "red",high = "green", trans="log10", guide = "none")

Post a Comment

0 Comments