Trouble with Curve Fitting a Custom Fit Function

Hello,

I am new to Igor and trying to fit a custom fit function. However I continue to get a ""The fitting function returned NaN for at least one X value." error, which I thought was due to my initial guesses being too far off to fit the function, but I no longer think that that is the issue because the fit function seems to lay directly on top of the plot.

I have attached my Igor experiment as I am not sure how else to show my problem. Please let me know what more I need to show to better explain my predicament.
Single Slit Testing.pxp
I re-wrote you fit function so that I could read it more easily, and added a conditional with print statement to pinpoint where the problem is. Here is my version of your function:
Function SingleSlit(w,theta) : FitFunc
    Wave w
    Variable theta

    //CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
    //CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
    //CurveFitDialog/ Equation:
    //CurveFitDialog/ f(theta) = y0+ (I0*(((sin(((3.14*a)/lambda)*sin(theta)))/(((3.14*a)/lambda)*sin(theta)))^(2)))
    //CurveFitDialog/ End of Equation
    //CurveFitDialog/ Independent Variables 1
    //CurveFitDialog/ theta
    //CurveFitDialog/ Coefficients 4
    //CurveFitDialog/ w[0] = I0
    //CurveFitDialog/ w[1] = a
    //CurveFitDialog/ w[2] = lambda
    //CurveFitDialog/ w[3] = y0

    Variable numerator = sin(((3.14*w[1])/w[2])*sin(theta))
    Variable denominator = ((3.14*w[1])/w[2])*sin(theta)
    Variable value = w[3]+ (w[0]*(((numerator)/(denominator))^(2)))
    if (numtype(value) != 0)
        print "Uh oh"
    endif
    return value
End

This makes it easy to see that if theta=0, then both numerator and denominator are zero. Dividing zero by zero is not well defined:) I see that one of your Angle points is zero.

I also put a breakpoint on the "Uh oh" line and ran the function from the command line: print singleslit(w_coef, 0). It broke into the debugger as expected. If your function had been more complex and not amenable to separation as I re-wrote it, the debugger would have given me a chance to investigate just what was going on. I often use this technique of testing the return value in order to make a good place to put a breakpoint that doesn't break every time it runs, just when it goes wrong.

If you're not familiar with Igor's symbolic debugger, read this:
DisplayHelpTopic "The Debugger"

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com