0
votes

I'm trying to create a periodic function but I get:

MethodError: no method matching

##   Defining the drift function
function drift_a(x)
    if  0<=x<2/3
        return 2/7-x-2/7*(1-3*x)*sqrt(abs(1-3*x))
    end
    if  2/3<=x<=1
        return -2/7+2/7*x
    end
end

function drift_b(x)
    return 12*(drift_a(x-floor(x))+0.05)
end

print(drift_b(0.5))
print(drift_b(10.5-floor(10.5)))
print(drift_b(10.5))

I'm new to Julia so I don't understand why it throws an error. I have tried creating a placeholder variable y = x-floor(x) and using the function on y instead, but it gives the same error.

1
did you want function drift_a(x) y is never referred to in drift_aOscar Smith
that was a typo from trying to use y = x-floor(x), it has been corrected nowSimon Chemnitz-Thomsen

1 Answers

1
votes

fixed it using mod instead

function drift_b(x)
    return 12*(drift_a(mod(x,1))+0.05)
end