The function at [0,2] is y=x for [0,1] and y=2-x for [1,2], I want the above function repeated at [2,10], so I need a periodic funtion in the whole [0,10], who can help me code it ,thank you.
Since you are making a periodic function, the mod(x,2) simply puts all of the input values into the range of one cycle. From there it is just a matter of forming the proper outputs of one cycle. The y=x part for the [0,1] input didn't need any adjustment so no extra code for that. Only the [1,2] part needed the extra code.
For this new function, you simply need to scale the x input properly and then use the same algorithm. E.g.,
As I can see in the help document, mod has the function similar to division ,but not as you said. What is the reason?
mod
Modulus after division
Syntax
M = mod(X,Y)
Description
M = mod(X,Y) if Y ~= 0, returns X - n.*Y where n = floor(X./Y). If Y is not an integer and the quotient X./Y is within roundoff error of an integer, then n is that integer. The inputs X and Y must be real arrays of the same size, or real scalars.
The following are true by convention:
mod(X,0) is X
mod(X,X) is 0
mod(X,Y) for X~=Y and Y~=0 has the same sign as Y.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
0 Comments
Sign in to comment.