Let's return to the original problem that we solved when studying recurrence
relations. We began by solving this recurrence relation:
sol=RSolve[{ s[n] == n +s[n-1] ,
s[0] == 0},s[n], n ]
We then simplified the result. This time, let's name the result of the
simplification so that we can use it later:
s1[n]=s[n]/. sol[[1]]
answer = Simplify[s1[n]]
If what we want is a function that will compute the sum of the first n
integers, what is unsatisfactory about our answer?
Click here for the answer.
Fortunately, Mathematica makes it easy to transform an
expression into a function. For example, if we want a function called
``sumOfInts'' to compute the sum of the first n integers, we need only do
sumOfInts[n_]=answer
The idea is this. If we have an expression containing
some variables, we can tell Mathematica to create a function in which the
expression is the body and one or more of the variables are the arguments. You
will shortly see an example in which we give more than one
variable as an argument.
Of course, we could have done without a function in this instance. Instead,
we could have simply typed the entire function definition into Mathematica by hand.
Even though making a function is only a convenience, it is a very useful
convenience when we are trying to convert very complicated expressions into
functions.
Study this carefully and be sure you understand what this section does before
you continue. Use the methods here to create functions to compute R and T
that you defined earlier.