On 6/8/07, Anssi Seppälä <[EMAIL PROTECTED]> wrote:
Dear J folks,
I have a problem: I have monthly average temperatures and I need
interpolate daily values and I like to have a beautiful cyclic curve
fitting and resulting almiost the same monthly averages. It is
allowed to assume that all months are 30 days.
The monthly averages are in Centrigrades: tave=:_7.3 _6.6 _1.8 3.6
11.1 17.1 19.8 11.3 4.7 _1.3 _5.0
There's all kinds of curve fitting.
For example, here's a fairly trivial fit that might or might not be
close to what you are looking for:
extend=: +/ .*&2 _1@(2&{.) , ] , +/ .*&_1 2@(_2&{.)
zero=: {. -:@+ {:
ct=: 2 o. 1r29p1*i.30
fit=: 15 }. _15 }. [: , 2&((zero + ct * zero - {:)\)@extend
Here's a somewhat different approach, emphasizing appearance:
arbitraryConstant=:300
curve=:3 :0
rough=.30#y
basis=.^((*-) -/~ i.#rough)%arbitraryConstant
shape=.basis +/ .*basis%.rough
max=.(i.>./)|shape
shape*rough%&(max&{)shape
)
Contrast:
plot (curve tave),(fit tave),:30#tave
(As an aside, I'm no expert on curve fitting issues.)
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm