What is the best practice for creating a recursion loop?
Hello all! I am trying to create a simple program that creates a fractal. It is supposed to be putting complex values into an array from the initial conditions and I will plot them later.
My Questions are:
1. What is the correct way to implement an Anonymous Function?
2. What is the best practice in Matlab for a recursion loop?
The answer to question 1 may not be necessary if the answer to 2 does not use Anonymous Functions.
clear all
clc
F = @(z) z^2 + c;
Re = [];
Im = [];
x = 1;
y = 1;
a = 2;
b = 3;
n = 10;
c = x+y*1i;
z0 = a+b*1i;
% Placing values in arrays to be plotted
Re(1,1) = real(z0 + c);
Im(1,1) = imag(z0 + c);
F(z0) = z; % First step of the recursion outside for loop?
% Second values for the array
Re(2,1) = real(z);
Im(2,1) = imag(z);
for h = (3:n) % Begin recursion
F(z) = z;
Re(h,1) = real(z);
Im(h,1) = imag(z);
h = h + 1;
endHello all! I am trying to create a simple program that creates a fractal. It is supposed to be putting complex values into an array from the initial conditions and I will plot them later.
My Questions are:
1. What is the correct way to implement an Anonymous Function?
2. What is the best practice in Matlab for a recursion loop?
The answer to question 1 may not be necessary if the answer to 2 does not use Anonymous Functions.
clear all
clc
F = @(z) z^2 + c;
Re = [];
Im = [];
x = 1;
y = 1;
a = 2;
b = 3;
n = 10;
c = x+y*1i;
z0 = a+b*1i;
% Placing values in arrays to be plotted
Re(1,1) = real(z0 + c);
Im(1,1) = imag(z0 + c);
F(z0) = z; % First step of the recursion outside for loop?
% Second values for the array
Re(2,1) = real(z);
Im(2,1) = imag(z);
for h = (3:n) % Begin recursion
F(z) = z;
Re(h,1) = real(z);
Im(h,1) = imag(z);
h = h + 1;
end Hello all! I am trying to create a simple program that creates a fractal. It is supposed to be putting complex values into an array from the initial conditions and I will plot them later.
My Questions are:
1. What is the correct way to implement an Anonymous Function?
2. What is the best practice in Matlab for a recursion loop?
The answer to question 1 may not be necessary if the answer to 2 does not use Anonymous Functions.
clear all
clc
F = @(z) z^2 + c;
Re = [];
Im = [];
x = 1;
y = 1;
a = 2;
b = 3;
n = 10;
c = x+y*1i;
z0 = a+b*1i;
% Placing values in arrays to be plotted
Re(1,1) = real(z0 + c);
Im(1,1) = imag(z0 + c);
F(z0) = z; % First step of the recursion outside for loop?
% Second values for the array
Re(2,1) = real(z);
Im(2,1) = imag(z);
for h = (3:n) % Begin recursion
F(z) = z;
Re(h,1) = real(z);
Im(h,1) = imag(z);
h = h + 1;
end anonymous function, recursion, fractal MATLAB Answers — New Questions