#1. Write a function which takes a square matrix as input and outputs its diagonal elements. The function:
## a) Takes one argument, a matrix m
## b) returns a vector containing the diagonal elements of m
#The function should:
## a) performs validation to check that the argument passed (m) is indeed a matrix. Hint: use R built-in function: is.matrix().
## b) performs validation to check that m is indeed a square matrix (i.e. its number of rows and number of columns are equal).
#Hint: there exists a built-in R function to extract the diagonal elements of a matrix.
#Test your function on the following matrices:
#m1 <- cbind(c(1,2),c(3,4))
#m2 <- rbind(c(1,2,3),c(5,-1,3))
#2. Modify our greeting function (previous practical) to output the following greeting:
# ******************************** Welcome to R, ! ********************************
#Hint: Use two for loops to generate the asterix sequences surrounding the greeting
# 3. Rewrite problem 1 (above) to return the squares of the diagonal elements of the matrix. Use sapply.
#4. Write a function isPositive which accepts a number and returns a boolean value (TRUE or FALSE) corresponding to whether or not the number is positive.
#5. Use sapply to classify the diagnonal elements of the following matrix as positive/negative:
#m3 <- rbind(c(1,2,3),c(5,-1,3),c(2,3,-2))
# 6. write a new generic 'summary' method which:
# a) outputs a greeting. e.g. "You are about to summarise a/an X object: " (where X is the object's class)
# b) calls the summary method appropriate for the object
# c) Ends the summary with a message such as: "<--End of Summary-->#
# 7. In the travelDistance problem (first functions practical), you wrote a function which will calculate the distance traveled by an elastic band given its length and amount of stretch.
# a) Call the 'summary' method on:
# - s
# - the vector returned by travelDistance
# - Obtain a linear model describing between s and the travel distance returned by the function. Visualise it with plot
# Notice the difference in the summary returned each time. Relate this difference to the class concept you've learned today.
# b) perform the tasks given in a) above using the 'plot' method instead.