This seems to maybe work. I added an annotation to the FDiff line, and then it gave me an error about the 1.0<'A> constant, so I changed that on the next line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
type Curve<[<Measure>] 'A, [<Measure>] 'B> (F, MinX, MaxX) as this =
    let MinX : float<'A> = MinX
    let MaxX : float<'A> = MaxX
    let F : float<'A> -> float<'B> = F;
 
    member this.GetValue (x : float<'A>) : float<'B> = 
        if x >= MinX && x <= MaxX then F(x) else 0.0<_>
 
    member this.FindRoot (x0 : float<'A>) (x1 : float<'A>) = 
        // 
        let rec DoStep a b = 
            if abs (float(F a)) < delta then a
            else 
                let c = (F(b) * a - F(a) * b) / (F(b) - F(a))
                if sign(F(a)) = sign(F(c)) then DoStep c b
                else DoStep a c
        DoStep x0 x1 * 1.0<_>   
 
    // Gets the intersection of F1 and F2
    static member FindIntersection (curve1 : Curve<'A, 'B>) (curve2 : Curve<'A, 'B>) (x0 : float<'A>) (x1 : float<'A>) = 
        let FDiff (x: float<'A>) : float<'B> = curve1.GetValue(x) - curve2.GetValue(x)
        let oneA = box 1.0 :?> float<'A>  
        let DCurve : Curve<'A, 'B> = Curve<'A, 'B>(FDiff, oneA, oneA)
        DCurve.FindRoot x0 x1
By on 12/5/2010 10:57 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper