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

1 visualización (últimos 30 días)
Sourav Kumar
Sourav Kumar el 11 de Ag. de 2017
Comentada: Walter Roberson el 2 de Nov. de 2023
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 comentarios
Jan
Jan el 12 de Ag. de 2017
Editada: Jan el 12 de Ag. de 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.
Sourav Kumar
Sourav Kumar el 12 de Ag. de 2017
Thanks a lot sir

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 12 de Ag. de 2017
Editada: Jan el 12 de Ag. de 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.

Más respuestas (3)

Matt J
Matt J el 11 de Ag. de 2017
Editada: Matt J el 11 de Ag. de 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 comentarios
Jan
Jan el 11 de Ag. de 2017
Editada: Jan el 11 de Ag. de 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 el 11 de Ag. de 2017
ok, Jan. Thanks for the +1.

Iniciar sesión para comentar.


John BG
John BG el 11 de Ag. de 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 el 2 de Nov. de 2023
plot f(x)=5x+7
  1 comentario
Walter Roberson
Walter Roberson el 2 de Nov. de 2023
What should we look for in that plot to locate the places where floor(x/5) -f loor(x/7) == 1 ?

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by