Info

This question is closed. Reopen it to edit or answer.

Fibonacci sequence problems, functions within functions

1 view (last 30 days)
So, I'm trying to create the golden spiral from the fibonacci sequence from using functions within functions. I'm new to matlab so any help is appreciated. I was wondering what y'all thought about my program so far. There are problems with it and if anyone could help by inputting into matlab that would be appreciated! I need to define the angle of rotation still however. The final product will be a spiral expanding with a radius of fibonacci. Thanks for any input or help!
function[]=Spiral (N)
basic_arc
for i=1:N;
[x]=(x*(fib (N)));
[y]=(y*(fib (N)));
Rotate(angle,x_shift,y_shift);
end
Rotate(x,y,angle,x_shift,y_shift);
for i=3:4:N;
x_shift=(-1)*fib (N);
for j=5:4:N;
x_shift=fib(N);
end
end
for i=2:4:N;
y_shift=fib(N);
for j=4:4:N;
y_shift=(-1)*fib (N);
end
end
[x1] =(x+(x_shift));
[y1] =(y+(y_shift));
Rotate=[cosd(angle),sind(angle);-sind(angle),cosd(angle)];
xy=[x1;y1];
xynew=(Rotate)*xy;
x2=xynew(1,:);
y2=xynew(2,:);
plot(x2,y2)
function[x,y] = basic_arc
for i=1:90
x(i)=cosd(i);
y(i)=sind(i);
end
end
function []=fib (N)
fib(1)=1;
fib(2)=1;
for i=3:N;
fib(i)=fib(i-2)+fib(i-1);
end
end
end

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!