Problem with non linear fit model

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?

回答 (1 件)

Stephan
Stephan 2018 年 6 月 27 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeCondensed Matter & Materials Physics についてさらに検索

質問済み:

2018 年 6 月 26 日

回答済み:

2018 年 6 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by