MATLAB Answers

How to do exponential curve fitting like y=a.* log(x + b.*exp(c.*x)

11 views (last 30 days)
Hi everybody,
I need to do nonlinear regression analysis. I have written a code for that and the function is in the form y=a.* log(x + b.*exp(c.*x). The variables a, b, c are unknowns. The matlab code is as follows.
x = load('xval.txt');
y = load('yval.txt');
f = @(b,x) b(1).*(log(x + (b(2).*exp(b(3).*x)))); % Objective Function
B = fminsearch(@(b) norm(y - f(b,x)), [2; -0.1; -5]) % Estimate Parameters
figure(1)
plot(x, y, 'pg')
hold on
plot(x, f(B,x), '-r')
hold off
grid
xlabel('x')
ylabel('f(x)')
I am unable to estimate the above parameters. Could anyone explain how to estimate [2; -0.1; -5]. But I could not fit the curve with the data. The X and Y values are attached. Like this I have 20 sets of xval and yval.
Thanks in advance.
Rajaram

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 27 Feb 2021
You can do something like this:
mod_fcn = @(b,x) b(1).*(log(x + (b(2).*exp(b(3).*x)))); % Objective Function
err_fcn = @(b,x,y,dy,f) sum((y-f(b,x)).^2./dy^2); % Allowing for weighted LSQ
B = fminsearch(@(b) err_fcn(b,x,y,ones(size(y)),mod_fcn), [2; -0.1; -5]) % Estimate Parameters
plot(xval,yval,xval,mod_fcn(B,xval))
Doesn't look like a particularly good fit, but that's what you get. More suitable model-function? Mixed up/confused the data?
HTH

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by