The problem is, that is not your code. Not all of it. That is just how you call lsqcurvefit. We do not see the pandemic1Dall2 code, nor do we have your data.
What I cannot be sure of is if your function really is deterministic. I've seen many people claim that their function is deterministic, when it is not, since something inside their code uses random numbers. Sometimes they used something in MATLAB that uses something random as a starting value. For example, eigs and svds are not deterministic. fit from the curve fitting toolbox is not, when used wihout starting values.
Is lsqcurvefit deterministic? Yes, I am pretty sure that it is. A quick test that I just ran shows results for consecutive calls to be identical to every single bit of the result on a simple 4 parameter problem.
If you will not show us what we need to determine if you are using something that is not in fact deterministic, then all I can suggest is you do a few simple tests:
- Call your function (fun) TWICE, with the same set of values as coefficients. Do not reset the random seed in MATLAB between calls.
- Compare the two sets of results from fun. Are they IDENTICALLY equal, down to the least significant bit?
This completely isolates the problem from lsqcurvefit. If they are not identical, then you have your answer. Your function is not indeed deterministic.
Next, perform the same operation, but now setting the random seed for MATLAB before each call to a fixed known number. Again, compare the results after each call.
This second test, even if your function was not deterministic, should now return the same results.
You can also perform the same pair of tests, but now calling lsqcurvefit too. But if your function is deterministic, then lscurvefit is too. I am confidant that lsqcurvefit is deterministic, and I have seen no indications it is not. For example, if you search the code for lsqcurvefit, the string "rand" (or any other random number generator in MATLAB) is NOT to be found in the code.
As well, depite the fact that lsqcurvefit "can" be sensitive to starting values, if you pass it exactly the same inputs, there is noting in it that will ever return any different result.
So, next, make sure that ALL data was identical between calls. Far too often I have seen people not realize that something was not indeed identical, even though being willing to swear on a stack of bibles that they had done exactly the same thing.
For example, it is terribly common for someone to use a set of numbers from one computation in their code. Then they copy those numbers from the command window, using them again, or so they think. But in fact, when they do that, they only copy a short approximation to the numbers, since what appears in the command window is only correct to 4 significant digits. Then they get upset, not understanding why they got different results. It happens all the time.
But if you want a better answer, then you really need to provide both your data AND all of your code for this problem.