Shop OBEX P1 Docs P2 Docs Learn Events
Equation help — Parallax Forums

Equation help

SassySassy Posts: 21
edited 2007-05-08 21:16 in BASIC Stamp
Could someone help figure out how to effectiviley write the following equation so that the Basic Stamp II could do. It deals with Wind Chill Factor.


Wind chill temperature = 35.74 + 0.6215T - 35.75V (**0.16) + 0.4275TV(**0.16)

In the formula, V is in the wind speed in statute miles per hour, and T is the temperature in degrees Fahrenheit.

Note: In the formula, ** means the following term is an exponent (i.e. 10**(0.5 ) means 10 to the 0.5 power, or the square root of V), - means to subtract, + means to add. A letter next to a number means to multiply that quantity represented by the letter by the number. The standard rules of algebra apply.



Sassy

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-06 19:23
    Have a look at Tracy Allen's website (www.emesystems.com), particularly the section on math. The Stamp's do all their arithmetic with 16 bit unsigned integers although it is possible to handle fixed point arithmetic with some work. Things like exponentials are usually handled by doing table lookup. For example, you could represent something like 35.74 as a fixed point number with 2 decimal places by using 3574 instead. You could transparently add and subtract similar numbers, but would have to adjust the result of multiplication or division by the appropriate factor of 10. In addition, with the limited number of significant digits (0 to 65535 or -32768 to 32767), you have to do multiplication and division carefully.

    Post Edited (Mike Green) : 5/6/2007 7:28:47 PM GMT
  • SassySassy Posts: 21
    edited 2007-05-06 19:28
    Thank You Mike,

    I did infact look at Tracy's Web page, But I am not smart enough to figure out how to do it. I was hoping someone with Good Math Knowledge could help me.

    Sassy
  • phil kennyphil kenny Posts: 233
    edited 2007-05-06 23:25
    Since this is a nonlinear equation involving the 6th root of two
    different terms, my first thought is to use a co-processor such
    as the PAK-II from Al Williams.

    See http://www.awce.com/pak1.htm

    It has the ability to handle the exponentiation required by this
    equation.

    phil
  • RickBRickB Posts: 395
    edited 2007-05-07 00:53
    A much better coprocessor is this. http://www.parallax.com/detail.asp?product_id=604-00050

    Rick
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-07 16:05
    The windchill formula as you have it written is a little ambiguous with the parentheses misplaced. The formula is,

    Wind chill temperature = 35.74 + 0.6215T - 35.75(V **0.16) + 0.4275T(V**0.16)

    The only factor raised to a power **0.16 is the wind speed. That makes things a lot easier. That is a very slow currve, easy to approximate.

    attachment.php?attachmentid=47052

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 5/7/2007 5:19:31 PM GMT
    615 x 403 - 60K
  • SassySassy Posts: 21
    edited 2007-05-07 23:11
    Tracy,

    Thank you for your help. Like I said I am not a Math wize. I was wondering if you have this on your site or know where I may obtain a sample program. Someone has had to attempt this.

    Thanks

    Sassy
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-05-08 00:27
    I am not a Math wize either.

    I'd programme·a table (matrix), using DATA; have the programme prompt for user input (Temperature, Wind Speed -- integers only or truncate them); then retrieve (READ) the pre-calculated "answers" to the more complicated parts which could be computed more easily.

    All this raising to powers of <1 and multiplying by <1... Sheesh.

    Update:
    • A = 0.6215T········ -- 86
    • B = 35.75(V^0.16)· ·-- 56
    • C = 0.4275T(V^0.16) -- 56

    ·Then you could "do" 35.74 + A - B + C (after you work around the "integer only" maths.)

    Post Edited (PJ Allen) : 5/8/2007 12:45:09 AM GMT
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-05-08 00:41
    Here, have a table

    DATA 36,31,25,19,13,7,1,-5,-11,-16,-22,-28,-34,-40,-46,-52,-57,-63
    DATA 34,27,21,15,9,3,-4,-10,-16,-22,-28,-35,-41,-47,-53,-59,-66,-72
    DATA 32,25,19,13,6,0,-7,-13,-19,-26,-32,-39,-45,-51,-58,-64,-71,-77
    DATA 30,24,17,11,4,-2,-9,-15,-22,-29,-35,-42,-48,-55,-61,-68,-74,-81
    DATA 29,23,16,9,3,-4,-11,-17,-24,-31,-37,-44,-51,-58,-64,-71,-78,-84
    DATA 28,22,15,8,1,-5,-12,-19,-26,-33,-39,-46,-53,-60,-67,-73,-80,-87
    DATA 28,21,14,7,0,-7,-14,-21,-27,-34,-41,-48,-55,-62,-69,-76,-82,-89
    DATA 27,20,13,6,-1,-8,-15,-22,-29,-36,-43,-50,-57,-64,-71,-78,-84,-91
    DATA 26,19,12,5,-2,-9,-16,-23,-30,-37,-44,-51,-58,-65,-72,-79,-86,-93
    DATA 26,19,12,4,-3,-10,-17,-24,-31,-38,-45,-52,-60,-67,-74,-81,-88,-95
    DATA 25,18,11,4,-3,-11,-18,-25,-32,-39,-46,-54,-61,-68,-75,-82,-89,-97
    DATA 25,17,10,3,-4,-11,-19,-26,-33,-40,-48,-55,-62,-69,-76,-84,-91,-98

    no, I didn't type it in. I used Excel and VBA

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-05-08 01:57
    And some code to go with it.


    "Typo Reposted"


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    DATA 36,31,25,19,13,7,1,-5,-11,-16,-22,-28,-34,-40,-46,-52,-57,-63
    DATA 34,27,21,15,9,3,-4,-10,-16,-22,-28,-35,-41,-47,-53,-59,-66,-72
    DATA 32,25,19,13,6,0,-7,-13,-19,-26,-32,-39,-45,-51,-58,-64,-71,-77
    DATA 30,24,17,11,4,-2,-9,-15,-22,-29,-35,-42,-48,-55,-61,-68,-74,-81
    DATA 29,23,16,9,3,-4,-11,-17,-24,-31,-37,-44,-51,-58,-64,-71,-78,-84
    DATA 28,22,15,8,1,-5,-12,-19,-26,-33,-39,-46,-53,-60,-67,-73,-80,-87
    DATA 28,21,14,7,0,-7,-14,-21,-27,-34,-41,-48,-55,-62,-69,-76,-82,-89
    DATA 27,20,13,6,-1,-8,-15,-22,-29,-36,-43,-50,-57,-64,-71,-78,-84,-91
    DATA 26,19,12,5,-2,-9,-16,-23,-30,-37,-44,-51,-58,-65,-72,-79,-86,-93
    DATA 26,19,12,4,-3,-10,-17,-24,-31,-38,-45,-52,-60,-67,-74,-81,-88,-95
    DATA 25,18,11,4,-3,-11,-18,-25,-32,-39,-46,-54,-61,-68,-75,-82,-89,-97
    DATA 25,17,10,3,-4,-11,-19,-26,-33,-40,-48,-55,-62,-69,-76,-84,-91,-98

    Temp VAR Byte
    Wind VAR Byte
    Index VAR Word
    result VAR Word

    DO
    · DEBUG "Temperature?",CR
    · DEBUGIN SDEC3 Temp
    · DEBUG ?Temp
    · DEBUG "Wind Speed?",CR
    · DEBUGIN DEC2 Wind
    · Index=40-Temp & $FF / 5
    · DEBUG ?index
    · Index=Wind - 5 / 5 * 18 +Index
    · DEBUG ?index

    · READ Index,result
    · result.HIGHBYTE=result.BIT7 * $FF 'sign extend
    · DEBUG "Wind Chill:",SDEC result,"°",CR,CR
    LOOP



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR

    Post Edited (TechnoRobbo) : 5/8/2007 4:01:07 AM GMT
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-08 20:25
    Here is another approach, that uses a table lookup for the mph^0.16 term, and then straightforward calculation for the rest. You can compare this with the NWS chart above or with the result of TR's program at the 5mph/5degF increments. There are some integer roundoff errors, but it seems to come within a degree.

    The calculation uses the */ operator for the fractional multiplies, and offsets the temperature to positive values and then restore the offset after the divisions. The attached graph shows mph ^ 0.16, except at values below 5mph I extrapolated through the value at 3mph to build the interpolation table. Windchill not defined for windspeeds below 3 mph.

    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    '  Tracy Allen, EME Systems
    ' Given temperature in Fahrenheit and windspeed in mph, calculates wind chill 
    ' from the formula at http://www.weather.gov/om/windchill/
    
    mph VAR BYTE
    degF VAR WORD
    vx VAR BYTE
    vy VAR BYTE
    idx VAR BYTE
    
    main:
      DO
      DEBUG "enter degF: "
      DEBUGIN SDEC degF
      DEBUG "enter mph: "
      DEBUGIN DEC mph
      GOSUB wind_Chill
      DEBUG "wind chill = ",SDEC degF, " degF",CR
      LOOP
    
    wind_Chill:
      vTable DATA 104,129,145,154,161,167,172,177,180,184,187,190,193,195,197 ' 100 * mph ^ 0.16
      idx = mph/5 + vTable    ' look up mph ^ 0.16
      READ idx, vx
      READ idx + 1, vy
      vx = mph // 5 * (vy-vx) / 5 + vx  ' interpolate
      degF=degF+45   ' make temperature positive for calculation
      degF = 36 + (159 */ degF -28) - (9152 */ vx / 100) + (109 */ vx * degF / 100) - (109 */ vx * 45 / 100)
    RETURN
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
    288 x 227 - 4K
  • SassySassy Posts: 21
    edited 2007-05-08 21:16
    Tracy,Pj and TechoRobbo

    Thank You all for your Help! I will try Using the Program Tracy has provided with the Look-Up Table TechoRobbo has provided. Tracy your Web page is a source of much needed information. I think you should add this to it.

    Thanks Again

    Sassy
Sign In or Register to comment.