Loading ...
Sorry, an error occurred while loading the content.
 

Using successive values in following calculations in For/Next Loop

Expand Messages
  • William
    In the program below I get correct values for the first step, then a division by zero error, probably the result of certain updated values not being available.
    Message 1 of 4 , Sep 22, 2010
      In the program below I get correct values for the first step, then a division by zero error, probably the result of certain updated values not being available.

      I believe I need some way to store and recall previous step calculated values: weight, tempGuess, and tempEstimateVariance, for use in each following loop to generate successive values.

      Can anyone suggest how I might do that in a FOR/NEXT loop?

      Thanks,

      W. D. Allen
      ballensr@...


      ' Kalman Rudimentary Example
      ' Illustrates progressive updating of variance estimate

      guess(1) = 1
      tempGuess(1) = 72
      tempVariance(1) = 2
      thermMeasurement(1) = 75
      thermVariance(1) = 5

      print " weight ", "TempEstimate ", "TempEstimateVariance "

      for i = 1 to 10
      weight(1) = tempVariance(i) / (tempVariance(i) + thermVariance(i))
      print weight(i),
      tempEstimate(i) = (1 - weight(i)) * tempGuess(i) + weight(i) * thermMeasurement(i)
      print tempEstimate(i),
      tempEstimateVariance(i) = tempVariance(i) * thermVariance(i) / (tempVariance(i) + thermVariance(i))
      print tempEstimateVariance(i)
      next i

      end
    • Ingemar Bjerle
      Hello Only tempVariance(1) is given. tempVariance(2-10) are all set to zero and you get an oveflow by dividing by zero Ingemar ... From: William To:
      Message 2 of 4 , Sep 22, 2010
        Hello
        Only tempVariance(1) is given. tempVariance(2-10) are all set to zero and you get an oveflow by dividing by zero
        Ingemar

        ----- Original Message -----
        From: William
        To: libertybasic@yahoogroups.com
        Sent: Wednesday, September 22, 2010 7:27 PM
        Subject: [libertybasic] Using successive values in following calculations in For/Next Loop



        In the program below I get correct values for the first step, then a division by zero error, probably the result of certain updated values not being available.

        I believe I need some way to store and recall previous step calculated values: weight, tempGuess, and tempEstimateVariance, for use in each following loop to generate successive values.

        Can anyone suggest how I might do that in a FOR/NEXT loop?

        Thanks,

        W. D. Allen
        ballensr@...

        ' Kalman Rudimentary Example
        ' Illustrates progressive updating of variance estimate

        guess(1) = 1
        tempGuess(1) = 72
        tempVariance(1) = 2
        thermMeasurement(1) = 75
        thermVariance(1) = 5

        print " weight ", "TempEstimate ", "TempEstimateVariance "

        for i = 1 to 10
        weight(1) = tempVariance(i) / (tempVariance(i) + thermVariance(i))
        print weight(i),
        tempEstimate(i) = (1 - weight(i)) * tempGuess(i) + weight(i) * thermMeasurement(i)
        print tempEstimate(i),
        tempEstimateVariance(i) = tempVariance(i) * thermVariance(i) / (tempVariance(i) + thermVariance(i))
        print tempEstimateVariance(i)
        next i

        end





        [Non-text portions of this message have been removed]
      • laurie camion
        I think you are asking how to refer to the previous value when looping, very simple example   value(0) = 10 inc = 3   for i = 1 to 10 value(i) = value(i-1) +
        Message 3 of 4 , Sep 22, 2010
          I think you are asking how to refer to the previous value when looping, very simple example
           
          value(0) = 10
          inc = 3
           
          for i = 1 to 10
          value(i) = value(i-1) + inc
          print value(i)
          next i

          but another problem is that your loop must generate new values with the same names as the initial ones.


          --- On Wed, 9/22/10, Ingemar Bjerle <ingbje@...> wrote:


          From: Ingemar Bjerle <ingbje@...>
          Subject: Re: [libertybasic] Using successive values in following calculations in For/Next Loop
          To: libertybasic@yahoogroups.com
          Date: Wednesday, September 22, 2010, 11:05 AM


           



          Hello
          Only tempVariance(1) is given. tempVariance(2-10) are all set to zero and you get an oveflow by dividing by zero
          Ingemar

          ----- Original Message -----
          From: William
          To: libertybasic@yahoogroups.com
          Sent: Wednesday, September 22, 2010 7:27 PM
          Subject: [libertybasic] Using successive values in following calculations in For/Next Loop

          In the program below I get correct values for the first step, then a division by zero error, probably the result of certain updated values not being available.

          I believe I need some way to store and recall previous step calculated values: weight, tempGuess, and tempEstimateVariance, for use in each following loop to generate successive values.

          Can anyone suggest how I might do that in a FOR/NEXT loop?

          Thanks,

          W. D. Allen
          ballensr@...

          ' Kalman Rudimentary Example
          ' Illustrates progressive updating of variance estimate

          guess(1) = 1
          tempGuess(1) = 72
          tempVariance(1) = 2
          thermMeasurement(1) = 75
          thermVariance(1) = 5

          print " weight ", "TempEstimate ", "TempEstimateVariance "

          for i = 1 to 10
          weight(1) = tempVariance(i) / (tempVariance(i) + thermVariance(i))
          print weight(i),
          tempEstimate(i) = (1 - weight(i)) * tempGuess(i) + weight(i) * thermMeasurement(i)
          print tempEstimate(i),
          tempEstimateVariance(i) = tempVariance(i) * thermVariance(i) / (tempVariance(i) + thermVariance(i))
          print tempEstimateVariance(i)
          next i

          end

          [Non-text portions of this message have been removed]











          [Non-text portions of this message have been removed]
        • justbasic_fan
          Instead of use FOR/NEXT Loop, you can also use IF statement. You can change value at [InitialValue] and [Increment] to fit your need, as well as you can change
          Message 4 of 4 , Sep 22, 2010
            Instead of use FOR/NEXT Loop, you can also use IF statement. You can change value at [InitialValue] and [Increment] to fit your need, as well as you can change how many it will be count at [ConditionalStatement], in this code it will count untill 10 loops.


            '---Code Start
            print space$(2);"Guess";space$(7);"Weight";space$(8);"TempEstimate";space$(4);"TempEstimateVariance"
            [InitialValue]
            guess = 0
            tempGuess = 70
            tempVariance = 1
            thermMeasurement = 68
            thermVariance = 3
            [Increment]
            guess = guess + 1
            tempGuess = tempGuess + 2
            tempVariance = tempVariance + 1
            thermMeasurement = thermMeasurement + 7
            thermVariance = thermVariance + 2
            [Formula]
            weight = tempVariance / (tempVariance + thermVariance)
            tempEstimate = (1 - weight) * tempGuess + weight * thermMeasurement
            tempEstimateVariance = tempVariance * thermVariance /(tempVariance+ thermVariance)
            [Result]
            print space$(4);guess;space$(5);using("####.#######",weight);space$(5);using("####.########",tempEstimate);_
            space$(5);using("####.#######",tempEstimateVariance)
            [ConditionalStatement]
            if guess <= 9 then
            goto [Increment]
            else
            end
            end if
            '---Code End



            --- In libertybasic@yahoogroups.com, laurie camion <lauriecam2006@...> wrote:
            >
            > I think you are asking how to refer to the previous value when looping, very simple example
            >  
            > value(0) = 10
            > inc = 3
            >  
            > for i = 1 to 10
            > value(i) = value(i-1) + inc
            > print value(i)
            > next i
            >
            > but another problem is that your loop must generate new values with the same names as the initial ones.
            >
            >
            > --- On Wed, 9/22/10, Ingemar Bjerle <ingbje@...> wrote:
            >
            >
            > From: Ingemar Bjerle <ingbje@...>
            > Subject: Re: [libertybasic] Using successive values in following calculations in For/Next Loop
            > To: libertybasic@yahoogroups.com
            > Date: Wednesday, September 22, 2010, 11:05 AM
            >
            >
            >  
            >
            >
            >
            > Hello
            > Only tempVariance(1) is given. tempVariance(2-10) are all set to zero and you get an oveflow by dividing by zero
            > Ingemar
            >
            > ----- Original Message -----
            > From: William
            > To: libertybasic@yahoogroups.com
            > Sent: Wednesday, September 22, 2010 7:27 PM
            > Subject: [libertybasic] Using successive values in following calculations in For/Next Loop
            >
            > In the program below I get correct values for the first step, then a division by zero error, probably the result of certain updated values not being available.
            >
            > I believe I need some way to store and recall previous step calculated values: weight, tempGuess, and tempEstimateVariance, for use in each following loop to generate successive values.
            >
            > Can anyone suggest how I might do that in a FOR/NEXT loop?
            >
            > Thanks,
            >
            > W. D. Allen
            > ballensr@...
            >
            > ' Kalman Rudimentary Example
            > ' Illustrates progressive updating of variance estimate
            >
            > guess(1) = 1
            > tempGuess(1) = 72
            > tempVariance(1) = 2
            > thermMeasurement(1) = 75
            > thermVariance(1) = 5
            >
            > print " weight ", "TempEstimate ", "TempEstimateVariance "
            >
            > for i = 1 to 10
            > weight(1) = tempVariance(i) / (tempVariance(i) + thermVariance(i))
            > print weight(i),
            > tempEstimate(i) = (1 - weight(i)) * tempGuess(i) + weight(i) * thermMeasurement(i)
            > print tempEstimate(i),
            > tempEstimateVariance(i) = tempVariance(i) * thermVariance(i) / (tempVariance(i) + thermVariance(i))
            > print tempEstimateVariance(i)
            > next i
            >
            > end
            >
            > [Non-text portions of this message have been removed]
            >
            >
            >
            >
            >
            >
            >
            >
            >
            >
            >
            > [Non-text portions of this message have been removed]
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.