MATLAB: Fitting curve to two points

curvecurve fittingscript

I have this daily load curve " f(x)=342.8+(-4.141*cos(x*0.261))+(-60.26*sin(x*0.261))+(43.46*cos(2*x*0.261))+(-21.9*sin(x*0.261*2)) " I also have data for the two peaks of each day, (ie the two local maxima) with no relation to time.That looks like this:
Day 1 Morning Max 800 Afternoon Max 860 Day 2 Morning Max 900 Afternoon Max 990
I need to adjust the coefficients so that the curve passes through or as close as possible to the data points. I need this to be done for every day for 3 months, so it has to be automated. Any ideas? Thanks in advance.

Best Answer

Here's the rub...
When you fit a second order Fourier series, you're estimating values for six different regression coefficients.
In this example you know that
  1. The location of data point 1
  2. The location of data point 2
  3. Data point 1 is a local maximum (the derivative is equal to zero)
  4. Data point 2 is a local maximum (the derivative is equal to zero)
I don't think that you have enough information to generate a unique solution.
Please note: If the fully parameterized daily load curve that you specified has some kind of real world meaning this might allow you to solve your problem. You'd need to design a custom objective function that minimizes some kind of error term between your new coefficients and the existing coefficients, subject to the constraint that data point 1 and data point 2 are local maxima.