Home |
Search |
Today's Posts |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi. I may be wrong, but it appears to me that:
asstdrop(i) = (asstdrop(i) * 1000 + (acttdrop - asstdrop(i)) * 0.5 * 1000) / 1000 is equal to: asstdrop(i) = (asstdrop(i) + acttdrop)/2 -- HTH. :) Dana DeLouis Windows XP, Office 2003 "duane" wrote in message ... Here is my entire code. It currently recurses the assumed to actual to within 1.2 on an actual of -51.5, and generally to within 0.1 on actuals closer to zero. I put the recursionlimit in because at one point the macro would not stop recursing - I never figured out why so I simply limited it. Increasing the limit does not improve the results. On about 120 rows of data, it runs in about 2 seconds. Option Explicit Sub Temprecurse() Dim acttdrop As Double Dim asstdrop(200) As Double Dim lastrow As Integer Dim firstrow As Integer Dim asstemplosscol As Integer Dim acttemplosscol As Integer Dim i As Integer Dim j As Integer Dim k As Integer Dim l As Integer Dim terror As Double firstrow = Range("b5").Row lastrow = Range("b5").End(xlDown).Row asstemplosscol = Range("asssegtloss").Column acttemplosscol = Range("segtloss").Column j = asstemplosscol k = acttemplosscol ' initialize assumed temperature drops to 4 f For i = firstrow To lastrow Cells(i, j).Value = 4 Next i ' Begin recursion routine i = firstrow - 1 nextrow: l = 0 i = i + 1 ' quit after last row If i lastrow Then GoTo done 'Read in assumed and actual temperature drops asstdrop(i) = Cells(i, j).Value acttdrop = Cells(i, k).Value recurse: l = l + 1 'Calculate error of assumed vs actual terror = Abs(asstdrop(i) * 1000 - acttdrop * 1000) ' set tolerance for assumed vs actual If terror < 1 Then GoTo nextrow ' split the difference on assumed vs actual for new estimate asstdrop(i) = (asstdrop(i) * 1000 + (acttdrop - asstdrop(i)) * 0.5 * 1000) / 1000 'limit recursion to 500 tries If l = 500 Then GoTo nextrow Else GoTo recurse done: For i = 5 To lastrow Cells(i, j).Value = asstdrop(i) Next i End Sub -- duane ------------------------------------------------------------------------ duane's Profile: http://www.excelforum.com/member.php...o&userid=11624 View this thread: http://www.excelforum.com/showthread...hreadid=561671 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Help with Excle Formula | Excel Discussion (Misc queries) | |||
Excle 2003 | Excel Discussion (Misc queries) | |||
average in excle | Excel Worksheet Functions | |||
help in excle setting | New Users to Excel | |||
Precision displayed does not match precision in cell | Excel Discussion (Misc queries) |