I would suggest you work out a way of using CHOOSE (its fast and
non-volatile): this should be reasonably straightforward if your intervals
are equal (you have to be able to convert the interval test to a 1-based
integer).
It will be more concise than the equivalent IF and probably more efficient.
If you can sensibly do the calculation using an excel (non-array) formula
then the formula will almost certainly be faster than a UDF, particularly if
calculation is automatic or called by Excel rather than VBA.
regards
Charles
______________________
Decision Models
FastExcel 2.2 Beta now available
www.DecisionModels.com
"Tushar Mehta" wrote in message
om...
My guess would be that XL formulas should be very fast. Also, what you
have
isn't overly complicated. I would go this route first. Further, I would
put t mod 1 (or, in XL, MOD(t,1)) into one cell. That way that expression
is calculated only once.
If you consider the UDF route, I would not be surprised if you do not see
any noticable performance difference. And, if you can generate the
results
for a vector of values (t=0,0.05,...0.95, 1) all at once and return them
as
an "array formula" the UDF will be quite fast.
You might also want to check your V(t) for 0.5 < t <= 0.75.
Maybe, you really want 1-4*(0.75-(t mod 1)) but it will go from V(0.5)=0
to
V(0.75)=1. If you are generating a 0-1 pulse with a linear rise and fall,
you need V(t)=4*(0.75-(t mod 1))
--
Regards,
Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
In article .com,
says...
I want to create a function which defines a pulse wave that rises from
0 to 1, stays at one for a bit, lowers to 0, and stays at zero for a
bit.
/ if (t mod 1) <0.25, V(t) = 4* (t mod 1)
| if 0.5 = (t mod 1) 0.25, V(t) = 1
V(t) = |
| if 0.75 =(t mod 1) 0.5, V(t) = 1-4* (0.75-(t mod 1))
\ if 1 (t mod 1) 0.75, V(t) = 0
For this pulse wave there are straight rises, falls and flat bottoms
and tops, which I need (and which is why a sine wave can't be used). If
you're still with me, thanks.
I can either put this all into a long excel equation for each cell that
I want this in (there will be about 4 'if' statements and 6 'mod'
statements) or create a UDF, where the t mod 1 only has to be
calculated once.
Any idea out there how much faster/ slower as UDF really is in a case
like this? Also, can you think of an easier way to create this pulse
wave?
As a side note, the t in my program has some ROW() and COLUMN()
dependence, and there will be 200+ cells filled with this equation
(thus, I can't just compute it once and copy the values to each cell).
Caculation speed is important because each cell is being calculated as
the time, t, is advanced by a timer.
Thanks in advance to anyone who takes a stab at this.
-Abe