简体   繁体   English

如何将正交多项式分配给函数?

[英]How to assign the Orthogonal Polynomials to functions?

Im trying to plot Laguerre's orthogonal polynomials for class assignment.我正在尝试 plot Laguerre 的 class 分配的正交多项式。 I thought to create 10 functions, each function assigned to a specific polynomial by the index i.我想创建 10 个函数,每个 function 通过索引 i 分配给一个特定的多项式。


for (i in 1:10){
  opl[i] <- function(x) {opl[3]}
}

and then use curve() to plot it.然后使用curve()到 plot 它。 But it's not working.但它不起作用。 the laguerre.polynomials() function gives you the polynomials as a list and I think that the problem is that my loop can't extract items from a list by the index and assign it to the function. laguerre.polynomials() function 将多项式作为列表提供给您,我认为问题在于我的循环无法通过索引从列表中提取项目并将其分配给 function。

Any ideas on how to do it?关于如何做的任何想法?

You could convert the polynomials into functions using as.function , eg by您可以使用as.function将多项式转换为函数,例如通过

library(orthopolynom)
library(ggplot2)

opl <- laguerre.polynomials(10)

opl_functions <- lapply(opl, as.function)

# x interval
x <- seq(-1, 1, 0.05)

# plot the first two polynomials
ggplot(data.frame(x), aes(x = x, y = y)) +      # basic graphical object
    geom_line(aes(y = opl_functions[[1]](x)), colour = "red") +  # first layer
    geom_line(aes(y = opl_functions[[2]](x)), colour = "blue") # second layer

# and so on ...

The i-th element of opl_functions is then the i-th polynomial, depending on x . opl_functions的第 i 个元素是第 i 个多项式,具体取决于x This can then be used in order to plot the polynomials.然后可以使用它来 plot 多项式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM