Doubt in a product erro

2 visualizaciones (últimos 30 días)
Nélio Dias
Nélio Dias el 2 de Abr. de 2021
Comentada: Sulaymon Eshkabilov el 4 de Abr. de 2021
Hi, I have wrinting a code e get a 1×0 empty double row vector error
So, what I wrote:
t1 = 0:0.01:300;
pmenor = 25*0.9;
pmaior = 25*(1.1);
idx1 = find(t1== pmenor);
idx2 = find(t1 == pmaior);
I got
idx2 =
1×0 empty double row vector
But, if I write:
idx2 = find(t1 == 27.5);
idx2 =
2751
So I dont understand the error since idx1 gives me the correct answer, because we know that 25*1.1 = 27.5.
Thanks for reading.

Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 2 de Abr. de 2021
Editada: Sulaymon Eshkabilov el 2 de Abr. de 2021
Here is a small correction to obtain the correct answers in your exercise:
t1 = 0:0.01:300;
N = 2; % Number of decimal digits to be rounded, e.g.: N = 2 or 3 or 5, etc.
pmenor = round(25*0.9, N);
pmaior = round(25*(1.1), N);
idx1 = find(t1== pmenor);
idx2 = find(t1 == pmaior);
  2 comentarios
Nélio Dias
Nélio Dias el 4 de Abr. de 2021
Thanks for the help.
Sulaymon Eshkabilov
Sulaymon Eshkabilov el 4 de Abr. de 2021
You are welcome - it is a pleasure.

Iniciar sesión para comentar.

Más respuestas (1)

the cyclist
the cyclist el 2 de Abr. de 2021
The reason has to do with the accuracy of floating-point math on a binary computer. I suggest you read this question and answer, to get a better understanding of what is going on.
  1 comentario
Nélio Dias
Nélio Dias el 4 de Abr. de 2021
Thanks for the sugestion

Iniciar sesión para comentar.

Categorías

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

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by