Hello,
I am trying to fit a curve using this function: t is the time vector, x the force measurement, d0 and nu are constants. I want to extract Er, tau1 and tau2.
function [Er,tau1,tau2] = viscoelasticcone(t,x,d0,nu)
fitfunctionconical=sprintf('Er*2*tan(35*pi/180)/(pi*(1-%d^2))*%d^2*(1+(tau1-tau2)/tau2*exp(-t/tau2))',nu,d0);
ftconical=fittype( fitfunctionconical, 'independent', 't', 'dependent', 'F');
[fitresult,R,~,CovB,MSE] = nlinfit(t,x, ftconical,[1e3 0.001 0.001]);
fit=ftconical(fitresult,t);
[Ypred,delta] = nlpredci(ftconical,t,fitresult,R,'Covar',CovB,'MSE',MSE,'SimOpt','on');
confidence{k}=delta;
lower = Ypred - delta;
upper = Ypred + delta;
end
If I use this function however, i get the following error:
Undefined function 'func2str' for input arguments of type 'fittype'.
Error in nlinfit (line 204)
m = message('stats:nlinfit:ModelFunctionError',func2str(model));
Any help ?
Michael

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 11 Aug. 2015

0 Stimmen

You need to call fit() on fit objects returned from fittype(), not nlinfit()

2 Kommentare

Hello Walter,
What about the nlinfit ?
I use fit with option equal to NonLinearLeastSquares but I have a real trouble with the fitting.
s = fitoptions('Method','NonlinearLeastSquares');
fitfunctionconical=sprintf('Er*2*tan(35*pi/180)/(pi*(1-%d))*%d^2*(1+(tau1-tau2)/tau2*exp(-t/tau2))',nu,d0);
ftconical=fittype( fitfunctionconical, 'independent', 't', 'dependent', 'F','coefficients',{'Er','tau1','tau2'},'option',s);
fitresult = fit(t',x, ftconical);
coeffvals = coeffvalues(fitresult);
I get wrong values for the coefficients and the curve is not at all fitted.
All right,
Here my final code:
ftVisco= @(b, t) b(1)*2*tan(35*pi/180)/(pi*(1-nu))*d0^2*(1+(b(2)-b(3))/b(3).*exp(-t./b(3)));
[fitresultnlinfit, R,~,CovB,MSE,Errorinfo] = nlinfit(t',x, ftVisco, [1e3 0.001 0.001]);
fitresultnlinfit
[Ypred,delta] = nlpredci(ftVisco,t',fitresultnlinfit,R,'Covar',CovB,'MSE',MSE);
confidence=delta;
lower = Ypred - delta;
upper = Ypred + delta;
It seems to work well.
Thank you Walter for pointing me out that we can't use fittype for nlinfit.
Cheers

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by