Curve Fitting

Standard memberRemoved
Posers and Puzzles 08 Jul '14 20:35
  1. R
    Standard memberRemoved
    Joined
    10 Dec '06
    Moves
    8528
    08 Jul '14 20:35
    I'm trying to curve fit 3 data points. The system has the characteristics of the general function:

    Y(x) = C*(1-e^(-b*x))

    I have 3 ordered pairs (0,0),(y1,x1),(y2,x2).

    I can solve for the undetermined constants (C & b) numerically from;

    y_1 = C*(1-e^(-b*x_1))

    y_2 = C*(1-e^(-b*x_2))

    The solution (0,0) is naturally a consequence of the equations form.

    However, after I do that the curve fits (0,0) and (x_1,y_1), but falls short on matching (x_2,y_2). What is the explanation for this?
  2. Joined
    26 Apr '03
    Moves
    26771
    08 Jul '14 21:31
    Originally posted by joe shmo
    I'm trying to curve fit 3 data points. The system has the characteristics of the general function:

    Y(x) = C*(1-e^(-b*x))

    I have 3 ordered pairs (0,0),(y1,x1),(y2,x2).

    I can solve for the undetermined constants (C & b) numerically from;

    y_1 = C*(1-e^(-b*x_1))

    y_2 = C*(1-e^(-b*x_2))

    The solution (0,0) is naturally a consequence of the eq ...[text shortened]... s (0,0) and (x_1,y_1), but falls short on matching (x_2,y_2). What is the explanation for this?
    That is a hard equation to solve!

    how did you do it?!
  3. R
    Standard memberRemoved
    Joined
    10 Dec '06
    Moves
    8528
    08 Jul '14 22:15
    Originally posted by iamatiger
    That is a hard equation to solve!

    how did you do it?!
    There were actual numbers (I didn't solve it generally) I used a spreadsheet.

    From:
    y_1 = C*(1-e^(-b*x_1))

    C = y_1/(1-e^(-b*x_1)) eq(2)

    y_2 = C*(1-e^(-b*x_2)) eq(3)

    Sub eq(2)--> eq(3)

    y_2 = y_1/(1-e^(-b*x_1))*(1-e^(-b*x_2))

    Solve for b from

    y_1/(1-e^(-b*x_1))*(1-e^(-b*x_2)) - y_2 = 0

    procedure:

    initial guess on b
    look for positive to negative change
    increase precision around change
    Lather
    Rinse
    Repeat

    Solve for "C" from eq(2)
  4. Joined
    26 Apr '03
    Moves
    26771
    09 Jul '14 07:33
    Any chance of your initial numbers? It is an interesting conundrum, but I think the solution does depend quite strongly on the numbers because of the powers (and can the values be complex numbers, by the way?)
  5. R
    Standard memberRemoved
    Joined
    10 Dec '06
    Moves
    8528
    09 Jul '14 11:101 edit
    Originally posted by iamatiger
    Any chance of your initial numbers? It is an interesting conundrum, but I think the solution does depend quite strongly on the numbers because of the powers (and can the values be complex numbers, by the way?)
    Sure,

    (y,x)
    (0,0)
    (3430,6.417)
    (4250,16.917)

    The solution for "b" I found was between 0.26 - 0.27, C = 4201.78

    If you mean the values of the constants being imaginary, I would say probably not.
  6. Standard memberAThousandYoung
    or different places
    tinyurl.com/2tp8tyx8
    Joined
    23 Aug '04
    Moves
    26660
    09 Jul '14 22:56
    Looks like logarithms might help
  7. Standard memberAThousandYoung
    or different places
    tinyurl.com/2tp8tyx8
    Joined
    23 Aug '04
    Moves
    26660
    10 Jul '14 07:091 edit
    Originally posted by joe shmo
    Sure,

    (y,x)
    (0,0)
    (3430,6.417)
    (4250,16.917)

    The solution for "b" I found was between 0.26 - 0.27, C = 4201.78

    If you mean the values of the constants being imaginary, I would say probably not.
    As x approaches infinity, y will approach C because it will be y=C*(1-0). That should be a maximum. Therefore your C cannot equal 4201.78 while your y equals 4250 in the third point. You need a C that is greater than 4250.
  8. Joined
    26 Apr '03
    Moves
    26771
    10 Jul '14 20:543 edits
    I found that eliminating B worked

    B = -ln(1-y1/C)/x1

    which then gives

    x2/x1 = ln(1-y2/C)/ln(1-y1/C)

    ln(1-y2/C)/ln(1-y1/C) - x2/x1 crosses zero when C is between 4316.498599 and 4316.4986

    so I estimated C to be 4316.4985995 and calculated B to be 0.24667606

    These values fit your input data very well indeed

    However eliminating C also worked:

    C = y1/(1-exp(1-Bx1)
    y2/y1 = (1-exp(-Bx2))/(1-exp(-Bx1))

    {where exp(x) means e^x}

    these gave exactly the same values for B and C, and look the same as your equations, so perhaps there was a typo somewhere when you did you lathering,, rinsing and repeating? Perhaps did your function exp() mean 10^x or something like that?
  9. Joined
    26 Apr '03
    Moves
    26771
    11 Jul '14 17:471 edit
    looking at what you said again, I don't suppose you wrote b down wrongly Joe?
    b is between 0.246 and 0.247 ....
  10. R
    Standard memberRemoved
    Joined
    10 Dec '06
    Moves
    8528
    11 Jul '14 21:03
    Originally posted by iamatiger
    looking at what you said again, I don't suppose you wrote b down wrongly Joe?
    b is between 0.2[b]4
    6 and 0.247 ....[/b]
    No... I re-checked my equation, and found I flipped some signs being sloppy with the algebra...oddly enough the solution to the wrong equation was somewhat close to the proper equations solution!

    Anyhow, thanks for you help in spotting the error!
Back to Top

Cookies help us deliver our Services. By using our Services or clicking I agree, you agree to our use of cookies. Learn More.I Agree