recursiveness using bool...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vajratkarviraj
    New Member
    • Jun 2007
    • 15

    #1

    recursiveness using bool...

    I hav a code like this

    Code:
    i=0
    while i<n:
        xold.data[0][i]=float(self.enINITGUESS.get());   #INITGUESS is an initial value
        xnew.data[0][i]=xold.data[0][i];
        i=i+1
    i=0
    flag = 1
    if True:
        flag=0
        for i in range (n):                  # all this is for improving my xnew
            j=0
            temp=0
            while j<i:
                temp=temp+a.data[i][j]*xnew.data[0][j]    #a,b,xnew,xold are classes #defined earlier
                j=j+1
            j=i+1
            while j<n:
                temp=temp+a.data[i][j]*xold.data[0][j]
                j=j+1
            xnew.data[0][i]=(b.data[0][i]-temp)/a.data[i][i]
            s1=xold.data[0][i]
            s2=xnew.data[0][i]                          #evaluating the results differences
            e.data[0][i]= s1-s2
            if e.data[0][i]<float(0):
                e.data[0][i]=0-e.data[0][i]
            i=0
            for i in range (n):
                xold.data[0][i]=xnew.data[0][i]
            if e.data[0][i]>float(self.enPREC.get()):  #if more than a certain value iterate #again using the newly defined xold
                flag=1

    evidently this code does not seem to reiterate... it jus perform the operation once only.... even if it finds tht the difference exceeds the given value specified by PREC it doesnt iterate again... it jus throws out the result of the calculation given by its first attempt on it... anybody care 2 help?
  • elbin
    New Member
    • Jul 2007
    • 27

    #2
    Originally posted by vajratkarviraj
    evidently this code does not seem to reiterate... it jus perform the operation once only.... even if it finds tht the difference exceeds the given value specified by PREC it doesnt iterate again... it jus throws out the result of the calculation given by its first attempt on it... anybody care 2 help?
    This code has no while statement dealing with flag, so I don't see how it could possibly iterate. Just replace the

    Code:
    if TRUE:
    with

    Code:
    while flag:
    and you'll have it.

    Comment

    Working...