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 Kommentare

Jos (10584)
Jos (10584) am 4 Dez. 2013
Bearbeitet: Jos (10584) am 4 Dez. 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
Vivian am 4 Dez. 2013
Yes,they are computer on the fly. I do not show the f since it is complex and takes time. It just input x and then output is the value of f with the variable x. I know L is wrong , actually is large, since I calculate using a simple data set.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Jos (10584)
Jos (10584) am 4 Dez. 2013
Bearbeitet: Jos (10584) am 4 Dez. 2013

0 Stimmen

Perhaps this is what you really want
if abs(f(x_new)-f(x_old)) < eps
end

1 Kommentar

Vivian
Vivian am 4 Dez. 2013
Hi, thank you, I do not think this is a good idea. I do not try to tell f(x_new)==f(x_old)

Melden Sie sich an, um zu kommentieren.

Andreas Goser
Andreas Goser am 4 Dez. 2013

0 Stimmen

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Tags

Noch keine Tags eingegeben.

Gefragt:

am 4 Dez. 2013

Kommentiert:

am 4 Dez. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by