how to express a formula for modelFun fo nlinfit

5 views (last 30 days)
Hello, guys,
I have the formula (convolution):
where
and C is a matrix 1x40 and t is also a matrix of 1x40.
I want to use the first formula for non-linear least square fit (nlinfit), but I don't know how to write modelFun to express this formula, where MTT is a parameter, which I need to estimate.
Thanks for a reply!
Donatas

Accepted Answer

Star Strider
Star Strider on 3 Apr 2014
Edited: Star Strider on 3 Apr 2014
I made several guesses as to what you are doing, but this seems to work:
% Create data:
t = linspace(0, 1, 40);
C = t;
% y = conv(t,exp(-t),'same');
y = conv(exp(-t/7),t);
% Objective function for curve fit
% w = @(P,t) conv(C, exp(-t/P),'same');
w = @(P,t) conv(C, exp(-t/P));
xv = 0:length(y)-1;
B = nlinfit(t, y, w, 1)
yp = w(B,t);
figure(1)
plot(xv, y, 'xb')
hold on
plot(xv, w(B,t), '-r')
hold off
grid
Note that there are 'full', 'same' and 'valid' options with the conv function. Use the one that most closely suits your needs.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!