fitting data to implicit function
显示 更早的评论
I have an experimental data with first column an independent variable and the second column a dependent variable. I need to estimate 2 parameters k and b. My model is actually a system o equations. The code of the model is below:
function y=calc_bg1(x,z) for ii=1:length(z) syms b gbg k n p r rgbg1 rgbg2 rgbg3 rgbg4 positive b=x(1); k=x(2); n=z(ii); [gbg,p,r,rgbg1,rgbg2,rgbg3,rgbg4]=solve(4*r*gbg == (k)*rgbg1, 3*rgbg1*gbg == 2*(k)*b*rgbg2, 2*rgbg2*gbg == 3*(k)*(b^2)*rgbg3, 1*rgbg3*gbg == 4*(k)*(b^3)*rgbg4, r+rgbg1+rgbg2+rgbg3+rgbg4 == 7*166e-9, gbg+rgbg1+2*rgbg2+3*rgbg3+4*rgbg4 == n*166e-9, (.97*rgbg4+0.03*7*166e-9)*52806306*0.19 == p*1e-3 ,gbg,p,r,rgbg1,rgbg2,rgbg3,rgbg4); pp(ii)=double(p); clear gbg n p r rgbg1 rgbg2 rgbg3 rgbg4 end y=pp'; When I am trying to do the fit with lsqcurvefit lsqcurvefit(@calc_bg1,[.4 7e-6],test1(:,1)',test1(:,2)) Improper assignment with rectangular empty matrix.
Error in calc_bg1 (line 9) pp(ii)=double(p);
Error in lsqcurvefit/objective (line 261) F = feval(funfcn_x_xdata{3},x,XDATA,varargin{:});
Error in snls (line 329) newfvec = feval(funfcn{3},xcurr,varargin{:});
Error in lsqncommon (line 155) [xC,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msgData]= ...
Error in lsqcurvefit (line 253) [xCurrent,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Can anybody help?
3 个评论
Karan Gill
2017-11-10
Please format your code. It's really hard to read.
Daniel Yakubovich
2017-11-10
Daniel Yakubovich
2017-11-10
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!