You are on page 1of 2

#QuestionNo.

2
#Definingxandy
x<seq(2,10,length.out=50)
y<seq(0,1,length.out=50)
par(mfrow=c(2,2))
#Plotofthefunctionin3D
func2<function(x,y){
1/64*(10(x*(y^2)))
}
z<outer(x,y,func2)
z[is.na(z)]<1
op<par(bg="white")
persp(x,y,z,theta=50,phi=40,expand=0.5,col="green",ltheta=100,
shade=0.75,ticktype="detailed",main="3Dplot",xlab="X",ylab="Y",zlab
="f(x,y)")
#Definingthefunction
func=1/64*(10(x*(y^2)))
#3DScatterplotwithColoringandVerticalDropLines
library(scatterplot3d)

scatterplot3d(x,y,func,pch=16,zlab="f(x,y)",tick.marks=TRUE,
highlight.3d=TRUE,box=TRUE,grid=TRUE,
type="h",main="3DScatterplot")
#Spinning3dScatterplot
library(rgl)
plot3d(x,y,func,type="h",col="blue",main="3DSpinningplot",size=9,
site=5,lwd=15)
#PlottingtheBestLinearPredictor
y<0.513(0.0131*x)
plot(y,x,main="BestLinearPredictor",type="l",lwd=4,
xlab="x",ylab="y",pch=19,col="black")
legend("topright",inset=.05,c("BestLinearPredictor","BestPredictor"),
fill=c("black","green"),horiz=TRUE)
#PlottingtheconditionalMean
mx<(3*(x20))/(4*(x30))
lines(mx,x,main="BestPredictor",col="green",type="l",lwd=4,xlab="m(x)",
ylab="y",pch=19)
#EndoftheProgram

You might also like