I want to take the output of a function and put it back into the function to get my next output, then get a matrix of all the results. For example, if my function was b=3*a+1, I would want to get the matrix [4, 13, 40, 121...] etc, but a very large size, eg. 500 numbers.
Here's how I'm currently doing it. I have the function:
function [ y ] = test( x )
assignin('base', 'B', evalin('base', 'B')+1)
The purpose of the assignin bit is to increase B (a variable in my main workspace) by 1 every time I use the function.
I start by setting B as 0. Then in my command window I do:
This sets M as 4.
Then I do:
This makes M a 1x2 matrix [4, 13].
I have to keep repeating this last command to get more values in matrix M.
Is there a way I could get, let's say, 500 values of M all at once, giving me a 1x500 matrix in one go?
P.S. 3X+1 is just an example - the equation I'm actually using is a bit more complicated, so finding a general equation for the nth term won't help.
I'm on 2016a