Reputation: 345
I have a curve that looks like an exponentiel function, I would like to fit this curve with this equation :
The goal is to find the value of A
, T
and d
which will minimize V
with my initial curve.
I did a function that is able to do it but it takes 10 seconds to run.
3 loops that test all the values that I want to and at the end of the 3 loops I calculate the RMSD (root mean square deviation) between my 2 curves and I put the result in a vector min_RMSN
, at the end I check the minimum value of min_RMSD
and it's done...
But this is not the best way for sure.
Thank you for your help, ideas :)
Upvotes: 4
Views: 1034
Reputation: 114250
Matlab has a built in fminsearch
function that does pretty much exactly what you want. You define a function handle that takes the RMSE of your data vs. the function fit, pass in your initial guess for A
, T
and d
, and get a result:
x0 = [A0, T0, d0]
fn = @(x) sum((x(1) * (1 - exp(-x[2] / (t - x[3]))) - y).^2)
V = fminsearch(@fn, x0)
Here t
is the x-data for the curve you have, y
are the corresponding y-values and, A0
, T0
, d0
are the initial guesses for your parameters. fn
computes the suquare of the RMSE between your ideal curve and y
. No need to take the square root since you minimizing the square will also minimize the RMSE itself, and computing square roots takes time.
Upvotes: 1