Could I trust Matlab?
Afficher commentaires plus anciens
Hello, I recently write a code and debug it.
I have a key sentence,
if true
% code
end while 1
...
if f(x_new)-f(x_old)<0
break;
elseif
L=1.1*L;
...
end
But it seems that the returned L is always wrong. And it always happened when f(x_new)-f(x_old)=1e-20. So I doubt maybe it should that f(x_new)<f(x_old), but the returned values is a little wrong to lead f(x_new)-f(x_old)=1e-20.
Could this thing happen in matlab.
Thank you in advance. I have already spent a lot time on it.
2 commentaires
Jos (10584)
le 4 Déc 2013
Modifié(e) : Jos (10584)
le 4 Déc 2013
Based on this snippet, I have no idea what f, L, x_new and x_old are doing inside the loop. Are they being updated on the fly? And how do you know the returned L is wrong?
The elseif statement also seems out of place ...
Vivian
le 4 Déc 2013
Réponses (2)
Jos (10584)
le 4 Déc 2013
Modifié(e) : Jos (10584)
le 4 Déc 2013
Perhaps this is what you really want
if abs(f(x_new)-f(x_old)) < eps
…
end
1 commentaire
Vivian
le 4 Déc 2013
Andreas Goser
le 4 Déc 2013
0 votes
Looks like yet another flavor of the numerical question with the highest volume: http://www.mathworks.com/matlabcentral/answers/102419-how-do-i-determine-if-the-error-in-my-answer-is-the-result-of-round-off-error-or-a-bug
1 commentaire
Vivian
le 4 Déc 2013
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!