Hello, I am trying to fit some data points with an exponential equation.
24 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a set of experimental X and Y values. I am trying to fit an exponential equation through these data points by minimizing the sum of the squares between the experimental Y and Y from the equation. The exponential function has two constants that need to changed to minimize the error. It is very similar to using the solver function in excel, where you give a starting guess value and the solver tries to find a solution hat satisfies the minimal error / objective.
Sorry, I am a first time Matlab user, hence need some extra help. Thanks in advance.
0 个评论
回答(3 个)
Matt Kindig
2012-12-13
Hi Krish,
There are a couple of different ways to do this. Do you have the Optimization Toolbox or Curve Fitting Toolbox? If so, type
ver
at the Matlab prompt '>>' and see if the Optimization Toolbox or Curve Fitting Toolbox are listed. Both make this sort of thing quite a bit easier, and I would use these toolboxes if available.
If all you have is basic Matlab, you can do it like this:
%x and y are your variables
expfn = @(p,xd) p(1)*exp(p(2)*xd); %define exponential function
errfn = @(p) sum((expfn(p,x)-y).^2); %define sum-squared error
pfit = fminsearch( errfn, [0 0]); %run the minimizer
plot(x,y,'bo'); hold on; %plot your raw data
plot(x, expfn(pfit, x), 'r-'); %plot the fit data
To understand this, you should search the documentation on anonymous functions and the 'fminsearch' function.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!