% use fminsearch for fitting float position data to function
lonref=69;
latref=30;

% vector of initial guess at unknowns:
% z00 r th0 omega w

% initial location of center
lat0 = 29.95;
lon0 = 69.05;
phi = lat0*pi/180;
x00 = 111000/cos(phi)*(lonref-lon0);
y00 = 111000*(lat0-latref);
z00 = x00 + i*y00;
% guess radius in meters
r=8.4e3; 
% initial angle
th0 = 0;
% guess angular velocity of eddy
omega = -1.4e-5;
% initial velocity of eddy
u = -.05;
v = 0; % this way get good (negative) u but zero v
%hmmm now the above gives a value for uout:  0.0131
%v = -0.000001; % this way u and v are both positive
w = u + i*v;

Z0=[z00 r th0 omega w];

options = optimset('MaxFunEvals',1e20,'MaxIter',1e20);
[X,fval,exitflag,output]=fminsearch(@my_fun,Z0,options);

xout = real(X(1));
yout = imag(X(1));
rout = X(2)
th0_out = X(3)
omega_out = X(4)
uout = real(X(5))
vout = imag(X(5))

lon_out = lonref + xout/111000*cos(phi)
lat_out = yout/111000 + latref
