Background (for interest/flavour): I'm writing a routine to extract certain physical parameters from a set of x-ray spectroscopy data. There are 7 parameters to be fitted; 3 (Dq, Dsigma, Dtau) relate the position and intensity of the spectral lines to the local symmetry of the crystal being studied (D3d in this case), 3 (sigma, gamma, frac) describe the shape of the spectral lines using a Pseudo-Voigt function, leaving 1 (mag) which scales the entire model to match the data set.
Problem: Currently, the function to be minimized is as follows
D3dDataFit[Dq1_, Dtau1_, Dsigma1_, sigma_, gamma_, frac_, mag_, x0_,
FitData_] :=
Module[{cf, model},
cf = Eigensystem[
CrystalFieldMatrix /. {Dq -> Dq1, Dtau -> Dtau1,
Dsigma -> Dsigma1}];
model = Sum[
mag ((1./3.) (cf2[[2, i, 7]])^2 + (2./3.) (cf2[[2, i, 6]])^2)
((1. - frac) Exp[-(x - (x0 + cf2[[1, i]]))^2/(2. sigma^2)]/(sigma 2.506628) +
frac gamma/(Pi ((x - (x0 + cf2[[1, i]]))^2 + gamma^2))), {i, 1, 40}];
Sum[((model /. {x -> FitData[[i]][[1]]}) - FitData[[i]][[2]])^2, {i, 1, Length[FitData]}]]
where x0 is the centre of weight of the spectrum (supplied by the user) and FitData is the experimental spectrum. CrystalFieldMatrix is a 40x40 matrix (the Hamiltonian of the system), which as can be seen is dependent on Dq, Dtau and Dsigma as arguments. The whole function normally takes about 0.14 seconds to run using about 140 points of data. My problem is twofold; Firstly, I would like to speed up the evaluation of D3dDataFit. Finding the Eigensystem takes Mathematica about 0.004 seconds and I would have thought that it would comprise the most computationally intensive part of the problem. Secondly, and more seriously, I would like to be able to minimize D3dDataFit automatically using NMinimize or similar, however whenever I try to do so I have always had to abort the evaluation after several hours when my computer becomes intolerably slow. Even after setting the "SamplePoints" and "Max Iterations" options to 1, and fixing sigma, gamma and frac, NMinimize is still evaluating after 40 minutes. I feel that NMinimize would never finish evaluating even if I let it run indefinitely, although I am not sure why, and I don't have any ideas to speed it up.
Any advice on solving these problems would be greatly appreciated!