Re: endless loop problem [message #68953] |
Sun, 06 December 2009 18:21 |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Dec 6, 11:20 pm, Elkunn <wasit.weat...@gmail.com> wrote:
> On Dec 6, 5:52 pm, David Fanning <n...@dfanning.com> wrote:
>
>
>
>> pp writes:
>
>> .
>
>>> L does not change because you are calculating the same thing over and
>>> over again. L only depends on EC[0] and EC[1], and neither changes
>>> when you go through the loop. So if L does not happen to be
>>> <1.2840277, the loop will never end.
>
>> And it is not likely that it will *ever* be 1.2840277!
>
>> http://www.dfanning.com//math_tips/sky_is_falling.html
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> I should have given more explanations on this. L changes over each
> iteration. There is no problem. I missed one letter, here is the
> corrected one.
> ;E1 = Unit vector, known
> ; Z is known matrix
> REPEAT BEGIN
> EC = Z##E1
> L = sqrt(EC[0]+EC[1])
> E1 = EC/L
> print,L
> ;Keep going until nothing is moved.
> ENDREP UNTIL L LT 1.2840277
>
> I am struggling to find eigenvalues and eigenvectors manually, instead
> of IDL routines.
>
> I think it might be a problem as David pointed out. But there should
> be a value less than or greater than that value, right?
> Thanks
In that case, your problem is either that L never gets smaller than
that value, or it varies slowly enough that it only seems it will
never get there. If in fact it never gets smaller than that limit, it
is either a problem with the algorithm (meaning that iterating that
way, with that starting point, L will never get below that value), or
it is a precision problem (meaning that at some point the steps become
too small to change the big value L has).
To diagnose it, what is probably more useful than just printing L at
each step would be to also print its variation, since it may just be
smaller than is visible with the default number of digits print uses.
Something like:
L=0d0
REPEAT BEGIN
EC = Z##E1
old_L=L
L = sqrt(EC[0]+EC[1])
E1 = EC/L
print,L,L-old_L
;Keep going until nothing is moved.
ENDREP UNTIL L LT 1.2840277
|
|
|
Re: endless loop problem [message #68959 is a reply to message #68953] |
Sun, 06 December 2009 17:20  |
Wasit.Weather
Messages: 62 Registered: February 2008
|
Member |
|
|
On Dec 6, 5:52 pm, David Fanning <n...@dfanning.com> wrote:
> pp writes:
>
> .
>
>> L does not change because you are calculating the same thing over and
>> over again. L only depends on EC[0] and EC[1], and neither changes
>> when you go through the loop. So if L does not happen to be
>> <1.2840277, the loop will never end.
>
> And it is not likely that it will *ever* be 1.2840277!
>
> http://www.dfanning.com//math_tips/sky_is_falling.html
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
I should have given more explanations on this. L changes over each
iteration. There is no problem. I missed one letter, here is the
corrected one.
;E1 = Unit vector, known
; Z is known matrix
REPEAT BEGIN
EC = Z##E1
L = sqrt(EC[0]+EC[1])
E1 = EC/L
print,L
;Keep going until nothing is moved.
ENDREP UNTIL L LT 1.2840277
I am struggling to find eigenvalues and eigenvectors manually, instead
of IDL routines.
I think it might be a problem as David pointed out. But there should
be a value less than or greater than that value, right?
Thanks
|
|
|
Re: endless loop problem [message #68962 is a reply to message #68959] |
Sun, 06 December 2009 15:52  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
pp writes:
.
> L does not change because you are calculating the same thing over and
> over again. L only depends on EC[0] and EC[1], and neither changes
> when you go through the loop. So if L does not happen to be
> <1.2840277, the loop will never end.
And it is not likely that it will *ever* be 1.2840277!
http://www.dfanning.com//math_tips/sky_is_falling.html
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: endless loop problem [message #68963 is a reply to message #68962] |
Sun, 06 December 2009 15:28  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Dec 6, 9:11 pm, Elkunn <wasit.weat...@gmail.com> wrote:
> Hi All,
> I would like to run iterations until a condition is met. But it runs
> non-stop. What is the problem with the following code? The problem is
> L reaches the value 1.2840277, but the loop still loops and gives
> 1.2840277 over and over. How to I stop it when it reaches to
> 1.2840277?
> Thanks
>
> ;E1 = Unit vector, known
> ; Z is known matrix
> REPEAT BEGIN
> C = Z##E1
> L = sqrt(EC[0]+EC[1])
> E1 = EC/L
> print,L
> ;Keep going until nothing is moved.
> ENDREP UNTIL L LT 1.2840277
>
L does not change because you are calculating the same thing over and
over again. L only depends on EC[0] and EC[1], and neither changes
when you go through the loop. So if L does not happen to be
<1.2840277, the loop will never end.
|
|
|