7.1 Prior Work

Suppose we have the function \(1 + i1*t1\) for values \(i1\) and \(t1\).

simple <- function(i1, t1){
  1 + i1*t1
 }

We want to evaluate the function where for every value of \(i1\), we would calculate the function at every value of \(t1\).

We need to be in careful using R because of the subtle math calculations that occur. For example, suppose the choice of \(i\) and \(t\) were the following:

i <- seq(from = 0, to = .05, by = 0.01)
t <- seq(from = 0, to = 5, by = 1)

The vector \(t\) is of length 6 and the vector \(i\) is of length 6. Evaluate simple to illustrate the result.

simple(i, t)

This is not the result that we want. The result is adding one to the product by element of \(i\) and \(t\).

Had we instead defined the length of \(i\) not as a multiple of \(t\), we would have received an error to alert us to an issue. Try this next example.

t <- seq(from = 0, to = 6, by = 1)
simple(i, t)

To obtain the correct answer, we could use a for loop. First delete \(i\) and \(t\) to clear the workspace so that we start with a clean slate.

i <- NULL
t <- NULL