%% dfpar.m determines the co-efficients of a Fermi-Dirac function
%% fit to alpha-alpha* and Delta for the H+ 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.03 0.03 0.03 0.02 0.02 0.01 0 -0.01 -0.02 -0.03 -0.03 -0.03 -0.03 -0.03];
alps=[2.41 2.39 2.29 2.19 2.14 1.97 1.75 1.54 1.37 1.26 1.2 1.17 1.13 1.13];
del=[0 0.01 0.06 0.11 0.14 0.22 0.33 0.43 0.52 0.57 0.6 0.62 0.63 0.64];

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