|
-
Mar 9th, 2019, 08:00 PM
#10
Thread Starter
Junior Member
Re: [RESOLVED] Weird Math Error in VBA for Excel
OptionBase1, you are a God send, thanks for following up with me
I have included the current code as requested below. In the Excel sheet using only formulas no code
I use the following, this works, I can replace ^2 with any rational number like ; 1.99, 1.999, 1.9999,
2.99, 3.999, etc I copy this down to up to 100 cells in a column, for the divisor value I can enter similiar
rationals and no problem, but this isnt the case with the code - if the iteration is set to say 100 loops
after about the 5th iteration sometimes sooner accuracy is lost badly and there is no correspondence between
what the sheet column cells report vs what the code loop returns. This is the sheet formula below,
except I replace the ^2 with other values mentioned like 1.9999
The first formula placed at (E2) looks like ; =MOD(((B2^2)/$B$3),$B$4)
In (E3) this statement is placed ; =MOD(((E2^2)/$B$3),$B$4)
Here is the code that returns wrong values ;
Code:
Public Function Phaser(phase As Double, radius As Double, decx As Double) As Double
'SYNTAX ; Phaser(phase,radius,divisor)
'Public Function Phaser(phase As Integer, radius As Integer, decx As Double) As Double
Application.Volatile
Dim Count As Integer
Phaser = phase
'Dim decx As Double
Count = 1
For Count = 1 To radius
Phaser = (Phaser ^ 3) '+ radius
Phaser = xlMOD(Phaser, 1449)
Phaser = xlMOD(Phaser, 1156) / decx
Next Count
End Function
Public Function xlMOD(a As Double, b As Double) As Double
xlMOD = a - (b * (a \ b))
End Function
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|