Excel Code running VERY slow (speed up tips?)

quan3165

New Member
Joined
May 1, 2011
Messages
3
Hi all,

I'm new to the forum and couldn't find any good tips for speeding up my program, but I'm hoping there's someone who can help. I'm writing this for a school project in my Heat Transfer class. m and n are coordinates, m range from 1 to 31, n range from 1 to 41 and I need to output a temperature (Tnode) for every (m,n) coordinate. Tau, Time, and Tstep are user inputted, but they can be .225, 20, and .2, respectively. I'm running Excel07/Win7/4GB ram/2.4GHz duo if that matters.

<m<31, 1<n<41="" and="" i="" need="" to="" output="" a="" temperature="" (tnode)="" for="" every="" (m,n)="" coordinate.="" tau,="" time,="" tstep="" are="" user="" inputted,="" but="" they="" can="" be="" .225,="" 20,="" .2,="" respectively.="" i'm="" running="" excel07="" win7="" 4gb="" ram="" 2.4ghz="" duo="" if="" that="" matters.
<m<31, 1<n<41="" and="" i="" need="" to="" output="" a="" temperature="" (tnode)="" for="" every="" (m,n)="" coordinate.="" tau,="" time,="" tstep="" are="" user="" inputted,="" but="" they="" can="" be="" .225,="" 20,="" .2,="" respectively.="" i'm="" running="" excel07="" win7="" 4gb="" ram="" 2.4ghz="" duo="" if="" that="" matters.


Option Explicit
Function Contour_Plot2(m, n, Tau, Time, Tstep)
Dim i, j, Tnode(1 To 31, 1 To 41), a, x, y, g, TV

For i = 1 To 31
Tnode(i, 1) = 10
Tnode(i, 41) = 40
Next i
For j = 1 To 41
Tnode(1, j) = 0
Tnode(31, j) = 0
Next j

For a = 1 To (Time / Tstep)
For x = 2 To 30
For y = 2 To 40
g = Tnode(x, y)
Tnode(x, y) = Tau * (Tnode(x + 1, y) + Tnode(x, y + 1) + Tnode(x - 1, y) + Tnode(x, y - 1)) + (1 - 4 * Tau) * Tnode(x, y)
TV = TV + Abs(Tnode(x, y) - g)
Next y
Next x
If TV < 0.01 Then
Exit For
End If
Next a

Contour_Plot2 = Tnode(m, n)

End Function
___________________________________

Thank you!<m<31, 1<n<41="" and="" i="" need="" to="" output="" a="" temperature="" (tnode)="" for="" every="" (m,n)="" coordinate.="" tau,="" time,="" tstep="" are="" user="" inputted,="" but="" they="" can="" be="" .225,="" 20,="" .2,="" respectively.="" i'm="" running="" excel07="" win7="" 4gb="" ram="" 2.4ghz="" duo="" if="" that="" matters.
</m<31,></m<31,></m<31,>
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I was able to speed this up by removing the (m,n) coordinate from the code altogether. The array the program outputs is rotated 90 degrees but I was able to Paste Special>Transpose if anyone needs this for future reference...
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top