Here is an old utility of mine:

    saw     =:  ] - 2 * [: <. 0.5 + 0.5 * ]  NB. sawtooth function, period 2

NB.  f @: saw is periodic with period 2 and agrees with
NB.  f on the interval _1 upto 1.  f @: (3 * saw @: (3 %~ ]))
NB.  is periodic with period 6 and agrees with f on the
NB.  interval _3 upto 3.  (  saw  itself is periodic with period 2 and
NB.  agrees with the identity function on the interval _1 upto 1.)

NB. Now, suppose

    tent =: 1 - |

NB. Try

    plot _1 1 ; 'tent y'
    plot _1 3; 'tent@:saw y'


The first plot will look like
    .
   / \
  /   \
_1    1

and the second,
    .    .
   / \  / \
  /   \/   \
_1         3

With a little adjusting, you can get what you want:

    plot 0 2;'0.25*tent@:saw@:(_1 + 2*]) y'


On 8/28/2011 11:03 AM, Henry Rich wrote:
> The function as spec'd had domain 0-1.  As used, it needs infinite
> domain.  From your reference, it should be
>
>      tent =: -:@:(|&.(0.5&-))@:(1&|)
>      (,: tent) 0.25 * i: 6
> _1.5 _1.25 _1 _0.75 _0.5 _0.25 0  0.25  0.5  0.75 1  1.25  1.5
> 0.25 0.125  0 0.125 0.25 0.125 0 0.125 0.25 0.125 0 0.125 0.25
>
> Then the infinite sum would be
>
>      INFINITY =: 32
>      h =: ([: +/ tent&.(*&(2 ^ i. INFINITY)))"0
>
> which you can see with
>
>      load 'plot'
>      plot 0 1 10000 ; 'h y'
>
>
> Alas,
>      plot 0 1; 'h y'
>
> fails.
>
> Henry Rich
>
> On 8/28/2011 11:21 AM, Roger Hui wrote:
>> The infinite sum looks OK to me.
>> http://en.wikipedia.org/wiki/Blancmange_curve
>>
>>
>>
>> ----- Original Message -----
>> From: Henry Rich<[email protected]>
>> Date: Sunday, August 28, 2011 8:01
>> Subject: Re: [Jprogramming] a new question
>> To: Programming forum<[email protected]>
>>
>>> With infinite rank:
>>>
>>>       tent =: -:@:(|&.(0.5&-))
>>>       tent _0.1 0 0.1 0.2 0.3 0.5 0.7 0.8 0.9 1 1.1
>>> _0.05 0 0.05 0.1 0.15 0.25 0.15 0.1 0.05 0 _0.05
>>>
>>> I got nothin' on the infinite sum (which looks to me like it has
>>> a typo
>>> in the spec)
>>>
>>> Henry Rich
>>>
>>> On 8/28/2011 10:38 AM, Marshall Lochbaum wrote:
>>>> How about
>>>>
>>>>        tent=: 0>. [:-: -.^:(>&0.5)"0
>>>>        tent _0.1 0 0.1 0.2 0.3 0.5 0.7 0.8
>>> 0.9 1 1.1
>>>> 0 0 0.05 0.1 0.15 0.25 0.15 0.1 0.05 0 0
>>>>
>>>> Marshall
>>>>
>>>> On Sun, Aug 28, 2011 at 7:47 AM, Ric
>>> Sherlock<[email protected]>    wrote:
>>>>
>>>>> Here's one tacit approach to the tent function:
>>>>>       tent=: 0:`-:`(-:@-.)`0:@.(0 0.5 1&I.)"0
>>>>>       tent _0.1 0 0.1 0.2 0.3 0.5 0.7 0.8 0.9 1 1.1
>>>>> 0 0 0.05 0.1 0.15 0.25 0.15 0.1 0.05 0 0
>>>>>
>>>>> Given it is rank 0 I expect its performance can be improved. Also
>>>>> although dyadic I. appears to work in this case, it doesn't
>>> strictly>>   follow the 0<=x condition below.
>>>>>
>>>>> On Sun, Aug 28, 2011 at 10:40 PM, mikel
>>> paternain<[email protected]>>>   wrote:
>>>>>>
>>>>>> How do you write in J a "tent" function:
>>>>>>
>>>>>> g(x)=
>>> x/2                if 0<=x<=1/2,
>>>>>>
>>> (1-x)/2            if 1/2<    x<    1
>>>>>>
>>>>>> and, more important, How do you write in J a Takagi function
>>> with the
>>>>> "tent" function:
>>>>>>
>>>>>> h(x)= Sum [r=0 to infinite,  g(2^r x)/2^r]
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to