Emulate BETADIST function

mark14

New Member
Joined
Dec 22, 2010
Messages
9
Hi everyone,

I have another application that I'm developing in Oracle Application Express using Oracle 10g. I developed a 'prototype' of the Oracle application in Excel and used the BETADIST function in this prototype. However, Oracle doesn't have this function, and I basically need to re-write it.

I've read all the documentation on the BETADIST function and how to use it in Excel, so I have a pretty good handle on that. I understand that you provide your x, alpha, beta, and optionally, lower and upper bounds, and the function returns the cumulative beta probability density function.

For example, =BETADIST(0.2,1.57,2) gives me 0.1803.

The problem is, I'm no statistician, and have no idea what it is doing behind the scenes to get the 0.1803 value in order to recreate it. I've checked the Wikipedia pages, among others, and all of those formulas are greek to me.

Can anyone help break down this function for me and explain how that value is logically derived in my example above, using those numbers? That will greatly help me figure out how to rewrite it.

Thanks in advance!
Mark
 
OK, this works better, but not great.

On entry, it computes a scale factor used in the subsequent calls to Func. Func itself is computed in log space, and then the scale factor is added before it's exponentiated.

=BETADIST(0.3, 401, 1001, 0, 1) returns 0.8761, as you noted.

=BetaDist1(0.3, 401, 1001, 0, 1) with nInt set to 500 returns 0.8725. With nInt set to 10000, it returns 0.8759, but is noticeably slow.

Code:
Option Explicit
 
' Number of double-intervals; increase for accuracy, decrease for speed
Const nInt          As Long = 10000
 
'======================= B e t a D i s t  E x a m p l e  =======================
' shg 2010-1223
 
' Beta distribution parameters
Public mAlpha       As Double
Public mBeta        As Double
Public miScale      As Long
 
Function Func(x As Double) As Double
    ' The evaluated function for BetaDist
 
    ' computed as a log and then scaled by Exp(miScale)
    ' to accommodate numerical precision
 
    If x = 0 Then
        Func = 0
    ElseIf x = 1 Then
        Func = 1
    Else
        Func = (mAlpha - 1) * Log(x) + (mBeta - 1) * Log(1 - x)
        Func = Exp(Func + miScale)
    End If
 
    'Func = x ^ (mAlpha - 1) * (1 - x) ^ (mBeta - 1)
End Function
 
' The UDF/VBA function itself
Function BetaDist1(ByVal x As Double, _
                   alpha As Double, beta As Double, _
                   Optional A As Double = 0#, Optional B As Double = 1#) As Variant
 
    ' shg 2008/2011
 
    ' For arguments, see Excel Help for BETADIST
 
    Dim d1          As Double   ' result of left-side integration
    Dim d2          As Double   ' result of right-side integration
 
    If alpha <= 0# Or beta <= 0# Or _
       x < A Or x > B Or _
       A = B Then
        BetaDist1 = CVErr(xlErrNum)
 
    Else
        mAlpha = alpha
        mBeta = beta
        x = (x - A) / (B - A)           ' scale x to interval
 
        ' set the scale factor for Func
        miScale = 300 - (mBeta - 1) * Log(1 - (1 - x) / nInt)
 
        d1 = SimpsonInt(0#, x, nInt)    ' get left-side integral
        d2 = SimpsonInt(x, 1#, nInt)    ' get right-side integral
        BetaDist1 = d1 / (d1 + d2)      ' compute ratio of left side to total
    End If
End Function
 
'============= G e n e r a l   S i m p s o n   I n t e g r a t o r =============
Private Function SimpsonInt(xi As Double, xf As Double, ByVal n As Long) As Double
    ' shg 2006
 
    ' Returns the integral of Func (specific to problem) over the interval xi to xf
    ' using the Composite Simpson's Rule over n intervals
 
    Dim i           As Double  ' index
    Dim dH          As Double  ' step size
    Dim dF          As Double   ' cumulative integration of f
 
    If n < 1 Then Exit Function
    n = n * 2
    dH = (xf - xi) / n
 
    dF = Func(xi)                          ' initial value
 
    For i = 1 To n - 1 Step 2
        dF = dF + 4 * Func(xi + i * dH) ' odd values
    Next i
 
    For i = 2 To n - 2 Step 2
        dF = dF + 2 * Func(xi + i * dH) ' even values
    Next i
 
    dF = dF + Func(xi)                  ' final value
 
    SimpsonInt = dF * dH / 3
End Function

Side note: there is an online calculator for BetaDist at http://www.solvemymath.com/online_m...cs/continuous_distributions/beta/cdf_beta.php

Plug those numbers in, and you get (drum roll) ... a divide by zero error. I'm not alone :biggrin:
 
Last edited:
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Well that had a hideous mistake. This is much better behaved, and converges much faster.

=BETADIST(0.3, 401, 1001, 0, 1) returns 0.876099

=BetaDist1(0.3, 401, 1001, 0, 1) with nInt set to 100 returns 0.876111, pretty darn close

Code:
Option Explicit
 
' Number of double-intervals; increase for accuracy, decrease for speed
Const nInt          As Long = 100
 
'======================= B e t a D i s t  E x a m p l e  =======================
' shg 2010-1223
 
' Beta distribution parameters
Public mAlpha       As Double
Public mBeta        As Double
Public miScale      As Long
 
Function Func(x As Double) As Double
    ' The evaluated function for BetaDist
 
    ' computed as a log and then scaled by Exp(miScale)
    ' to accommodate numerical precision
 
    If x = 0 Or x = 1 Then
        Func = 0
    Else
        Func = (mAlpha - 1) * Log(x) + (mBeta - 1) * Log(1 - x)
        Func = Exp(Func + miScale)
    End If
 
    'Func = x ^ (mAlpha - 1) * (1 - x) ^ (mBeta - 1)
End Function
 
Function BetaDist1(ByVal x As Double, _
                   alpha As Double, beta As Double, _
                   Optional A As Double = 0#, Optional B As Double = 1#) As Variant
    ' shg 2008/2011
    ' For arguments, see Excel Help for BETADIST
 
    Dim d1          As Double   ' result of left-side integration
    Dim d2          As Double   ' result of right-side integration
 
    If alpha <= 0# Or beta <= 0# Or _
       x < A Or x > B Or _
       A = B Then
        BetaDist1 = CVErr(xlErrNum)
 
    Else
        mAlpha = alpha
        mBeta = beta
        x = (x - A) / (B - A)           ' scale x to interval
 
        ' set the scale factor for Func
        miScale = 300 - (mBeta - 1) * Log(1 - (1 - x) / nInt)
 
        d1 = SimpsonInt(0#, x, nInt)    ' get left-side integral
        d2 = SimpsonInt(x, 1#, nInt)    ' get right-side integral
        BetaDist1 = d1 / (d1 + d2)      ' compute ratio of left side to total
    End If
End Function
'============= G e n e r a l   S i m p s o n   I n t e g r a t o r =============
Private Function SimpsonInt(xi As Double, xf As Double, ByVal n As Long) As Double
    ' shg 2006
 
    ' Returns the integral of Func (specific to problem) over the interval xi to xf
    ' using the Composite Simpson's Rule over 2n intervals
 
    Dim i           As Double  ' index
    Dim dH          As Double  ' step size
    Dim dF          As Double   ' cumulative integration of f
 
    If n < 1 Then Exit Function
    n = 2 * n
    dH = (xf - xi) / n
 
    dF = Func(xi)                       ' initial value
 
    For i = 1 To n - 1 Step 2
        dF = dF + 4 * Func(xi + i * dH) ' odd values
    Next i
 
    For i = 2 To n - 2 Step 2
        dF = dF + 2 * Func(xi + i * dH) ' even values
    Next i
 
    dF = dF + Func(xf)                  ' final value
 
    SimpsonInt = dF * dH / 3
End Function
 
Upvote 0
ssgh4421,

Once again thank you so much for sticking with me on this and helping with this function. That's too funny that those parameters produced an error on another online calculator :LOL:. Leave it to me to find the weirdest parameter combinations possible. Although, to my credit, I wasn't the one that came up with those parameters, so I'll blame it on the subject matter experts. I've already asked if they could come up with some different numbers for those cases, but again, if Excel can do it, I need to be able to do it.

Anyway, it looks like you've found a solid solution, so I'll try to incorporate your changes into my Oracle function and see how it works.

Thanks again! You. Are. Awesome.
Mark
 
Upvote 0
Hi shg4421,

In the =BetaDist1(0.3, 401, 1001) example, I'm getting an unexpected number when stepping through the VBA code for miScale at this line:

Code:
' set the scale factor for Func
  miScale = 300 - (mBeta - 1) * Log(1 - (1 - x) / nInt)

Which ends up being...
Code:
' set the scale factor for Func
  miScale = 300 - (1001 - 1) * Log(1 - (1 - 0.3) / 100)

After stepping into that line, the code is saying miScale = 307. However, when I type in (what I think is) the same formula below into an Excel cell, it gives me 303.0508.

Code:
=300 - (1001 - 1) * LOG(1 - (1 - 0.3) / 100)

Any idea why there is a difference?

Thanks!
Mark
 
Upvote 0
You're welcome, but this is much less robust because of the log evaluation. I'm sure a more rigorous solution is possible. Use with caution.
 
Upvote 0
http://www.techonthenet.com/excel/formulas/log.php

Looks like, in VBA, the log function returns the natural log of a number, which is why it's 307, instead of the logarithm of 303.0508.

That's weird that the same-named (LOG) function does two entirely different things between Excel and VBA.

So, LN() in Excel actually equals LOG() in VBA.

Oh well... is natural log what we want?
 
Last edited:
Upvote 0
It doesn't matter what base you use -- the purpose is just to eliminate overflow errors (run-time errors) and minimize underflow (lose significant data).
 
Upvote 0
Hi guys

Would you be able to post your SQL implementation of the beta code? I'm trying to implement something too, where i need to return a probability for all records in a table, each of which have different beta parameters contained in separate fields and a couple of general parameters which don't change on each process run. Any help gratefully appreciated...

Cheers
 
Last edited:
Upvote 0
Hi Dango, I ended up finding out about a Java library that already had the betadist function defined. So, I loaded that library and am now calling the Java function. It works perfectly. See the solution for this approach from MichaelS in this thread:

https://forums.oracle.com/forums/thread.jspa?messageID=9240804&#9240804

But, thanks to shg, I was originally able to derive the following PL/SQL code, which helped me understand the function much more. I haven't looked at it in awhile, and I'm not sure if I ever got it 100% correct, although it was really close. Sorry, the formatting didn't quite remain intact.

Hope this helps!
Mark

Code:
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]CREATE [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]OR [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]REPLACE [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]FUNCTION[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] EV_370[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff].[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#808000][FONT=Courier][SIZE=2][COLOR=#808000][FONT=Courier][SIZE=2][COLOR=#808000]F_BETADIST[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_x [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_alpha [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_beta [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_a [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]DEFAULT [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_b [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]DEFAULT [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]) [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]RETURN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IS[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_x [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Reassignment variable for i_x[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_alpha [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Beta distribution parameter[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_beta [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Beta distribution parameter[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_d1 [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Result of left-side integration[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_d2 [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Result of right-side integration[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_scale [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Sets the scale factor for F_CALC_FUNC[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]r_f_betadist [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Return value [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]c_interval [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]CONSTANT [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]200[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Number of double-intervals; Increase for accuracy, decrease for speed[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]c_zero [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]CONSTANT [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- For binary comparison[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]c_one [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]CONSTANT [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- For binary comparison[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT]
[I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]/*******************************************************************************************************************[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[SIZE=2][FONT=Courier][COLOR=#008000][I][SIZE=2][FONT=Courier][COLOR=#008000]Function Name: F_CALC_FUNC[/COLOR][/FONT][/SIZE][/I]
[I][SIZE=2][FONT=Courier][COLOR=#008000]Function Desc: The evaluated function for F_BETADIST[/COLOR][/FONT][/SIZE][/I]
[I][SIZE=2][FONT=Courier][COLOR=#008000]Computed as a log and then scaled by Exp(miScale) to accommodate numerical precision[/COLOR][/FONT][/SIZE][/I]
[I][SIZE=2][FONT=Courier][COLOR=#008000]********************************************************************************************************************/[/COLOR][/FONT][/SIZE][/I][/COLOR][/FONT][/SIZE][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]FUNCTION[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] F_CALC[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_calc_val [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]) [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]RETURN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IS[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]r_f_calc [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]BEGIN[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IF[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_calc_val [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]0 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]OR[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_calc_val [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]) [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]THEN[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]r_f_calc [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]RETURN[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] r_f_calc[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]ELSE[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]r_f_calc [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:= [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_alpha [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff])[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] * [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]LN([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_calc_val[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff])[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]+[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_beta [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff])[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] * [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]LN([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_calc_val[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]r_f_calc [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:= [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]EXP([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]r_f_calc [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]+[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_scale[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]RETURN[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] r_f_calc[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]END [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IF;[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]END[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] F_CALC[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]/**************************************************************************************************[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[SIZE=2][FONT=Courier][COLOR=#008000][I][SIZE=2][FONT=Courier][COLOR=#008000]Function Name: F_SIMPSON[/COLOR][/FONT][/SIZE][/I]
[I][SIZE=2][FONT=Courier][COLOR=#008000]Function Desc: General Simpson Integrator[/COLOR][/FONT][/SIZE][/I]
[I][SIZE=2][FONT=Courier][COLOR=#008000]Returns the integral of Func (specific to problem) over the interval xi to xf[/COLOR][/FONT][/SIZE][/I]
[I][SIZE=2][FONT=Courier][COLOR=#008000]using the Composite Simpson's Rule over 2n intervals[/COLOR][/FONT][/SIZE][/I]
[I][SIZE=2][FONT=Courier][COLOR=#008000]***************************************************************************************************/[/COLOR][/FONT][/SIZE][/I][/COLOR][/FONT][/SIZE][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]FUNCTION[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] F_SIMPSON[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_xi [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_xf [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_n [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]) [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]RETURN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IS[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier][SIZE=2][FONT=Courier]v_i [/FONT][/SIZE][/FONT][/SIZE][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- index[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_i_val [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- reassignement variable for v_i[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_n [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- reassignment variable for i_n[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_dh [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- step size[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_df [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- cumulative integration of f[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]r_f_simpson [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]BINARY_DOUBLE [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Return value[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]BEGIN[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IF[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_n [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]>= [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]THEN[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_n [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:= [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] * i_n[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_dh [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:= [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_xf [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_xi[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff])[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]/[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_n[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Initial value[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_df [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] F_CALC[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_xi[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Odd values[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]FOR[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_i [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]..[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_n [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]LOOP[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IF [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]MOD([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_i[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]) [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]0 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]THEN[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- v_i is even[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]NULL;[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]ELSE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- v_i is odd[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_df [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_df [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]+[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]4[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] * F_CALC[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_xi [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]+[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_i * v_dh[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]END [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IF;[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]END [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]LOOP;[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Even values[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]FOR[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_i [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]..[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_n [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]2[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]LOOP[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IF [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]MOD([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_i[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]) [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]0 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]THEN[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- v_i is even [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_df [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_df [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]+[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] * F_CALC[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_xi [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]+[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_i * v_dh[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]ELSE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- v_i is odd[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]NULL;[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]END [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IF;[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]END [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]LOOP;[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Final value[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_df [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_df [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]+[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] F_CALC[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_xf[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]r_f_simpson [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_df * v_dh [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]/[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]3[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]RETURN[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] r_f_simpson[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]ELSE[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]RETURN [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]END [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IF;[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]END[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] F_SIMPSON[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]BEGIN[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IF[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_alpha [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]<=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] c_zero [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]OR[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_beta [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]<=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] c_zero [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]OR[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_x [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]<[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_a [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]OR[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_x [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]>[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_b [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]OR[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_a [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_b [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]THEN[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]RAISE_APPLICATION_ERROR[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff](-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]20000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000][FONT=Courier][SIZE=2][COLOR=#ff0000]'Invalid beta distribution parameters'[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]ELSE[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_alpha [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_alpha[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_beta [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_beta[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_x [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_x[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_x [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_x [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_a[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff])[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]/[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]i_b [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] i_a[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- scale to intervalb[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_scale [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]300[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_beta [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff])[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] * [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]LN([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000][FONT=Courier][SIZE=2][COLOR=#800000]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]-[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_x[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff])[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]/[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] c_interval[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_d1 [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] F_SIMPSON[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]c_zero[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_x[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] c_interval[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- get left-side integral[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_d2 [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] F_SIMPSON[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_x[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] c_one[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff],[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] c_interval[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- get right-side integral[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT]
[I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- When v_d1 + v_d2 = 0, then the function will produce an error because you can't divide by zero.[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- To get around this, I return a binary_double data type, which return NAN in these cases.[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- Then, using NVL, I can substitute zero for these values.[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]r_f_betadist [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]:=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_d1 [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]/[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]([/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2]v_d1 [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]+[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] v_d2[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]);[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][I][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000][FONT=Courier][SIZE=2][COLOR=#008000]-- compute ratio of left side to total[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]RETURN[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][FONT=Courier][SIZE=2] r_f_betadist[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]END [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]IF;[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff]END [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#808000][FONT=Courier][SIZE=2][COLOR=#808000][FONT=Courier][SIZE=2][COLOR=#808000]F_BETADIST[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff][FONT=Courier][SIZE=2][COLOR=#0000ff];[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier][COLOR=#0000ff]/[/COLOR][/FONT][/SIZE]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
 
Upvote 0
Thanks Mark

I'm using Microsoft SQL 2008 so if i can't find some pre-existing code, i'll try and figure out a way to implement it there. In the meantime, thanks for your help!

Dango
 
Upvote 0

Forum statistics

Threads
1,215,506
Messages
6,125,197
Members
449,214
Latest member
mr_ordinaryboy

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