How to put a function in a function in matlab and plot it?

45 Views Asked by At

Now I am new to matlab, and now the basic syntax, however I am not sure how to write a function to loop for instance the following recurrence equation:

$y(n+1)=\exp(-y(n))$

..

where $y(1) = \exp(-y(0))$

and $y(0) = x$

1

There are 1 best solutions below

7
On

First define $x$:

x = 1;

Next, define the vector $y$:

n = 10;
y = zeros(n,1);

Initialize the vector:

y(1) = x;

Then build a loop:

for i = 2:n
    y(i) = exp(-y(i-1));
end

To plot:

plot(1:n,y)