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

1 回表示 (過去 30 日間)
Sourav Kumar
Sourav Kumar 2017 年 8 月 11 日
コメント済み: Walter Roberson 2023 年 11 月 2 日
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.
Sourav Kumar
Sourav Kumar 2017 年 8 月 12 日
Thanks a lot sir

サインインしてコメントする。

採用された回答

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.
Matt J
Matt J 2017 年 8 月 11 日
ok, Jan. Thanks for the +1.

サインインしてコメントする。


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 Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by