function [muo1, mu0]=occultquadVec(p,z,u1,u2,ToPlot,varargin) % Aviv Comments % ================================================== % v.0.32 - vectorize rc,rj,rf % - Allow correcting behaviour near z==p, z=1-p % - Added optinal parameter TolFactor for tolerances control % - Removed all "CloseToOne" and added ToSmooth Parameter %%%%%%%%%%%%%%%% - Mandel Agol comments % % This routine computes the lightcurve for occultation % of a quadratically limb-darkened source without microlensing. % Please cite Mandel & Agol (2002) if you make use of this routine % in your research. Please report errors or bugs to agol@tapir.caltech.edu % implicit none % integer i,nz % double precision z0(nz),u1,u2,p,muo1(nz),mu0(nz), % & mu(nz),lambdad(nz),etad(nz),lambdae(nz),lam, % & pi,x1,x2,x3,z,omega,kap0,kap1,q,Kk,Ek,Pk,n,ellec,ellk,rj % % Input: % % rs radius of the source (set to unity) % z impact parameter in units of rs % p occulting star radius in units of rs % u1 linear limb-darkening coefficient (gamma_1 in paper) % u2 quadratic limb-darkening coefficient (gamma_2 in paper) % % Optional input: % % ToPlot: Graphical output [default=false]; % Tols: A factor controling the three "ERRTOL" parameters for the three helper functions. If given, all three default ERRTOLs wil be scaled by it: [Default =1 ] % ToSmooth: if true, smooths the original Mandel-Agol model around z=p and around abs(z-p)=1 to produce better-behaving derivative. The value themselves are virtually unchanged. [default=true] % % Output: % % muo1 fraction of flux at each z for a limb-darkened source % mu0 fraction of flux at each z for a uniform source % % Limb darkening has the form: % I(r)=[1-u1*(1-sqrt(1-(r/rs)^2))-u2*(1-sqrt(1-(r/rs)^2))^2]/(1-u1/3-u2/6)/pi % % To use this routine % % Now, compute pure occultation curve: % Setting the extra inputs for the case in which only p,z,u1,u2 are given if nargin<5 ToPlot=false; end; TolFactor=1; ToSmooth=true; for i=1:2:numel(varargin) switch lower(varargin{i}) case 'tolfactor' TolFactor=varargin{i+1}; case 'tosmooth' ToSmooth=varargin{i+1}; otherwise fprintf('WARNING: parameter %s is unknown, and so ignored.\n',varargin{i}); end; end; %make z a column vector if size(z,2)>size(z,1) % z is a column vector z=z.'; end; %set zeros to lambdad, lambda3, 3tad, kap0, kap1 lambdad=zeros(size(z)); lambdae=lambdad; etad=lambdad; kap0=lambdad; kap1=lambdad; %if p is close to 0.5, make it 0.5 if abs(p-0.5)<1e-3 p=0.5; end; omega=1-u1/3-u2/6; x1=(p-z).^2; x2=(p+z).^2; x3=p.^2-z.^2; % the source is unocculted: % Table 3, I. i=z>=1+p; if any(i) lambdad(i)=0; etad(i)=0; lambdae(i)=0; end; % the source is partly occulted and the occulting object crosses the limb: % Equation (26): i=z>=abs(1-p) & z<=1+p; if any(i) kap1(i)=acos(min((1-p^2+z(i).^2)/2./z(i),1)); kap0(i)=acos(min((p*p+z(i).^2-1)/2/p./z(i),1)); lambdae(i)=p^2*kap0(i)+kap1(i); lambdae(i)=(lambdae(i)-0.5*sqrt(max(4*z(i).^2-(1+z(i).^2-p^2).^2,0)))/pi; end; % the occulting object transits the source star (but doesn't % completely cover it): i=z<=1-p; if any(i) lambdae(i)=p^2; end; % the edge of the occulting star lies at the origin- special % expressions in this case: i=find(abs(z-p)<1e-4*(z+p)); if ~isempty(i) % Table 3, Case V.: j=z(i)>=0.5; if any(j) %lam=0.5*pi; q=0.5/p; Kk=ellkVec(q); Ek=ellecVec(q); % Equation 34: lambda_3 lambdad(i(j))=1/3+16*p/9/pi*(2*p^2-1)*Ek-(32*p^4-20*p^2+3)/9/pi/p*Kk; % Equation 34: eta_1 etad(i(j))=1/2/pi*(kap1(i(j))+p^2*(p^2+2*z(i(j))).*kap0(i(j))-(1+5*p^2+z(i(j)).^2)./4.*sqrt((1-x1(i(j))).*(x2(i(j))-1))); if p==0.5 % Case VIII: p=1/2, z=1/2 lambdad(i(j))=1/3-4/pi/9; etad(i(j))=3/32; end; end; j=~j; if any(j) % Table 3, Case VI.: %lam=0.5*pi; q=2*p; Kk=ellkVec(q); Ek=ellecVec(q); % Equation 34: lambda_4 lambdad(i(j))=1/3+2/9/pi*(4*(2*p^2-1)*Ek+(1-4*p^2)*Kk); % Equation 34: eta_2 etad(i(j))=p^2/2*(p^2+2*z(i(j)).^2); end end % the occulting star partly occults the source and crosses the limb: % Table 3, Case III: i=find(z>=0.5+abs(p-0.5) & z<1+p | (p>0.5 & z>abs(1-p)*(1+10*eps(1)) & z
10*eps); if any(i) %lam=0.5*pi; q=sqrt((x2(i)-x1(i))./(1-x1(i))); Kk=ellkVec(q); Ek=ellecVec(q); n=x2(i)./x1(i)-1; Pk=Kk-n/3.*rj(0,1-q.^2,1,1+n,TolFactor); % Equation 34, lambda_2: lambdad(i)=2/9/pi./sqrt(1-x1(i)).*((1-5*z(i).^2+p^2+x3(i).^2).*Kk+(1-x1(i)).*(z(i).^2+7*p^2-4).*Ek-3*x3(i)./x1(i).*Pk); j=z(i)
=1
i=z<=p-1;
if any(i)
%lambdad(i)=1;
%etad(i)=1;
%lambdae(i)=1;
muo1(i)=0;
mu0(i)=0;
end;
end
if ToSmooth>0
deg=2;
CorrectionRange=2e-4;
FitRange=5*CorrectionRange;
% i=find(z>=1-p-CorrectionRange & z<=1-p+CorrectionRange); % inner than II/III contact
% if ~isempty(i)
% if p<1
% tmpz=1-p+[linspace(-FitRange,-CorrectionRange,deg*10).'; linspace(CorrectionRange,FitRange,deg*10).'];
% else
% tmpz=p-1+[linspace(-FitRange,-CorrectionRange,deg*10).'; linspace(CorrectionRange,FitRange,deg*10).'];
% end
% tmpz(tmpz<0)=[];
% tmp_muo1=occultquadVec(p,tmpz,u1,u2,0,'ToSmooth',false);
% if ~isempty(tmpz)
% pol=IterativePolyfit(tmpz,tmp_muo1,deg,3);
% muo1(i)=polyval(pol,z(i));
% end
% end;
% inner than II/III contact
i=z>=1-p-CorrectionRange & z<=1-p;
if ~isempty(i)
%if p<1
% tmpz=1-p+linspace(-FitRange,-CorrectionRange,deg*10).';
%else
% tmpz=p-1+linspace(-FitRange,-CorrectionRange,deg*10).';
%end
tmpz=abs(1-p)+linspace(-FitRange,-CorrectionRange,deg*10).';
tmpz(tmpz<0)=[];
tmp_muo1=occultquadVec(p,tmpz,u1,u2,0,'ToSmooth',false);
if ~isempty(tmpz)
pol=polyfit(tmpz,tmp_muo1,deg);
muo1(i)=polyval(pol,z(i));
end
end;
% outer than II/III contact
j=z>=1-p & z<=1-p+CorrectionRange;
if ~isempty(j)
%if p<1
% tmpz=1-p+linspace(CorrectionRange,FitRange,deg*10).';
%else
% tmpz=p-1+linspace(CorrectionRange,FitRange,deg*10).';
%end
tmpz=abs(1-p)+linspace(CorrectionRange,FitRange,deg*10).';
tmpz(tmpz<0)=[];
tmp_muo1=occultquadVec(p,tmpz,u1,u2,0,'ToSmooth',false);
if ~isempty(tmpz)
pol=polyfit(tmpz,tmp_muo1,deg);
muo1(j)=polyval(pol,z(j));
end
end;
% close to z=p
if p>0.5
deg=3;
end;
CorrectionRange=1e-2;
FitRange=5*CorrectionRange;
if p<0.5
i=find(z-p>-CorrectionRange & z-p