Thanks very much, that was exceptionally helpful. These are a nice set of functions and very much appreciated.

Unsurprisingly, calling a loop to gradest for several points inside fminsearch is not the fastest thing in the world, but such are the trade-offs, and it does seem to do the job!

Any thoughts on why this sometimes returns parameter uncertainties = 0 (i.e. dParams(i).du = 0, and dParams(i).lVal = params(i))?

This seems to occur for me in cases where the uncertainties are definitely significant, but are also significantly skewed rather than normally distributed (when tested by Monte Carlo simulation).

I may be missing something obvious here, but is there a clever way to use derivest to calculate a set of partial derivatives?

I have a function something like
f = k1 * x * (1 - exp(-k2*(y^k3)*(z^k4)*(x^k5))
and would like to be able to calculate partial derivatives df/dx, df/dy, and df/dz for sets of specific values of x, y, and z.

I am doing this in order to calculate an error weighting for least squares fitting -- I have uncertainties in x, y, and z which I would like to map onto f in order to determine a weighting factor for the minimization (so I want the gradient at each point). I would prefer to determine the derivative numerically because that will allow me the most flexibility in being able to try different forms of the function, etc.

The help page for FitChiTool is very useful indeed. Please can you provide some similar documentation or perhaps even a tutorial for the ModelEditor? This would make the whole package dramatically more user-friendly, and broadly useful.

@Paddy - I would suggest you try swapping x and y. Matlab has for me a rather annoying habit of defining x as the *second* coordinate, and y as the first. To get your code to work in Paraview, you should just need to swap x and y in your meshgrid call - or use ndgrid which keeps x as the first coordinate.

Could you please show how you calculated your vector field? I calculate a field in Matlab, visualise it with e.g. quiver3 (and looks as expected), but the field looks very different (i.e. wrong) in Paraview after I export it as per your instructions. A simple example of what I am doing is below. I then read the resulting field in as per your instructions, and the resulting plots in paraview aren't correct?
Thanks alot!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% visualise Taylor-Green vortex
clear all;
% coordinates
x = linspace(0,1,100);
y = linspace(0,1,100);
z = linspace(0,1,100);
[xx,yy,zz] = meshgrid(x,y,z);
% x,y,z components of vector field
u = sin(pi*xx).*cos(pi*yy).*cos(pi*zz);
v = -cos(pi*xx).*sin(pi*yy).*cos(pi*zz);
w = sqrt(2/3).*cos(pi*xx).*cos(pi*yy).*sin(pi*zz);
% write for paraview
V = cat(4,u,v,w);
B = permute(V,[4 1 2 3]);
fid = fopen('V.raw','w');
fwrite(fid,V,'float');
fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Comment only