fitting curve to two points

9 views (last 30 days)
d s.
d s. on 24 Feb 2012
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.

Accepted Answer

Richard Willey
Richard Willey on 27 Feb 2012
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.
  1 Comment
d s.
d s. on 28 Feb 2012
Thank you for your reply. I will try a different approach and get back to this if else fails. I am not closing this thread yet as I might need your help again.

Sign in to comment.

More Answers (1)

Richard Willey
Richard Willey on 24 Feb 2012
From the looks of things, your daily load curve is a particular example of a second order Fourier series.
If you have Curve Fitting Toolbox, its pretty easy to generate a fit. If you don't have Curve Fitting Toolbox, you can solve this same equation using nlinfit in Stats or lsqcurvefit in Optim. However, in either case you'll need to provide starting conditions. (Curve Fitting Toolbox is able to automatically compute the starting conditions for the solvers)
%%Generate a set of random data
X = linspace(1,10,100);
X = X';
% Specify the parameters for a second order Fourier series
w = .6067;
a0 = 1.6345;
a1 = -.6235;
b1 = -1.3501;
a2 = -1.1622;
b2 = -.9443;
Y = a0 + a1*cos(X*w) + b1*sin(X*w) + a2*cos(2*X*w) + b2*sin(2*X*w);
foo = fit(X,Y, 'Fourier2')
Please note: You mention that the only data points that you have available are the peaks in the data series. I'd be leery about using the resulting model to predict anything other than the peak load...
  1 Comment
d s.
d s. on 24 Feb 2012
Thank you so much for your reply. I am sorry but I think I didnt explain properly or I didnt understand your answer completely. The daily curve I have is indeed a second order Fourrier series that I got from the curve fitting tool. The curve represents the electrical consumption of a day so it has 24 values on the x axis (one measurement per hour). The data I have and I want to fit the curve to, are only two points per day and specifically the two local maxima. I mean the data I have is not continuous as the data generated with linspace, it is just two points per curve. And because images explain better than words http://imgur.com/RmzKO all that I need to do is to make the green dots fit the red ones with no time shift. Thanks again.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!