Problem using nlinfit . The code works with a random model function that I found on the web, but not with my model functions

1 次查看(过去 30 天)
Please Help. I have two models that I a trying to fit into a set of data, but I get the following error:
??? Error using ==> nlinfit at 120 Error evaluating model function '@(b,t)(((kb-ki)*(1/exp((t*b(1))/b(2))-1))/b(1))'.
Error in ==> regrassion at 53 b1hat=nlinfit(t,y1,wd,b0); %one volume
Caused by: Error using ==> mldivide Matrix dimensions must agree.
Here is my code:
t=[0, 62 ,121, 150]; y1=[0,.1808318, .2245815, .2469898]; kb=2.2; ki=6.67;
wd=@(b,t) (((kb - ki)*(1/exp((t*b(1))/b(2)) - 1))/b(1)); %first model w1d=@(p,t) -((kb - ki)*((((t*p(... %second model solution is quit long so I am not including it here
b0=[100 5]; p0=[100 200 1 8]; %initial guesses
plot(t,y1,'s','markersize',5,'color',[0,0,0]); hold on
b1hat=nlinfit(t,y1,wd,b0); %one volume b2hat=nlinfit(t,y1,w1d,p0) %two volume
I have a feeling that my model functions are not being understood well. I used the symbolic expression to solve for the model functions and when I graph them separately, they both work. They just don't work when I use them as model function. Please help. I greatly appreciate it.

回答(1 个)

Tom Lane
Tom Lane 2013-4-12
It looks like you want "1./exp(...)" in place of "1/exp(...)" so you get the reciprocal of each element instead of a matrix division.
Consider each use of *, /, or ^ in your expression to make sure it's as intended. You may find it easier to debug if you just make sure your function evaluates from the command line with a vector of input values, before you try passing it into nlinfit.

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by