Curve fitter app with custom function

Hi, I have a gaussian function y=A*exp(-(x-mu).^2/(2*sigma^2)).
I want to use custom equation in curve fitter. The default setting in the custom equation is a*exp(-b*x)+c.
How should I key in mu and sigma in custom equation? I put "a*exp(-(x-b).^2/(2*c^2))" but the curve doesn't look correct.
I used Gaussian option with 'gauss2' and the curve looks fine but the equation for gauss2 is not exactly same as my custom function. that's why I want to use custom function. Please advise.
thanks.

 Accepted Answer

If you are using cftool, then when you get to the place to enter the custom equation, you can just enter
A*exp(-(x-mu).^2/(2*sigma^2))
and it will estimate all of the parameters.
Note: you might want to consider adding a constant term to the equation.

6 Comments

Now I tried default Gaussian "Term 2" without center. From the attached tuningpic.fig, the half width of half max is obviously not 127 degree which I get from default gaussian. c1 from the fitting is very big.
Could you suggest which setting I should use. I attached my data as tuningvalues (Orientation_vect is x and TuningCurve_Avg_vect is y). Thanks.
I used cftool.
Can you insert the picture in your post. Otherwise I'd have to save the .fig file to disk, switch over to MATLAB, open that .fig file just to see it. (I didn't bother.) It's much easier if you just put it here.
Also I have a version that works with fitnlm if you have the Statistics and Machine Learning Toolbox. Ask me if you want my demo.
I attched the figure to .jpeg file.
When you fit with Gauss2 model, notice that each of the coefficient confidence bounds crosses 0 badly. That reflects the fact that there is no priority to the two terms, so if you have a1*this + a2*that and one should be negative but the other should be positive, then the fit cannot tell the difference between negative*this + positive*that and negative*that + positive*this since the "this" and "that" values could be exchanged (because they have the same forms.)
If you use the Fit Options in cftool to select Advanced Options, and you go down to Coefficient Constraints, and you set the Lower bound for a1 to 0 so that the terms are no longer interchangable, then you get a much better looking fit that only goes up to 180 instead of up to 900.
Hi Walter, thanks a lot for explanation. I changed the Lower bound for a1 to 0. I got a better fitted graph with these coefficients.
though a2 is reduced to around 180 as you said, a1 is pretty higher than the raw data.
a1 = 1.583e+06 (-5.126e+08, 5.158e+08)
b1 = 706.8 (-1.249e+04, 1.391e+04)
c1 = 129.7 (-1933, 2192)
a2 = 179.6 (-466.8, 826.1)
b2 = 121.9 (77.94, 165.9)
c2 = 23.27 (-31, 77.53)
Actually, I am following the below bold method for fitting. I don't think I can find equal width sigma using cftool. could you please suggest? I first time use Gaussian fitting so I am quite lost. thanks again for your help.
I would suggest constraining b1 as well to positive... keep constraining more variables to positive until you stop getting coefficients that cross 0 in the confidence bounds.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!