Hello, I am trying to fit some data points with an exponential equation.
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (3)
Matt Kindig
am 13 Dez. 2012
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.
Matt Fig
am 14 Dez. 2012
Bearbeitet: Matt Fig
am 14 Dez. 2012
>> X = sort(rand(1,10)*30); % Say this is our x data.
>> Y = 14*exp(3*X); % Say this is _unknown_ equation.
>> pp = polyfit(X,log(Y),1); % Get 14, 3 from data only.
>> pp(2) = exp(pp(2))
pp =
3.0000 14.0000
pp should look familiar!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!