MATLAB: How can i plot surfaces for a recursive function

recurrencerecursive functionsubplotsurf

I have written a recursive function from a given recurrence formula, using the form "function z=F(n,x,y)" which evaluates the function at (x,y).
Now i want to plot the surfaces of Fn(x,y) for a range of n (0:5) and -1≤ x,y≤ 1. To get them all in the same figure i know i need to use subplot, but i am struggling with how to use surf for a recursive function?
Any help much appreciated 🙂

Best Answer

Try this:
for n = 0:5
ax = subplot(2,3,n+1);
fsurf(ax, @(x,y) F(n,x,y), [-1 1])
end