Interpolation, keep average over certain range to fixed value
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hey :) I have some data for the monthly averages of a certain parameter.
Now I would like to create some varying data for the individual days of the year from this. I need it in order to have some varying inputs for a dynamic simulation. The values should not be scattered chaotically but somewhat continuous transition from one value to the next. I thought I could do so by using interpolation or fitting a curve to this data. However, the problem is that I need for the integral of each month (hence the average of the values of the respective month) to stay as the provided averages.
Is there any way to do such a thing in Matlab? I was thinking of creating a piecewise polynomial or interpolation data somehow, but i don't know how to keep it to the fixed average value.
I tried 1-D interpolation, but the average values of the month didn't stay the same:
clear all
clc
x = [0 31 59 90 120 151 181 212 243 273 304 334 365]
v = [1000 2000 500 300 700 1200 1400 1500 1100 1200 1000 800 800] %average value of that month
stairs(x,v) %this is how the data currently looks.
%average is used for each day of the month
v(13)=[] %deletes value, was only used for depiction
xq = 1:1:365
for i=1:length(x)-1
middle(i)=x(i+1)-0.5*(x(i+1)-x(i)) %middles of the months
end
figure
vq1 = interp1(middle,v,xq)
vq2 = interp1(middle,v,xq,'spline')
vq3 = interp1(middle,v,xq,'v5cubic')
plot(middle,v,'o',xq,vq1,':.',xq,vq2,'x',xq,vq3);
I hope it is clear what I mean.
Thanks for any input! :)
0 Commenti
Risposte (2)
John D'Errico
il 14 Set 2017
Sorry. But interpolation tools (including any that I have ever written) do not allow a constraint that lets you tell it to maintain the average over one or more specific time period(s). That does not mean you could not do so, but you would need to develop an interpolating spline code of some sort with that constraint explicitly implemented.
If you do write your own, be careful with a simple piecewise approximation, as you may wish to require the interpolant to be continuous, or even differentiable. This requires more than simply creating a set of functions that apply over segments. You will need to learn to tie them together, as in a spline.
Simon Schraml
il 14 Set 2017
1 Commento
Michael König
il 7 Mag 2020
Hey, just out of curiosity - did you figure out a solution for your problem? I'm working on something that might require a similar solution. I have mean speeds of a car driving between scattered points along a route and want to interpolate a continous function with transmissions between those means around the waypoints at which the driving time and distance was taken. Did you figure something out that could help me in any way?
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

