-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimize_array.m
More file actions
58 lines (46 loc) · 1.19 KB
/
Copy pathoptimize_array.m
File metadata and controls
58 lines (46 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
close all; clear;
N = 20;
theta = optimvar('theta',N,'LowerBound',0,'UpperBound',2.*pi);
thetaprob = optimproblem;
energy = optimexpr(1);
rw = linspace(-10,10,501);
w = taylorwin(501);
rs = rejectionSample(w,rw,N)';
ws = interp1(rw,w,rs);
init.theta = rand(N,1).*2.*pi;
x = rs.*cos(theta);
y = rs.*sin(theta);
for ii = 1:(N-1)
jj = (ii+1):N;
tempe = (x(ii)-x(jj)).^2 + (y(ii)-y(jj)).^2;
energy = energy + sum(tempe.^(-1/2));
end
thetaprob.Objective = energy;
x0 = rs.*cos(init.theta);
y0 = rs.*sin(init.theta);
[sol,fval,exitlfag,output] = solve(thetaprob,init);
xf = rs.*cos(sol.theta);
yf = rs.*sin(sol.theta);
dx = xf -x0;
dy = yf -y0;
scatter(x0,y0,'filled'); hold on;
scatter(xf,yf,'filled');
legend('Start','Finish');
quiver(x0,y0,dx,dy,'off');
theta = linspace(0,pi,181)';
phi = linspace(0,2*pi,361);
AF = zeros(numel(theta),numel(phi));
for id=1:N
AF =AF + ws(id).*exp(1j.*2.*pi.*(xf(id).*sin(theta).*cos(phi)+yf(id).*sin(theta).*sin(phi)));
end
[TH,PH] = ndgrid(theta,phi);
U = sin(TH).*cos(PH);
V = sin(TH).*sin(PH);
figure;
surf(U,V,10.*log10(abs(AF)),'EdgeColor','interp');
colorbar;
view(2);
figure;
for phid=1:10:numel(phi)
plot(theta,10.*log10(abs(AF(:,phid)))); hold on;
end