# How to find unknown parameters from experimental data fitted to an equation?

조회 수: 11(최근 30일)
lala 2020년 11월 11일
편집: Jon 2020년 11월 12일
I am working on involves fitting experimental data to a model function y = a(1)*exp(-1*(x/t(1))) + a(2)*exp(-1*(x/t(2))) + a(3)*exp(-1*(x/t(3)))
My experimental data from a graph are:
x = [-1.220657277 0 0.234741784 0.328638498 0.516431925 0.798122066 1.549295775 3.098591549 5.915492958 9.014084507 12.53521127 17.98122066 21.87793427 26.05633803 30.14084507 33.84976526 38.21596244 43.75586854 48.16901408 51.45539906 53.99061033 57.27699531 60.37558685 63.61502347]
y = [0.996409336 1 0.870736086 0.748653501 0.612208258 0.482944345 0.342908438 0.213644524 0.127468582 0.087971275 0.062836625 0.041292639 0.032315978 0.023339318 0.017953321 0.014362657 0.010771993 0.005385996 0.003590664 0.001795332 0 0 0 0]
Equation:
y = a(1)*exp(-1*(x/t(1))) + a(2)*exp(-1*(x/t(2))) + a(3)*exp(-1*(x/t(3)))
There are six unknowns in the function:
a(1) a(2) a(3) t(1) t(2) t(3)
May I know how to find the 6 unknowns that give the best fit of experimental data and the function?

댓글을 달려면 로그인하십시오.

### 채택된 답변

Jon 2020년 11월 11일
If you have the Optimization Toolbox you can use the function lsqcurvefit for solving this problem. Type doc lsqcurvefit on your command line for documentation
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Jon 2020년 11월 12일
You are misunderstanding how to use the lsqcurvefit function. Please look at the first example in https://www.mathworks.com/help/optim/ug/lsqcurvefit.html which is quite similar to your problem.
Note that lsqcurvefit finds the vector parameter values that best fit the data using the function that you provide. In the documenation, MATLAB refers to this parameter vector as x, which I think is a little confusing as xdata are the independent variables. I would of called the unknown parameters, p, or some other variable name, but of course the name doesn't really matter as long as you understand what it stands for.
Anyhow, here is an example of how you might code your problem. You should check the details to make sure it is exactly the function you wanted, but it should give you an idea of how to code this.
xdata = [-1.220657277 0 0.234741784 0.328638498 0.516431925 0.798122066 1.549295775 3.098591549 5.915492958 9.014084507 12.53521127 17.98122066 21.87793427 26.05633803 30.14084507 33.84976526 38.21596244 43.75586854 48.16901408 51.45539906 53.99061033 57.27699531 60.37558685 63.61502347];
ydata = [0.996409336 1 0.870736086 0.748653501 0.612208258 0.482944345 0.342908438 0.213644524 0.127468582 0.087971275 0.062836625 0.041292639 0.032315978 0.023339318 0.017953321 0.014362657 0.010771993 0.005385996 0.003590664 0.001795332 0 0 0 0];
% define function to approximate the data
% using parameter vector p where p represents [a(1) a(2) a(3) t(1) t(2)
% t(3)]
fun = @(p,xdata) p(1)*exp(-xdata/p(4)) + p(2)*exp(-xdata/p(5)) + p(3)*exp(-xdata/p(6));
p0 = ones(6,1);
% solve for parameters that provide best fit to data
p = lsqcurvefit(fun,p0,xdata,ydata)
% assign parameters to a and t in case you want those separately
a = p(1:3);
t = p(4:6);
% compare data with fitted curve
yfit = fun(p,xdata);
plot(xdata,ydata,'o',xdata,yfit,'-')
Note that the results may be dependent upon the initial guess p0. I had no idea what were reasonable starting values so I arbitrarily set all of the values to 1.
The results show that it fits well with all of the a values equal and all of the t values equal. This suggests that you could fit the data well with just a simple exponential (just one scaling value a and one time constant). If this is the case you could take the log of both sides and then just fit using a standard linear least squares fit

댓글을 달려면 로그인하십시오.

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by