Hi Mikel,
This was not a function I had seen before. Very interesting.
Here is a solution although I think there must be other nicer ones.
I'll leave that to the forum.
Best, Cliff

Try the following:

NB. 4 quick ideas for tent function
load 'plot'
NB. use control structures
g1=: 3 : 'if. y<: 0.5 do. -:y else. -:-.y end.'"0
plot (;g1) 0.01*i.101
NB. use agenda @.
g2=: -:`(-:@-.)@.(>&0.5)"0
plot (;g2) 0.01*i.101
NB. use absolute value and arithmetic
g3=:0.25&*@:-.@:+:@:|@:(-&0.5)
plot (;g3) 0.01*i.101

NB. but you need domain 0 to _ so use 1&|
g=:-:@:|@:(1&|&.(0.5&-))
plot (;g) 0.01*i.101
plot (;g) 0.01*i.1001

NB. left (adverb) argument is number of terms
h=:1 : 0("0)
r=.2^i.m
+/(g y*r)%r
)

plot 2 h  0.01*i.101
plot 100 h  0.01*i.101
plot 100 h  0.001*i.1001




On 8/28/2011 6:40 AM, mikel paternain 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
>

-- 
Clifford A. Reiter
Lafayette College, Easton, PA 18042
http://webbox.lafayette.edu/~reiterc/

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to