diff --git a/src/new/FT_find_radius_for_clipping_loss.m b/src/new/FT_find_radius_for_clipping_loss.m new file mode 100644 index 0000000000000000000000000000000000000000..acbaec8f6e248b176aa71e626cf788d30e6ddccc --- /dev/null +++ b/src/new/FT_find_radius_for_clipping_loss.m @@ -0,0 +1,63 @@ +% +%-------------------------------------------------------------------------- +% function [R_out,cl_out] = FT_find_radius_for_clipping_loss(cl_in,p,l,w,R_in) +% +% A function for Matlab which attempts to find the required radius of a +% mirror to give a specified clipping loss for a particular LG beam. The +% function uses a fitting function, fminsearch, to try and minimise the +% difference between the actual and required clipping. +% +% cl_in: required clipping loss +% p,l: indices of the LG beam +% w: beam radius at the mirror +% R_in: initial guess for the radius of the mirror. Care +% should be taken when choosing this. If the +% resulting clipping doesn't match the requirements +% well repeat the function using the outputted +% radius, R_out. +% +% R_out: radius required for given clipping, output of the +% fitting routine. +% cl_out: clipping loss given by R_out. +% +% Charlotte Bond 18.12.2010 +%-------------------------------------------------------------------------- + +function [R_out,cl_out] = FT_radius_for_clipping_loss(cl_in,p,l,w,R_in) + + + params=[R_in]; + + + % set options for fminsearch ('help optimset' gives the list of options) + options=optimset('Display','off', 'TolX', 1e-08, 'TolFun',1e-10, 'MaxIter', 10000); + + % create link to test function below + f=@testfunc; + + % run the fitting algorithm + params=fminsearch(f,params,options,cl_in,p,l,w); + + % assign new radius of mirror + R_out=params(1); + + cl_out=FT_LG_clipping_loss(p,l,w,R_out); + +end + + + +% test function for fminsearch +function [y]=testfunc(params,cl_in,p,l,w) + + R=params(1); + + % Use clipping loss function + cl=FT_LG_clipping_loss(p,l,w,R); + + y=abs(cl-cl_in); + +end + + + \ No newline at end of file