Trying to solve the parameters for an equation

There is a dataset for the following mathematical model, please use MATLAB to find these parameters a1、a2、b1 and b2
x=0:0.1:2
y=[xdata1 xdata2... xdata21]
y=a1*exp(b1*x)+a2*exp(b2*x)
I think it has something to do with fminsearch, but I don't know where to start

 Accepted Answer

fun = @(ab) sum((ab(1)*exp(ab(3)*x) + ab(2) * exp(ab(4)*x) - y).^2)
ab0 = randn(1,4);
AB = fminsearch(fun, ab0);
a1 = AB(1); a2 = AB(2); b1 = AB(3); b2 = AB(4);

4 Comments

What is the use of "randn"?
So I know randn(1,4) give you four random numbers; but what is the use of that in this function?
Nvm, I got it. Thanks m8, much love <3
In this context, ab0 is the starting point for the search. I did not want to presume that the values were positive.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!