Re: Exponetial Interpolation VBA Code



On Aug 8, 6:18 am, David B <da...@xxxxxxxxxxxxxxxxxxxxxx> wrote:

You (as well as dougaj4) also make (IMO) goofy implicit
assumptions about the nature of the objects/arrays being passed in, as
well as some inefficient "dims".




David B, feel free to tell which implicit assumptions are goofy, and
why, and show us how to make the "dims" more efficient.


More to the point, the formula given in the OP gives the wrong
answers.

The code below will I believe give correct exponential interpolation:

Function ExpInterp2(D As Variant, P As Variant, V As Double) As
Variant
Dim i As Long, LogP As Double, LogPdiff As Double, Dprev As Double
Dim DDiff As Double, Logslope As Double, LogInterp As Double

If TypeName(D) = "range" Then D = D.Value
If TypeName(D) = "range" Then P = P.Value

i = 1
Do While V > D(i, 1)
i = i + 1
Loop
i = i - 1

LogP = Log(P(i, 1))
LogPdiff = Log(P(i + 1)) - LogP
Dprev = D(i, 1)
DDiff = D(i + 1, 1) - Dprev
Logslope = LogPdiff / DDiff

LogInterp = LogP + (V - Dprev) * Logslope

ExpInterp2 = Exp(LogInterp)

End Function


Goofy implicit assumptions are that D and P are single column ranges
containing values, and V is a value or a cell address containing a
value.

.



Relevant Pages

  • Re: Exponetial Interpolation VBA Code
    ... Function ExpInterp2(D As Variant, P As Variant, V As Double) As ... Dim DDiff As Double, Logslope As Double, LogInterp As Double ... Goofy implicit assumptions are that D and P are single column ranges ...
    (comp.apps.spreadsheets)
  • Re: Some thoughts on VB9
    ... implicit typing is very useful and makes more sense. ... : Dim s = 1 ... The fact that implicit types encourage laziness ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Looping variables - Integer vs Long
    ... >>>I would think the opposite since either a variant or an object is ... >> setting the implicit reference ... > data type that can used in a For Each loop. ... Dim ctl As Control ...
    (comp.databases.ms-access)
  • Re: XOR operator
    ... I tried to use the Strict On function, but then a got errors about implicit ... type conversion. ... I had tried to dim the variables as the same as the result, ...
    (microsoft.public.dotnet.general)
  • Re: Variable Declaration
    ... decision to have a variant. ... you explicitly declare it as Variant rather than leave it as an implicit ... so should NOT be left as an implicit ... or declared as an explicit variant type, ...
    (microsoft.public.excel.programming)