Problem with non linear fit model
Afficher commentaires plus anciens
I was trying to do the nonlinear fit model. Here is the function and program:
function Zel = TangentialElectrode1st(fre,Q4,a4,Rsep,Q2,a2,Rion,Rcont)
Z1 = Rcont
Zs = CPE (fre(:),Q2,a2)
Z2 = ((Rion*Zs).^0.5).*coth((Rion./Zs).^0.5)
Z3 = Rsep
Z4 = CPE (fre(:),Q4,a4)
Z23= (Z2*Z3)/(Z2+Z3)
Z234 = (Z23*Z4)/(Z23+Z4)
Zel = Z234+Z1
end
modelfun = @(P,fre) TangentialElectrode1st(fre(:,1),P(1),P(2),P(3),P(4),P(5),P(6),P(7));
beta0 = [Q4,a4,Rsep,Q2,a2,Rion,Rcont]
mdl = nlinfit(fre,Zd,modelfun,beta0)
However, the matlab indicated that:
Error using nlinfit (line 211) MODELFUN must be a function that returns a vector of fitted values the same size as Y (150-by-1). The model function you provided returned a result that was 1-by-1.
One common reason for a size mismatch is using matrix operators (, /, ^) in your function instead of the corresponding elementwise operators (., ./, .^).
SO what could be the problem?
Réponses (1)
Stephan
le 27 Juin 2018
Hi,
check the size of:
Z23= (Z2*Z3)/(Z2+Z3)
Z234 = (Z23*Z4)/(Z23+Z4)
maybe you should also use .* and ./ here
Z23= (Z2.*Z3)./(Z2+Z3)
Z234 = (Z23.*Z4)./(Z23+Z4)
Best regards
Stephan
Catégories
En savoir plus sur Statistics and Machine Learning Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!