Home » Math (Page 2)

# Category Archives: Math

## Ford Circles

clc; close all; fi = 0:0.01:2*pi;

```figure('Position',[0 0 500 500])
hold on;
for h =1:15
for k = 1:15
R  = 1/(2*k^2);
x  = h/k + R*sin(fi);
y  = 1/(2*k^2) + R*cos(fi);
plot(x,y,'k');
% Symmetric
y  = -(1/(2*k^2) + R*cos(fi));
plot(x,y,'k');
end
end
axis([0, 2.2,-1.1, 1.1 ]);axis off;```

## Dragon Fractal

clc; clear all; close all;

```a  = ones(1);
for i = 1:12
sz = size(a);
b  = a;
ind = ceil(sz(2)/2);
b(ind) = ~(b(ind));
sz = size(a);
a = [a,1,b];
end
st = 1; % Step
len = size(a);
x0 = 0; y0 = 0; %Initial
Lv = 0; % Looking along positive x axis
for i = 1:len(2)
x1 = x0 - sin(Lv)*st;
y1 = y0 + cos(Lv)*st;
if a(i) == 1
Lv = Lv + pi/2;
else
Lv = Lv - pi/2;
end
xv(i) = x1;
yv(i) = y1;
x0 = x1;
y0 = y1;
end```
```fig = figure('Position',[0 0 800 800]);
set(fig, 'color', [0 0 0]);
plot(xv,yv,'clipping','off')
axis off;```

## Box Fractals

clc; clear all; close all;

```a = 1;
figure('Position',[0 0 800 800])
for i = 1 :5
[n m] = size(a);
Z = zeros(n,m);
a = [a,Z,a;
a,a,a;
a,Z,a
];
end
imagesc(a);
colormap bone;axis off;
caxis([0, 1]);```

```clc; clear all;
a = 1;
figure('Position',[0 0 800 800])
for i = 1 :5
[n m] = size(a);
Z= zeros(n,m);
a = [Z,a,Z;
a,a,a;
Z,a,Z
];
end
imagesc(a);
colormap bone;axis off;
caxis([0, 1]);```

```clc; clear all;
a = 1;
figure('Position',[0 0 800 800])
for i = 1 :5
[n m] = size(a);
Z= zeros(n,m);
a = [a,a,a;
a,Z,a;
a,a,a
];
end
imagesc(a);
colormap bone;axis off;
caxis([0, 1]);```

```clc; clear all;
a = 1;
figure('Position',[0 0 800 800])
for i = 1 :5
[n m] = size(a);
Z= zeros(n,m);
a = [a,Z,a;
Z,a,Z;
a,Z,a
];
end
imagesc(a);
colormap bone;axis off;
caxis([0, 1]);

```
```clc; clear all;
a = 1;
figure('Position',[0 0 800 800])
for i = 1 :5
[n m] = size(a);
Z= zeros(n,m);
if mod(i,2) == 0
a = [Z,a,a;
a,a,a;
a,a,a
];
else
a = [a,a,a;
a,Z,a;
a,a,a
];
end
end
imagesc(a);
colormap bone;axis off;
caxis([0, 1]);```

## Voronoi Diagram, Capitals of Every Country

clear all; clc;close all;

```load CapLatLon
lat = CapLatLon(:,1);
lon = CapLatLon(:,2);
sz = size(lon);
for i =1:sz(1)
if lon(i) <= 0
lon(i) = lon(i)+360;
end
end
fig = figure('Position',[0 0 800 800]);
hold on;
xy = [lon,lat];
ind =1;
[v,c] = voronoin(xy);
figure(1);
col = colormap(pink);
for i = 1:length(c)
if ind >= 24
ind = 1;
end
p = patch(v(c{i},1),v(c{i},2), col(35+ind,:) ); % use color i.
set(p,'EdgeColor','w')
ind = ind + 4;
end```
`Map Configuration`
```xwidth = 820;
ywidth = 420;
hFig = figure(1);
set(gcf,'PaperPositionMode','auto')
set(hFig, 'Position', [100 100 xwidth ywidth])
hold on;
axis([0 360 -90 90]);
contour(0:359,-90:89,topo,[0 0],'.k')
axis equal
box on
set(gca,'XLim',[0 360],'YLim',[-90 90], ...
'XTick',[0 60 120 180 240 300 360], ...
'Ytick',[-90 -60 -30 0 30 60 90]);
colormap(topomap1);
ylabel('Latitude [deg]');
xlabel('Longitude [deg]');
title('Voronoi Diagram, Capitals of Every Country');
scatter(lon,lat,'.r');
print(fig,'filename','-djpeg','-r600');```

% Capitals of Every Country