% Hua-sheng XIE, huashengxie@gmail.com, IFTS-ZJU, 2012-01-10 14:01
% On Numerical Calculation of the Plasma Dispersion Function, section 10.3
% http://ifts.zju.edu.cn/forum/viewtopic.php?f=18&t=527,bump-on-tail
clear;clc;
Ti=1; % Tb/Te
mi=1836; % vd/vtb
zeta=@(x)faddeeva(x)*1i*sqrt(pi);
f=@(x,k)k*k+(1+x*zeta(x))+1/Ti*(1+(x/sqrt(Ti/mi))*zeta(x/sqrt(Ti/mi)));
w=[];

kmin=0.95;dk=0.05;kmax=1.1;
k=[kmin:dk:kmax];
% x0=(1.0-0.0i)*sqrt(2)*kmin;
x0=1.2-0.5i;
% x0=0.04-0.02i;
for kk=k
    options=optimset('Display','off');
    x=fsolve(f,x0,options,kk)*sqrt(2)*kk;
    x0=x;
    w=[w,x];
end
wre=real(w);wie=imag(w);
plot(k,wre,'r+',k,wie,'.');
grid on;
% title(['Bump-on-tail, n_b=',num2str(nb),', T_b/T_e=',...
%     num2str(Tb),', v_d=',num2str(vd)]);
xlabel('k\lambda_D');ylabel('\gamma/\omega_p'); % wp^2=wpe^2+wpb^2
xlim([kmin,kmax]);
% ylim([-0.08,0.08]);

%%
title(['k=',num2str(k(2)),', \omega=',num2str(w(2))])

print('-dpng',['IAW_mi',num2str(mi),'_Ti',num2str(Ti),'.png']);

