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

1 次查看(过去 30 天)
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 个评论
Jan
Jan 2017-8-12
编辑:Jan 2017-8-12
@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.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2017-8-12
编辑:Jan 2017-8-12
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.

更多回答(3 个)

Matt J
Matt J 2017-8-11
编辑:Matt J 2017-8-11
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 个评论
Jan
Jan 2017-8-11
编辑:Jan 2017-8-11
@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.

请先登录,再进行评论。


John BG
John BG 2017-8-11
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 2023-11-2
plot f(x)=5x+7
  1 个评论
Walter Roberson
Walter Roberson 2023-11-2
What should we look for in that plot to locate the places where floor(x/5) -f loor(x/7) == 1 ?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by