Beginner: how to use nlinfit to set parameters and curve fitting?
Show older comments
Dear,
I am fresh with matlab and only followed tutorial with 2 weeks on examples.
I have a assignment for setting parameters and curve fitting.
However, I stucked in the first step, anybody could please help me out?
Thank you in advance.
t=[0 60 120 180 240 300 360 420 480 540 600 660 720]';
q=[295 161 99.1 68.2 50.2 38.6 30.6 24.8 20.5 17.2 14.7 12.6 11]';
plot(t,q,'ko');
xlabel('time(days),t');ylabel('production rate(bbl/day,q');
modelFun=@(b,t)(250/(1+b(1)*t/b(2))^(1/b(1));
beta0=[2,1];
beta=nlinfit(t,q,modelFun,beta0);
yhat = modelFun(beta,t);
figure(1)
plot(t,q,'xb')
Joe
6 Comments
Adam Danz
on 24 Sep 2020
Perhaps going through the examples in the documentation and thinking through each step will be helpful.
Any time you get an error message you should include it in your question. When I ran your code I get this error message. As the message indicates, "check for mismatched delimiters". What's that mean? a newbie may ask. Google's first link led me to the explanation. Long story short, you're missing a closed parenthesis.
modelFun=@(b,t)(250/(1+b(1)*t/b(2))^(1/b(1));
↑
Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check
for mismatched delimiters
Zuojing zhu
on 25 Sep 2020
When I run your code with the function you defined in the comment above, I do not get an error. My previous comment said,
"Any time you get an error message you should include it in your question."
Your previous comment claims to be getting an error message but I still don't see it 😕
the cyclist
on 25 Sep 2020
Reiterating what Adam said, when I run the following code, which has your own fixed syntax in it, I get no error:
t=[0 60 120 180 240 300 360 420 480 540 600 660 720]';
q=[295 161 99.1 68.2 50.2 38.6 30.6 24.8 20.5 17.2 14.7 12.6 11]';
plot(t,q,'ko');
xlabel('time(days),t');ylabel('production rate(bbl/day,q');
modelFun=@(b,t)(250./(1+b(1).*t./b(2)).^(1./b(1)));
beta0=[2,1];
beta=nlinfit(t,q,modelFun,beta0);
yhat = modelFun(beta,t);
figure
plot(t,q,'xb')
Be sure that you saved the code change before you ran it.
Zuojing zhu
on 25 Sep 2020
Adam Danz
on 25 Sep 2020
Sounds like you're on the right path! Keep going!
Answers (0)
Categories
Find more on Descriptive Statistics 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!