如何使用R语言编写牛顿插值公式对缺失值进行插值
LagrangePolynomial?<-?function(x,y)?{
len?=?length(x) if(len?!=?length(y))stop("length?not?equal!")
if(len?<?2)stop("dim?size?must?more?than?1")
#pretreat?data?abd?alloc?memery xx?<-?paste("(","a?-",x,")") m?<-?c(rep(0,len)) #combin?express for(i?in?1:len)?{td?<-?1
tm?<-?"1"
for(j?in?1:len)?{
if(i?!=?j)?{td?<-?td*(x[i]?-?x[j])
tm?<-?paste(tm,"*",xx[j])
}}
tm?<-?paste(tm,"/",td)
m[i]<-tm?#m[i]?<-?parse(text=tm)
} #combin?the?exrpession m?<-?paste(m,"*",y) r?<-?paste(m,collapse="+") #combin?the?function fbody?<-?paste("{?return(",r,")}") f?<-?function(a)?{} #fill?the?function's?body body(f)?<-?parse(text=fbody) return(f)}
这是拉格朗日多项式插值算法?你参考下吧