Problems with while loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Tamia Eli
el 30 de Ag. de 2020
Comentada: Tamia Eli
el 31 de Ag. de 2020
Hi, I have a problem, I want the subtraction d1 to be less than 1 * 10 ^ -15 after several iterations, but the program stays busy.
2 comentarios
James Tursa
el 31 de Ag. de 2020
Please post your code as regular text and highlight it with the CODE button. We can't run pictures.
Respuesta aceptada
Bruno Luong
el 31 de Ag. de 2020
Editada: Bruno Luong
el 31 de Ag. de 2020
"Hi, I have a problem, I want the subtraction d1 to be less than 1 * 10 ^ -15 after several iterations, but the program stays busy."
Well you cannot demand floating point error to be that small.
Double IEEE has about 15 digits relative precision. You compare B1 to (y/k0) which is -7699432.66755457. The most you can demand is error is about
>> tol = eps(y/k0)
tol =
9.31322574615479e-10
So if you replace the break condition by
tol = eps(y/k0);
while tt>tol
...
end
your while loop will stop.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!