Math 222 MATLAB Supplementary lecture
Part 1: For loops and recurrence relations
Any formula which generates a sequence and gives in terms of is called a recurrence relation. Of course such a formula needs an initial value . A very simple recurrence relation is
This define a sequence of values
n=0:N; % note that this starts from n=0
We know, from first semester calculus (NJIT Math 111), that the exact solution to this recurrence is
yExact=n.*(n+1)/2; % Note the use of .* to multiply arrays!
We plot both of these on the same axis. Note the plotting syntax, including both the plots of both y and yExact, is not taught in the Onramp, but how it works should be obvious