| 1 | initial version |
Thank-you for the quick answer.
frac() gives a function which is periodic on positive reals. I just adapted your solution to get it periodic on \RR.
f = lambda x: 1 if (x - RR(x).floor()) < 1/2 else 0
I would have liked to be able to define a symbolic function though. Is it doable?
I was also trying to get a function whose plot is correct (without asking it to be pointwise) as it is the case for Piecewise().
Below are some of the things (not chronologically ordred though) I had tried (just for completness as I guess they are just full of beginer's classical mistakes).
f(x)=sum((-1)^k*unit_step(x-k),k,0,infinity)
which does not evaluate
f1(x)=0
f2(x)=1
h=Piecewise([[(-oo,0),f1],[(0,1),f2],[(1,2),f1],[(2,+oo),f1]],x)
h.plot()
returns ValueError: cannot convert float NaN to integer.
f(x)=sum(h(x-2*k),k,0,infinity)
returns ValueError: Value not defined outside of domain.
f(x)=sum(h(x-2*k),k,0,4)
also returns ValueError: Value not defined outside of domain.
I also tried to redefine unit_step:
def echelon_unite(x):
#
if x<0:
hres=0
else:
hres=1
return hres
problem integral(echelon_unite(x),x,-10,3) returns 13
numerical integral returns a coherent result.
Other tentative with incoherent result (still with integrate and not numerical_integral)
def Periodisation_int(f,a,b):
x = var('x')
h0(x) = (x-b)-(b-a)*floor((x-b)/(b-a))
hres = compose(f,h0)
return hres
sage: g=Periodisation_int(sin,0,1)
sage: integrate(g(x),x,0,2)
-cos(1) + 2
sage: integrate(g(x),x,0,1)
-cos(1) + 1
sage: integrate(g(x),x,1,2)
-1/2*cos(1) + 1
My guess is I was using integrate on inappropriate objects. I would still like to know how to define corresponding symbolic function (if it is possible).
Thanks again,
best regards.
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.