Shop OBEX P1 Docs P2 Docs Learn Events
exponential regression? — Parallax Forums

exponential regression?

unteerunteer Posts: 5
edited 2008-01-30 12:55 in BASIC Stamp
I am controlling some DC motors using pulse width and BASIC Stamp 2's. I somehow need to model an exponentially increasing slope in an equation, but BS2's do not support exponents as far as I can tell. Does anyone have any suggestions as to possible work arounds? Sorry if this is too vague. What other information would you need to help me out?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-30 02:39
    You can achieve what you want by multiplying by a fixed constant at each step. Here's an example:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    x VAR Word
    i VAR Byte
    
    x = 100
    
    FOR i = 1 TO 50
      DEBUG DEC5 x, " "
      IF (i // 10 = 0) THEN DEBUG CR
      x = x */ 282
    NEXT
    
    
    


    This multiplies x by approximately 1.1 (282 / 256 = 1.1015625) at each step, resulting in an exponential progression. Here's what the output looks like:

    00100 00110 00121 00133 00146 00160 00176 00193 00212 00233
    00256 00282 00310 00341 00375 00413 00454 00500 00550 00605
    00666 00733 00807 00888 00978 01077 01186 01306 01438 01584
    01744 01921 02116 02330 02566 02826 03113 03429 03777 04160
    04582 05047 05559 06123 06744 07428 08182 09012 09927 10935
    
    
    


    -Phil
  • stephenwagnerstephenwagner Posts: 147
    edited 2008-01-30 12:55
    Unteer,

    Application No. 7 of this Parallax application note may help.
    http://www.parallax.com/Portals/0/Downloads/appnt/stamps/bs1Appnotes.pdf
    It demonstrates how to straighten a non-linear curve.
    If you plot your values in Micro Soft Xcel, XY scatter, there is an option to plot·the best fit equation·using plot wizard. I am unaware if "GAUSFIT" is still supported by Parallax. MSXcel will do the same thing. Remember to keep your math at 16 bits or less.

    SJW
Sign In or Register to comment.