Write a function m-file which given any real x returns f(x) (Hint: the floor function may help here).

A periodic function with period 3 is defined on the interval 0 ≤ x ≤ 3 by:
f(x) = 2sqrt(x), for 0 x ≤ 1
f(x) = 3-x, for 1 x ≤ 3
QUESTION: Write a function m-file which given any real x returns f(x) (Hint: the floor function may help here).

1 Comment

Set - what is your question? This homework question seems straightforward, but is there something in particular that you are getting stuck on? Concentrate first on writing your function for the interval [0,3], and once you have that working, then try to figure out how the period of the function can be used for other inputs.

Sign in to comment.

Answers (1)

I would think the rem() function would be better than floor. For example if you wanted to pass in 34.567, it should give the same f(x) output as 1.567.
>> rem(34.567, 3)
ans =
1.567

Categories

Find more on Programming in Help Center and File Exchange

Asked:

Sey
on 26 Nov 2014

Answered:

on 27 Nov 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!