Hello, I am trying to fit some data points with an exponential equation.
조회 수: 22 (최근 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!