+ Reply to Thread
Results 1 to 2 of 2

Iterative code stops right after 1st step

  1. #1
    Registered User
    Join Date
    01-29-2014
    Location
    Oklahoma City
    MS-Off Ver
    Excel 2010
    Posts
    2

    Iterative code stops right after 1st step

    Hello All,

    I am new in writing code in VBA for excel and I am writing a code to get wet bulb temperature (WBT) from dry bulb (DBT) and relative humidity, but when I run my simulation I am getting an answer which would have been the next step in iterative calculation. For example if my initial guess for DBT=98F, Relative Humidity= 40% (.4 as input)and an initial guess for WBT = 98F then my iteration stops at 97.9F. I will appreciate if anybody could help me correct the iterative coding if I am wrong.


    '-------------------------------------------------------------------------------
    'Calculate wet bulb temp given dry bulb temp and relative humidity
    '
    Function psychro_WBT(DBT, RH)

    Dim DBR As Double
    Dim Pws As Double
    Dim Ws As Double
    Dim Pw As Double
    Dim Wact As Double

    DBR = DBT + 459.67

    Pws = Exp(-10440.397 / DBR + -11.29465 + -0.027022355 * DBR + 0.00001289036 * DBR ^ 2 + -2.4780681E-09 * DBR ^ 3 + 6.5459673 * Log(DBR))

    Ws = 0.621945 * Pws / (14.7 - Pws)

    Pw = RH * Pws

    Wact = 0.621945 * (Pw / (14.7 - Pw))

    Do
    WBT = DBR
    Wnew = ((1093 - 0.556 * WBT) * Ws - 0.24 * (DBR - WBT)) / (1093 + 0.444 * DBR - WBT)
    WBT = WBT - 0.1
    Diff = (Wact - Wnew) / ((Wnew + Wact) / 2)
    Loop Until (Diff < 0.1)

    psychro_WBT = WBT

    End Function

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Iterative code stops right after 1st step

    Forum rules require that you put code inside of code tags.

    I haven't looked at it closely, but I would guess that the problem is in Diff. If Wact<Wnew, the Diff will be negative (<0) and any number <0 will also be <0.1. You probably need an ABS function in there somewhere.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Removing code line stops code working?!?!?
    By adamj1910 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2012, 02:36 PM
  2. Problem with Iterative Code, Excel Precision, or my maths??
    By Phil_V in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-19-2009, 09:59 AM
  3. Code stops when high lighting (Chips code)
    By ste mac in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-02-2006, 08:45 AM
  4. [SOLVED] Macro just stops in Step Mode
    By AccessNewbie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-23-2006, 11:25 AM
  5. VB Code stops working
    By Michelle K in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-28-2005, 05:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1