I want to plot a function that is abs(x) for -1<= x <= 1 and repeats to create a sawtooth shaped function. With the code
def h(x):
while x>1:
x=x-2
return abs(x)
h(4.3)
The Sage sell server tells me the value is 0.300000000000000, which is what I want as h(4.3)=h(2.3)=h(.3)=abs(.3) However, when I tried to plot h(x) with
def h(x):
while x>1:
x=x-2
return abs(x)
plot(h(x),x,0,5)
The plot looks like abs(x), so that h(4.3) now appears to be 4.3. What has gone wrong? How can I properly plot the h(x) I want?