Advertisement
Guest User

Untitled

a guest
May 27th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. KSo<-c(0.90,0.95,1.00,1.05,1.10)
  2. T<-c(1/12,3/12,6/12,1,2,5)
  3. mapping<-c(14.2, 13.0, 12.0, 13.1, 14.5,
  4. 14.0, 13.0, 12.0, 13.1, 14.2,
  5. 14.1, 13.3, 12.5, 13.4, 14.3,
  6. 14.7, 14.0, 13.5, 14.0, 14.8,
  7. 15.0, 14.4, 14.0, 14.5, 15.1,
  8. 14.8, 14.6, 14.4, 14.7, 15.0)
  9. mapped<-matrix(mapping, ncol=5, byrow=TRUE)
  10.  
  11. #predict
  12. x<-0.98
  13. y<-11/12
  14.  
  15. #Perform 2D interpolation
  16. #find index
  17. ki<-as.integer(cut(x, KSo, right=FALSE))
  18. Ti<-as.integer(cut(y, T, right=FALSE))
  19. dx<-(x-KSo[ki])/(KSo[ki+1]-KSo[ki])
  20. dy<-(y-T[Ti])/(T[Ti+1]-T[Ti])
  21.  
  22. #find values and weighed sums of neighboring points
  23. f00<-mapped[Ti, ki]*(1-dx)*(1-dy)
  24. f01<-mapped[Ti+1, ki]*(1-dx)*dy
  25. f10<-mapped[Ti, ki+1]*dx*(1-dy)
  26. f11<-mapped[Ti+1, ki+1]*dx*dy
  27. sum(f00, f10, f01, f11)
  28.  
  29. #estaablish data frame with raw data
  30. df<-data.frame(expand.grid(KSo, T), mapping)
  31. names(df)<-c("KSo", "T", "z")
  32.  
  33. #Perform regression
  34. model<-lm(z~I(KSo^2)+I(T^2)+KSo*T, data=df)
  35.  
  36. #Predict results at desired coordinates
  37. dfnew<-data.frame(KSo=c(1, 0.98), T=c(0.5, 0.9166667))
  38. predict(model, dfnew)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement