MATLAB我想尽量减少差异拟合

时间:2016-06-30 08:14:01

标签: matlab optimization

我有一条看起来像指数函数的曲线,我想用这个等式拟合这条曲线:

enter image description here

目标是找到ATd的值,这将使我的初始曲线最小化V

我做了一个能够做到的功能,但需要10秒才能运行。 3个循环测试我想要的所有值,并在3个循环结束时计算我的2条曲线之间的RMSD(均方根偏差),并将结果放在向量min_RMSN中,最后我检查了min_RMSD的最小值并完成了它...

但这不是最好的方式。

感谢您的帮助,想法:)

1 个答案:

答案 0 :(得分:1)

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.