Solve for constants of 4-parameter (Rodbard Equation) using Python
Question: I am new to python and what I am trying to do is write an algorithm to solve
for the 4 unknown parameters in the Rodbard Equation where we are relating a
grayscale value measured using ImageJ to optical density calibration discs.
This equation is nonlinear and is written as y = c*((x-a)/(d-x))^(1/b) where
a, b, c, and d are unknown. I have the values of x and y for four point
(176.5, 0), (161.333, 0.1), (66.1667, 0.9), and (40.833, 2.5). Below, I have
posted my attempt to solve for these 4 unknowns. Any help to point me in the
right direction would be greatly appreciated!

    
    
        import scipy.optimize as opt
    
        def f(a, b, c, d):
             0 == [c * ((176.5 - a)/(d - 176.5))**(1/b)]
             0.1 == [c * ((161.333 - a)/(d - 161.333))**(1/b)]
             0.9 == [c * ((66.1667 - a)/(d - 66.1667))**(1/b)]
             2.5 == [c * ((40.833 - a)/(d - 40.833))**(1/b)]
        return f
    
        opt.curve_fit(a, b, c, d)
    
        print a
        print b
        print c
        print d
    


Answer: If you want to use curve_fit, you should do the following:

    
    
    def f(x1, a1, b1, c1, d1):
        return c1 * (((x1 - a1)/(d1 - x1))**1/b1)
    
    x_data = np.array([176.5, 161.333, 66.1667, 40.833])
    y_data = np.array([0., 0.1, 0.9, 2.5])
    p0 = np.array([168., -0.01, -7.4, 35000.])
    
    popt, pcov = opt.curve_fit(f, x_data, y_data, p0, None, False, True, ftol = 0.00001)
    

p0 is the initial guess and if you do not inform it, an array of all ones will
be assumed.

With the provided data I have tried with different params but I've not been
able to find a solution.

I hope this helps. Good luck!

