I have previously asked a similar question here but I've changed my code slightly and I'm now having a new issue so I thought I'd try again.

I have a dataset to which I am trying to fit the following equation:

f(t) = (wpmcoeff./(t.^2)) + ((1.038+3.*log(2.*pi.*1e6.*t)).*fpmcoeff./(t.^2))+(wfmcoeff./t) + (ffmcoeff)+(rwfmcoeff.*t).

My code is as follows:

```
clock='atomicclockgpsworld.txt';
data=importdata(clock);
sig=data(:,2);
t=data(:,1);
fh=1e6;
carrier=10e6;
sigsq=sig.^2;
fun = @(coeff)sseval(coeff,t,sigsq);
x0 = 1e-25.*rand(1,5);
%creates a random staring point
ub = [1,1,1,1,1];
%coefficients are all <1
lb = [realmin,realmin,realmin,realmin,realmin];
%coefficients are all >0
options = optimoptions(@fmincon,'ConstraintTolerance',1e-10,'OptimalityTolerance',1e-10,'StepTolerance',1e-10);
%I'm not entirely sure what the tolerances should be but they don't seem to make much difference to my result
bestx = double(fmincon(fun,x0,[],[],[],[],lb,ub,[],options));
wpmcoeff = bestx(1);
fpmcoeff = bestx(2);
wfmcoeff = bestx(3);
ffmcoeff = bestx(4);
rwfmcoeff = bestx(5);
x=logspace(0,5,114);
yfit=(wpmcoeff./(x.^2))+((1.038+3.*log(2.*pi.*1e6.*x)).*fpmcoeff./(x.^2))+(wfmcoeff./x)+(ffmcoeff)+(rwfmcoeff.*x);
figure
loglog(t,sigsq,'.');
hold on
loglog(x,yfit);
legend('true data','best fit');
saveas(gcf,'sigsqfitted','png');
```

At this point, the plot that is created shows a curve which almost looks like the curve I want but reflected about x~500! Therefore I tried to use the following method to reflect the curve I'd created and then tried again to fit the reflected curve to my equation to see if I could get a better fit to my data..

```
for i=1:114
yfitm(i)=yfit(115-i);
end
loglog(t,sigsq,'.');
hold on
loglog(x,yfitm);
legend('true data','best fit');
fun2=@(coeff)sseval(coeff,x,yfitm);
bestx2 = double(fmincon(fun2,x0,[],[],[],[],lb,ub,[],options));
wpmcoeff = bestx2(1);
fpmcoeff = bestx2(2);
wfmcoeff = bestx2(3);
ffmcoeff = bestx2(4);
rwfmcoeff = bestx2(5);
yfit2=(wpmcoeff./(x.^2))+((1.038+3.*log(2.*pi.*1e6.*x)).*fpmcoeff./(x.^2))+(wfmcoeff./x)+(ffmcoeff)+(rwfmcoeff.*x);
loglog(t,sigsq,'.');
hold on
loglog(x,yfitm);
hold on
loglog(x,yfit2);
```

Here is my function sseval:

```
function sse = sseval(coeff,t,sigsq)
wpmcoeff = coeff(1);
fpmcoeff = coeff(2);
wfmcoeff = coeff(3);
ffmcoeff = coeff(4);
rwfmcoeff = coeff(5);
sse = sum((sigsq - ((wpmcoeff./(t.^2))+((1.038+3.*log(2.*pi.*1e6.*t)).*fpmcoeff./(t.^2))+(wfmcoeff./t)+(ffmcoeff)+(rwfmcoeff.*t))).^2);
end
```

Here is my dataset. Any advice as to why the fitted curve seems to be in the wrong place would be very much appreciated!