MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

Krish
0

Hello, I am trying to fit some data points with an exponential equation.

Krish
さんによって質問されました 2012 年 12 月 13 日
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 件のコメント

サインイン to comment.

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.

  1 件のコメント

Matt,
Sorry I do not have Curve Fitting Tool/Optimization Tool. Hence have to go with the other option.Here is the function I am trying to fit:-
X=[10,20,40,80]; Y=[0.1,0.2,0.3,0.4]; ((C1*exp(-C2/(R*T)))*X)/(1+((C1*exp(-C2/(R*T)))*X))
C1 and C2 are the constants I need to find to fit a curve that will pass through the expt data points
I understood your code, but I need to get the values of C1 & C2 and then use that to plot with X ranging from 1 to 100 in 1 increments and get corresponding Y value, showing goof correlation between experimental and the model.
Again thanks for you time and effort.

サインイン to comment.


回答者: Loginatorist
2012 年 12 月 14 日
編集済み: Loginatorist
2012 年 12 月 14 日

>> 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 件のコメント

サインイン to comment.


回答者: Alan Weiss
2012 年 12 月 14 日

The documentation has a solved example that is similar to what you are trying to do.
Alan Weiss
MATLAB mathematical toolbox documentation

  0 件のコメント

サインイン to comment.



Translated by