summaryrefslogtreecommitdiff
path: root/mode_match.m
diff options
context:
space:
mode:
authorMatt Argao <mcargao@email.wm.edu>2012-11-06 17:33:27 -0500
committerMatt Argao <mcargao@email.wm.edu>2012-11-06 17:33:27 -0500
commit9967bdc8f5c9ab51ea69cacdf694a3ddc5fd233e (patch)
tree420d433d2b43301d8d01f33c414bf3f08dcff498 /mode_match.m
parent6a755b5f70bc4960e818de260b8b5d057295eb5f (diff)
downloadmode_match-9967bdc8f5c9ab51ea69cacdf694a3ddc5fd233e.tar.gz
mode_match-9967bdc8f5c9ab51ea69cacdf694a3ddc5fd233e.zip
Assorted code cleanup, addition of mode_match.m
Refinement of fitness function
Diffstat (limited to 'mode_match.m')
-rw-r--r--mode_match.m50
1 files changed, 50 insertions, 0 deletions
diff --git a/mode_match.m b/mode_match.m
new file mode 100644
index 0000000..596cff1
--- /dev/null
+++ b/mode_match.m
@@ -0,0 +1,50 @@
+function [ possible_lens_placement, possible_lens_set, possible_sample_energy, n_possible_lens_placement, index ] = mode_match( q0, qf, Ltot, lambda, lens_permutations )
+%MODE_MATCH Summary of this function goes here
+% Detailed explanation goes here
+
+n_perms = size(lens_permutations,1);
+n_shuffles=1; %number of random placements of lenses
+
+%Initialize sample arrays
+N = n_perms * n_shuffles;
+possible_lens_placement = zeros(N,3);
+possible_lens_set = zeros(N,3);
+possible_sample_energy = zeros(N,1);
+initial_rand_lens_placement=zeros(N,3);
+
+lens_size = .03; % physical size of the lens
+
+for ip = 1:n_perms
+ f3=lens_permutations(ip,3);
+ x3=Ltot-f3; % last lense transfer collimated region to focused spot
+ for is = 1:n_shuffles
+ possible_lens_set((ip-1)*n_shuffles + is,:) = lens_permutations(ip,:);
+
+ initial_rand_lens_placement_tmp = sort(lens_size+(x3-2*lens_size)*rand(1,2));
+ initial_rand_lens_placement((ip-1)*n_shuffles + is,:) = [initial_rand_lens_placement_tmp, x3];
+ end
+end
+
+parfor i = 1:N
+
+ fitness_simplified=@(x) fitness(q0, qf, Ltot, x, possible_lens_set(i,:), lambda );
+ [x_sol, energy]=fminsearch(fitness_simplified, initial_rand_lens_placement(i,:), optimset('TolX',1e-8,'TolFun',1e-8,'MaxFunEvals',1e8,'MaxIter',200));
+
+ possible_lens_placement(i,:) =x_sol;
+ possible_sample_energy(i) = energy;
+
+end
+
+%Sorting possible solution according to energy
+[possible_sample_energy, index] = sort(possible_sample_energy);
+possible_lens_placement = possible_lens_placement(index,:);
+possible_lens_set = possible_lens_set(index,:);
+
+%Truncate other possible solutions to an accuracy of n decimal places
+n=4;
+possible_lens_placement_trunc = round(possible_lens_placement*10^n)./10^n;
+[possible_lens_placement_uniq, index] = unique(possible_lens_placement_trunc,'rows','stable'); %Unique solutions only
+
+n_possible_lens_placement = min(5,size(possible_lens_placement_uniq,1));
+
+end