Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- KSo<-c(0.90,0.95,1.00,1.05,1.10)
- T<-c(1/12,3/12,6/12,1,2,5)
- mapping<-c(14.2, 13.0, 12.0, 13.1, 14.5,
- 14.0, 13.0, 12.0, 13.1, 14.2,
- 14.1, 13.3, 12.5, 13.4, 14.3,
- 14.7, 14.0, 13.5, 14.0, 14.8,
- 15.0, 14.4, 14.0, 14.5, 15.1,
- 14.8, 14.6, 14.4, 14.7, 15.0)
- mapped<-matrix(mapping, ncol=5, byrow=TRUE)
- #predict
- x<-0.98
- y<-11/12
- #Perform 2D interpolation
- #find index
- ki<-as.integer(cut(x, KSo, right=FALSE))
- Ti<-as.integer(cut(y, T, right=FALSE))
- dx<-(x-KSo[ki])/(KSo[ki+1]-KSo[ki])
- dy<-(y-T[Ti])/(T[Ti+1]-T[Ti])
- #find values and weighed sums of neighboring points
- f00<-mapped[Ti, ki]*(1-dx)*(1-dy)
- f01<-mapped[Ti+1, ki]*(1-dx)*dy
- f10<-mapped[Ti, ki+1]*dx*(1-dy)
- f11<-mapped[Ti+1, ki+1]*dx*dy
- sum(f00, f10, f01, f11)
- #estaablish data frame with raw data
- df<-data.frame(expand.grid(KSo, T), mapping)
- names(df)<-c("KSo", "T", "z")
- #Perform regression
- model<-lm(z~I(KSo^2)+I(T^2)+KSo*T, data=df)
- #Predict results at desired coordinates
- dfnew<-data.frame(KSo=c(1, 0.98), T=c(0.5, 0.9166667))
- predict(model, dfnew)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement