Results 1 to 10 of 10

Macro to perform a complicated equation

Threaded View

  1. #1
    Registered User
    Join Date
    01-30-2015
    Location
    Durham, England
    MS-Off Ver
    Microsoft 2007
    Posts
    31

    Macro to perform a complicated equation

    Hello everyone, I am new to Excel Macros, I have some (limited) computing knowledge though. i am trying to use excel to perform the equation in the image below. This equation is meant to represent the heat distribution though insulation.
    descretizationequation.jpg
    where Dt is the time step= 0.065 and the superscript n represents the current time step.

    The image below shows the parameters to enter into this equation. (these can also be seen in the attached workbook)
    parameters.jpg
    I am not entirely sure how to get excel to calculate T at each time step for each layer.
    I have made a start on the coding, however the results show that temperature does not change with time when it should, please note that this coding is currently missing the final term in the equation as shown in the image below (I am doing it step by step), but in terms of the output there should still should be some changes in T with time.
    final part of equation.jpg
    Please see below for the coding I have started: and comments to help would be greatly appreciated.
    Best Wishes,
    Sarah

    Private Sub CommandButton1_Click()
    Dim i, time, X, stepSizeX, stepSizej, j, material, NUMB, n, T0, ControlV, Y
    i = 0
    
    'Delta t (Time Step):
    stepSizeX = 0.0625
    
    'Number of Time Seconds Experiment will run for
    X = Range("B2").Value
    
    'Clearing cells ready for the next calculation/macro run
    Range("A12:B99000").Value = ""
    Range("J12:Z99000").Value = ""
    
    'Intial value of hot chamber ( used in layer 1 calculation coding)
    T0 = Range("D2").Value
      
    'Loop which has time at intervals of 0.0625
    For time = 0.065 To X Step stepSizeX
    Cells(12 + i, 1).Value = time
    '
    'If Wood (Layer 1)Then Tj^n+1 =
    Cells(13 + i, 15).Value = (Range("F13") / Range("I13")) * (0.0625 / (Range("H13")) * (Range("G13") * Range("E13")) * Cells(12 + i, 16)) _
    + (Range("F12") / Range("I12")) * (0.0625 / (Range("H13")) * Range("G13") * Range("E13")) * T0 + _
    ((1 - (Range("F13") / Range("I13") + Range("F12") / Range("I12")) * (0.0625 / Range("H13") * Range("G13") * Range("E13"))) * Cells(12 + i, 15))
    
    'If Aluminium (layer 2) Then Tj^n+1=
    Cells(13 + i, 16).Value = (Range("F14") / Range("I14")) * (0.0625 / (Range("H14")) * (Range("G14") * Range("E14")) * Cells(12 + i, 17)) _
    + (Range("F13") / Range("I13")) * (0.0625 / (Range("H14")) * Range("G14") * Range("E14")) * Cells(12 + i, 15) + _
    ((1 - (Range("F14") / Range("I14") + Range("F13") / Range("I13")) * (0.0625 / Range("H14") * Range("G14") * Range("E14"))) * Cells(12 + i, 16))
    
    'If Air Bubbles (layer 3) Then Tj^n+1=
    Cells(13 + i, 17).Value = (Range("F15") / Range("I15")) * (0.0625 / (Range("H15")) * (Range("G15") * Range("E15")) * Cells(12 + i, 18)) _
    + (Range("F14") / Range("I14")) * (0.0625 / (Range("H15")) * Range("G15") * Range("E15")) * Cells(12 + i, 16) + _
    ((1 - (Range("F15") / Range("I15") + Range("F14") / Range("I14")) * (0.0625 / Range("H15") * Range("G15") * Range("E15"))) * Cells(12 + i, 17))
    
    'If polyester (layer 4) Then Tj^n+1=
    Cells(13 + i, 18).Value = (Range("F16") / Range("I16")) * (0.0625 / (Range("H16")) * (Range("G16") * Range("E16")) * Cells(12 + i, 19)) _
    + (Range("F15") / Range("I15")) * (0.0625 / (Range("H16")) * Range("G16") * Range("E16")) * Cells(12 + i, 17) + _
    ((1 - (Range("F16") / Range("I16") + Range("F15") / Range("I15")) * (0.0625 / Range("H16") * Range("G16") * Range("E16"))) * Cells(12 + i, 18))
    
    'If Air Bubbles (layer 5) Then Tj^n+1=
    Cells(13 + i, 19).Value = (Range("F17") / Range("I17")) * (0.0625 / (Range("H17")) * (Range("G17") * Range("E17")) * Cells(12 + i, 20)) _
    + (Range("F16") / Range("I16")) * (0.0625 / (Range("H17")) * Range("G17") * Range("E17")) * Cells(12 + i, 18) + _
    ((1 - (Range("F17") / Range("I17") + Range("F16") / Range("I16")) * (0.0625 / Range("H17") * Range("G17") * Range("E17"))) * Cells(12 + i, 19))
    
    'If polyester (layer 6) Then Tj^n+1=
    Cells(13 + i, 20).Value = (Range("F18") / Range("I18")) * (0.0625 / (Range("H18")) * (Range("G18") * Range("E18")) * Cells(12 + i, 21)) _
    + (Range("F17") / Range("I17")) * (0.0625 / (Range("H18")) * Range("G18") * Range("E18")) * Cells(12 + i, 19) + _
    ((1 - (Range("F18") / Range("I18") + Range("F17") / Range("I17")) * (0.0625 / Range("H18") * Range("G18") * Range("E18"))) * Cells(12 + i, 20))
    
    'If Air Bubbles (layer 7) Then Tj^n+1=
    Cells(13 + i, 21).Value = (Range("F19") / Range("I19")) * (0.0625 / (Range("H19")) * (Range("G19") * Range("E19")) * Cells(12 + i, 22)) _
    + (Range("F18") / Range("I18")) * (0.0625 / (Range("H19")) * Range("G19") * Range("E19")) * Cells(12 + i, 20) + _
    ((1 - (Range("F19") / Range("I19") + Range("F18") / Range("I18")) * (0.0625 / Range("H19") * Range("G19") * Range("E19"))) * Cells(12 + i, 21))
    
    'If Aluminium (layer 8) Then Tj^n+1=
    Cells(13 + i, 22).Value = (Range("F20") / Range("I20")) * (0.0625 / (Range("H20")) * (Range("G20") * Range("E20")) * Cells(12 + i, 23)) _
    + (Range("F19") / Range("I19")) * (0.0625 / (Range("H20")) * Range("G20") * Range("E20")) * Cells(12 + i, 21) + _
    ((1 - (Range("F20") / Range("I20") + Range("F19") / Range("I19")) * (0.0625 / Range("H20") * Range("G20") * Range("E20"))) * Cells(12 + i, 22))
    '
    'if air gap (layer 9) Then Tj^n+1=
    Cells(13 + i, 23).Value = (Range("F21") / Range("I21")) * (0.0625 / (Range("H21")) * (Range("G21") * Range("E21")) * Cells(12 + i, 24)) _
    + (Range("F20") / Range("I20")) * (0.0625 / (Range("H21")) * Range("G21") * Range("E21")) * Cells(12 + i, 22) + _
    ((1 - (Range("F21") / Range("I21") + Range("F20") / Range("I20")) * (0.0625 / Range("H21") * Range("G21") * Range("E21"))) * Cells(12 + i, 23))
    
    'if Glass wool (layer 10) Then Tj^n+1=
    Cells(13 + i, 24).Value = (Range("F22") / Range("I22")) * (0.0625 / (Range("H22")) * (Range("G22") * Range("E22")) * Cells(12 + i, 25)) _
    + (Range("F21") / Range("I21")) * (0.0625 / (Range("H22")) * Range("G22") * Range("E22")) * Cells(12 + i, 23) + _
    ((1 - (Range("F22") / Range("I22") + Range("F21") / Range("I21")) * (0.0625 / Range("H22") * Range("G22") * Range("E22"))) * Cells(12 + i, 24))
    '
    'if wood (layer 11) Then Tj^n+1=
    Cells(13 + i, 25).Value = (Range("F23") / Range("I23")) * (0.0625 / (Range("H23")) * (Range("G23") * Range("E23")) * Cells(12 + i, 26)) _
    + (Range("F22") / Range("I22")) * (0.0625 / (Range("H23")) * Range("G23") * Range("E23")) * Cells(12 + i, 24) + _
    ((1 - (Range("F23") / Range("I23") + Range("F22") / Range("I22")) * (0.0625 / Range("H23") * Range("G23") * Range("E23"))) * Cells(12 + i, 25))
    
    'if cold chamber (layer 12) Then Tj^n+1=
    Cells(13 + i, 26).Value = (Range("F24") / Range("I24")) * (0.0625 / (Range("H24")) * (Range("G24") * Range("E24")) * Cells(12 + i, 27)) _
    + (Range("F23") / Range("I23")) * (0.0625 / (Range("H24")) * Range("G24") * Range("E24")) * Cells(12 + i, 25) + _
    ((1 - (Range("F24") / Range("I24") + Range("F23") / Range("I23")) * (0.0625 / Range("H24") * Range("G24") * Range("E24"))) * Cells(12 + i, 26))
    
     i = i + 1
    
    Next time
    
    'Just so I know many time steps have passed
    NUMB = X / 0.065
     Range("B6").Value = NUMB
    
    End Sub
    Attached Files Attached Files
    Last edited by eocsur; 01-30-2015 at 11:07 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Please help - complicated equation plus plotting it
    By loto11 in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 03-01-2013, 07:39 PM
  2. Replace Fill Down, Complicated Equation
    By thequiff in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-15-2012, 10:03 AM
  3. [SOLVED] Complicated IF statement that runs an equation on True
    By scrumpulate in forum Excel General
    Replies: 1
    Last Post: 04-20-2012, 04:24 PM
  4. Replies: 1
    Last Post: 05-15-2011, 07:00 PM
  5. Complicated If Equation
    By Brad Larsen in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-22-2006, 05:29 PM

Tags for this Thread

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