Problem using nlinfit . The code works with a random model function that I found on the web, but not with my model functions
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Tom Lane
on 12 Apr 2013
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.
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!