From: Steven Lord on 12 Jul 2010 10:25 "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message news:i1bcd4$o8i$1(a)fred.mathworks.com... > Hi All, > > I am having trouble with fitting. Here's a simple version of what I am > trying: > > clear all > x=[1:100]; > y=0.1*sin(x)+2; > s = fitoptions('Method','LinearLeastSquares','Lower',[0 0]); > ffun = > fittype('a*sin(x)+b','coefficients',{'a','b'},'independent','x','options',s); > f=fit(x',y',ffun) > > And here's what I get: > ??? No appropriate method, property, or field startpoint for class > curvefit.llsqoptions. > > Error in ==> fit at 325 > start = options.startpoint; > > Matlab helps tells me that when I have "LinearLeastSquares" as a method I > have the option to set a lower limit to the fit. This is driving me > crazy.. I need to get the lower limit to the fit since the function I am > really using in my code -log(a^x+b^x)/log(2) calculates complex values > when x is a negative integer, and a and b are negative and my code stops > there. You're creating the options structure for a linear least squares fit, but then creating a fittype for a general expression that FITTYPE can't tell is linear. In fact, if you use the ISLINEAR method on ffun, it will return false. Try creating ffun in such a way that FITTYPE can tell that the expression is linear. ffun = fittype({'sin(x)','1'}, 'independent','x','options',s); ISLINEAR on this fittype returns true, and when I use your FIT call above with this ffun it works as expected. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: Aino on 15 Jul 2010 09:00 "Steven Lord" <slord(a)mathworks.com> wrote in message <i1f8jt$p9r$1(a)fred.mathworks.com>... > > "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message > news:i1bcd4$o8i$1(a)fred.mathworks.com... > > Hi All, > > > > I am having trouble with fitting. Here's a simple version of what I am > > trying: > > > > clear all > > x=[1:100]; > > y=0.1*sin(x)+2; > > s = fitoptions('Method','LinearLeastSquares','Lower',[0 0]); > > ffun = > > fittype('a*sin(x)+b','coefficients',{'a','b'},'independent','x','options',s); > > f=fit(x',y',ffun) > > > > And here's what I get: > > ??? No appropriate method, property, or field startpoint for class > > curvefit.llsqoptions. > > > > Error in ==> fit at 325 > > start = options.startpoint; > > > > Matlab helps tells me that when I have "LinearLeastSquares" as a method I > > have the option to set a lower limit to the fit. This is driving me > > crazy.. I need to get the lower limit to the fit since the function I am > > really using in my code -log(a^x+b^x)/log(2) calculates complex values > > when x is a negative integer, and a and b are negative and my code stops > > there. > > You're creating the options structure for a linear least squares fit, but > then creating a fittype for a general expression that FITTYPE can't tell is > linear. In fact, if you use the ISLINEAR method on ffun, it will return > false. > > Try creating ffun in such a way that FITTYPE can tell that the expression is > linear. > > ffun = fittype({'sin(x)','1'}, 'independent','x','options',s); > > ISLINEAR on this fittype returns true, and when I use your FIT call above > with this ffun it works as expected. > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ > To contact Technical Support use the Contact Us link on > http://www.mathworks.com > Thank you, Steve. Now I have a bad feeling that I have been wrestling with this problem before.. Does Matlab Help clarify how that {'sin(x)','1'} is actually created, I mean what's the logic behind that notation? I would have to get -log(a^x+b^x)/log(2) into that form.. -Aino
From: Steven Lord on 15 Jul 2010 14:22 "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message news:i1n0p6$74b$1(a)fred.mathworks.com... > "Steven Lord" <slord(a)mathworks.com> wrote in message > <i1f8jt$p9r$1(a)fred.mathworks.com>... *snip* > Thank you, Steve. > > Now I have a bad feeling that I have been wrestling with this problem > before.. Does Matlab Help clarify how that {'sin(x)','1'} is actually > created, I mean what's the logic behind that notation? The help text for FITTYPE does (help fittype) and the reference page for FITTYPE indicate that you need to use that syntax for the fitting functions to recognize your fit as a linear fit. http://www.mathworks.com/access/helpdesk/help/toolbox/curvefit/fittype.html > I would have to get -log(a^x+b^x)/log(2) into that form.. That is not a linear fit; it is not in the form a*f(x)+b*g(x)+c*h(x)+... For that you will need to use a nonlinear fitting method. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: Aino on 15 Jul 2010 18:04
"Steven Lord" <slord(a)mathworks.com> wrote in message <i1njkt$9sn$1(a)fred.mathworks.com>... > > "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message > news:i1n0p6$74b$1(a)fred.mathworks.com... > > "Steven Lord" <slord(a)mathworks.com> wrote in message > > <i1f8jt$p9r$1(a)fred.mathworks.com>... > > *snip* > > > Thank you, Steve. > > > > Now I have a bad feeling that I have been wrestling with this problem > > before.. Does Matlab Help clarify how that {'sin(x)','1'} is actually > > created, I mean what's the logic behind that notation? > > The help text for FITTYPE does (help fittype) and the reference page for > FITTYPE indicate that you need to use that syntax for the fitting functions > to recognize your fit as a linear fit. > > http://www.mathworks.com/access/helpdesk/help/toolbox/curvefit/fittype.html > > > I would have to get -log(a^x+b^x)/log(2) into that form.. > > That is not a linear fit; it is not in the form a*f(x)+b*g(x)+c*h(x)+... > For that you will need to use a nonlinear fitting method. > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ > To contact Technical Support use the Contact Us link on > http://www.mathworks.com > Thank you Steve, it seems I don't have a problem after all, except perhaps in my basic knowledge about the subject.. -Aino |