Clear Filters
Clear Filters

Solve: floor(x/5) - floor(x/7) = 1 in Matlab

1 view (last 30 days)
Sir/Mam, i want to find all the solutions of the equation: floor(x/5) - floor(x/7) = 1 ;where x belongs to Natural Number, so how can i find all its solutions in Matlab? with Thanks
  11 Comments
Jan
Jan on 12 Aug 2017
Edited: Jan on 12 Aug 2017
@Sourav: This is not a link. John inserts his name and email address several times in each of his messages. He includes the mail address in < and > characters, such that they are displayed as a link in the forum, which is confusing.
The idea of the forum is to solve problems in public and you do not have to contact contributors personally by email.

Sign in to comment.

Accepted Answer

Jan
Jan on 12 Aug 2017
Edited: Jan on 12 Aug 2017
Okay, if this is not a homework, than you find enough information here to solve the problem already. I summarize:
  • Matt J showed, that the results must be 0 <= x <= 35.
  • You can easily check all values:
x = 0:35;
match = (floor(x / 5) - floor(x / 7) == 1);
result = x(match)
And here you get your 17 values.

More Answers (3)

Matt J
Matt J on 11 Aug 2017
Edited: Matt J on 11 Aug 2017
As I mentioned, the solutions are going to be uncountable because F(x) = floor(x/5) - floor(x/7) is a piecewise constant function of x. However, from a little analysis, we know that they must lie in the interval [0,35]. To see this, note that we have the bounds
x/5-x/7 +1 >= floor(x/5) - floor(x/7) >= (x/5-x/7)-1
The upper bound is less than 1 for all x<0 and the lower bound is greater than 1 for all x>35.
Also, F(x) can only change value at multiples of 5 or 7. So, the solution reduces to a search over
xSet=sort([0:5:35, 0:7:35]);
Once you find the subset of solutions xCritical,
xCritical = xSet( floor(xSet/5)-floor(xSet/7) ==1 )
it is a simple matter to look at the full intervals bounded by xSet to see which ones constitute solutions.
  4 Comments
Jan
Jan on 11 Aug 2017
Edited: Jan on 11 Aug 2017
@Matt J: I did not see your 2nd last comment, when I typed mine.
I thought about more complicated functions, when a search over all numbers is impossible, and then I've overseen, that this looks like a homework.
I've removed my answer and comment. +1 for yours, with the constraint the "the solution reduces to a search over [xSet]" sounds like this is the full set of results.
Matt J
Matt J on 11 Aug 2017
ok, Jan. Thanks for the +1.

Sign in to comment.


John BG
John BG on 11 Aug 2017
Hi Sourav Kumar
x=[1:1:17]
nonzeros(x.*((floor(x/5)-floor(x/7))==1))
=
5
6
10
11
12
13
15
16
17
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG

Ashen
Ashen on 2 Nov 2023
plot f(x)=5x+7
  1 Comment
Walter Roberson
Walter Roberson on 2 Nov 2023
What should we look for in that plot to locate the places where floor(x/5) -f loor(x/7) == 1 ?

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!