Chapter 4 - Classification, q12

(a)

In [3]:
Power = function(){
    print(2^3)
}
Power()
[1] 8

(b)

In [5]:
Power2 = function(x,a){
    print(x^a)
}
Power2(3,8)
[1] 6561

(c)

In [6]:
Power2(10,3)
Power2(8,17)
Power2(131,3)
[1] 1000
[1] 2.2518e+15
[1] 2248091

(d)

In [8]:
Power3 = function(x,a){
    answer = x^a
    return(answer)
}
Power3(2,3)
8

(e)

In [39]:
x = 1:10
y = Power3(x,2)
plot(x,y,main="x^2 vs x",xlab="x",ylab="x^2")
In [38]:
x=1:10
plot(x,Power3(x,2),log="xy", main="log(y) vs log(x)")
plot(x,Power3(x,2),log="x",main="y vs log(x)")

(f)

In [26]:
PlotPower = function(x,a){
    y = x^a
    plot(x,y)
}
PlotPower(1:10,3)
In [ ]: