%% dfpar2.m determines the co-efficients of a Fermi-Dirac function
%% fit to alpha-alpha* and Delta for the He+ flow from 
%% St-Maurice and Schunk, Planet. Space Sci. 1977.

clear

nrat=[1e-3 1e-2 0.05 0.1 0.125 0.25 0.5 1 2 4 8 16 1e2 1e3];

alp=[0.13 0.13 0.12 0.11 0.10 0.08 0.05 0.01 -0.03 -0.06 -0.08 -0.09 -0.10 -0.10];
alps=[1.80 1.79 1.74 1.69 1.67 1.57 1.44 1.30 1.18 1.10 1.05 1.02 1.00 0.99];
del=[0.02 0.02 0.05 0.09 0.10 0.16 0.23 0.31 0.38 0.42 0.45 0.46 0.47 0.48];

acf0=[1.2 -2.4 0 -0.5];
ascf0=[0.6 0 -0.3 -0.5];

lnrat=log10(nrat);

options=optimset('fminsearch');

acf=fminsearch('fdmin',acf0,options,lnrat,(alp-alps));
ascf=fminsearch('fdmin',ascf0,options,lnrat,del);

lnf=linspace(-3,3);
alpf=fedi(acf,lnf);
delf=fedi(ascf,lnf);

figure(1)
plot(lnrat,alp-alps,'s',lnf,alpf)
grid

figure(2)
plot(lnrat,del,'o',lnf,delf)
grid