sophialll 发表于 2011-4-18 10:34

matlab多参数指数拟合如何实现

我有一组数据
x=
y=
绘出来像个指数函数。我猜想它是指数函数,用matlab进行拟合,但是指数的底不知道,还有N多其他参数也不知道,应该如何拟合啊,求高手帮忙,要具体程序过程。我编了好几个程序都运行不成功。

sophialll 发表于 2011-4-18 10:41

初始回归系数也不清楚。

qibbxxt 发表于 2011-4-18 10:57

General model Exp2:
   f(x) = a*exp(b*x) + c*exp(d*x)
Coefficients (with 95% confidence bounds):
       a =      0.1916(0.1792, 0.204)
       b =      -0.319(-0.3373, -0.3006)
       c =   0.04072(0.03814, 0.04329)
            d =    -0.04487(-0.0476, -0.04214)

Goodness of fit:
SSE: 1.669e-006
R-square: 0.9997
Adjusted R-square: 0.9997
RMSE: 0.0002754

function createFit(x,y)
%CREATEFIT Create plot of data sets and fits
%   CREATEFIT(X,Y)
%   Creates a plot, similar to the plot in the main Curve Fitting Tool,
%   using the data that you provide as input.You can
%   use this function with the same data you used with CFTOOL
%   or with different data.You may want to edit the function to
%   customize the code and this help message.
%
%   Number of data sets:1
%   Number of fits:1% Data from data set "y vs. x":
%   X = x:
%   Y = y:
%   Unweighted% Auto-generated by MATLAB on 18-Apr-2011 10:56:55% Set up figure to receive data sets and fits
f_ = clf;
figure(f_);
set(f_,'Units','Pixels','Position',);
% Line handles and text for the legend.
legh_ = [];
legt_ = {};
% Limits of the x-axis.
xlim_ = ;
% Axes for the plot.
ax_ = axes;
set(ax_,'Units','normalized','OuterPosition',);
set(ax_,'Box','on');
axes(ax_);
hold on;% --- Plot data that was originally in data set "y vs. x"
x = x(:);
y = y(:);
h_ = line(x,y,'Parent',ax_,'Color',,...
    'LineStyle','none', 'LineWidth',1,...
    'Marker','.', 'MarkerSize',12);
xlim_(1) = min(xlim_(1),min(x));
xlim_(2) = max(xlim_(2),max(x));
legh_(end+1) = h_;
legt_{end+1} = 'y vs. x';% Nudge axis limits beyond data limits
if all(isfinite(xlim_))
    xlim_ = xlim_ + [-1 1] * 0.01 * diff(xlim_);
    set(ax_,'XLim',xlim_)
else
    set(ax_, 'XLim',);
end% --- Create fit "fit 1"
ok_ = isfinite(x) & isfinite(y);
if ~all( ok_ )
    warning( 'GenerateMFile:IgnoringNansAndInfs',...
      'Ignoring NaNs and Infs in data.' );
end
st_ = ;
ft_ = fittype('exp2');% Fit this model using new data
cf_ = fit(x(ok_),y(ok_),ft_,'Startpoint',st_);
% Alternatively uncomment the following lines to use coefficients from the
% original fit. You can use this choice to plot the original fit against new
% data.
%    cv_ = { 0.19159877789258178, -0.31895949786907274, 0.040716429909295873, -0.044867078417144955};
%    cf_ = cfit(ft_,cv_{:});% Plot this fit
h_ = plot(cf_,'fit',0.95);
set(h_(1),'Color',,...
    'LineStyle','-', 'LineWidth',2,...
    'Marker','none', 'MarkerSize',6);
% Turn off legend created by plot method.
legend off;
% Store line handle and fit name for legend.
legh_(end+1) = h_(1);
legt_{end+1} = 'fit 1';% --- Finished fitting and plotting data. Clean up.
hold off;
% Display legend
leginfo_ = {'Orientation', 'vertical', 'Location', 'NorthEast'};
h_ = legend(ax_,legh_,legt_,leginfo_{:});
set(h_,'Interpreter','none');
% Remove labels from x- and y-axes.
xlabel(ax_,'');
ylabel(ax_,'');

sophialll 发表于 2011-4-18 13:45

回复 3 # qibbxxt 的帖子

不好意思啊,求教高手,前面的系数是怎么求出来的?直接用的matlab的工具箱吗?还是程序运行的结果啊?

sophialll 发表于 2011-4-18 14:28

回复 3 # qibbxxt 的帖子

另外,您怎么这么厉害,不知道有什么学习经验可以传授一下吗?

meiyongyuandeze 发表于 2011-4-18 14:49

x=;
>> y=;
>> f=fittype('a*exp(b*x)+c*exp(d*x)','coeff',{'a','b','c','d'});
>> =fit(x',y',f)
Warning: Start point not provided, choosing random start point.
> In fit>handlewarn at 705
In fit at 321

c =

General model:
c(x) = a*exp(b*x)+c*exp(d*x)
Coefficients (with 95% confidence bounds):
a = 0.00362 (-0.02079, 0.02803)
b = 0.1983 (-0.107, 0.5036)
c = -3.244e-010 (-1.577e-008, 1.512e-008)
d = 0.7468 (-0.7801, 2.274)


gof2 =

sse: 1.7698
rsquare: -282.6509
dfe: 22
adjrsquare: -321.3306
rmse: 0.2836请教主任,我用的上面的指数函数进行拟合,为什么和你给出的系数差别如此大呢!请指教!

ChaChing 发表于 2011-4-18 14:55

回复 4 # sophialll 的帖子

这有些也是跟qibbxxt学的, 我来补充下
1.command window下cftool
2.>> data %% 输入x,y
3.>> Fitting >> New fit
4. Type of fit >> Exponential >> 选a*exp(b*x) + c*exp(d*x) >> apply
5. File >> Generate M-file

meiyongyuandeze 发表于 2011-4-18 15:29

回复 7 # ChaChing 的帖子

用cftool工具和我自己用代码操作(代码在6楼),选择的函数都是指数函数,为什么拟合的系数差别比较大呢!
个人感觉应该和warning有关,是不是应该给定初值,如果是这样的话,请教您初值一般应该如何给才能保证精度呢?

sophialll 发表于 2011-4-18 19:50

回复 7 # ChaChing 的帖子

:handshake太感谢了,都是高手

ChaChing 发表于 2011-4-18 22:03

回复 8 # meiyongyuandeze 的帖子

最近回帖都没刷新下, 所以都没注意到有新回帖!
以前自己没使用过Curve Fitting Toolbox, 来此为了回帖才稍微看下的
试下你的写法, 的确不同, 但也与你的不同, 我的是R2009a>> f=fittype('a*exp(b*x)+c*exp(d*x)','coeff',{'a','b','c','d'});

>> =fit(x',y',f)
Warning: Start point not provided, choosing random start point.
> In fit>handlewarn at 817
In fit at 380
Maximum number of function evaluations exceeded. Increasing
MaxFunEvals (in fit options) may allow for a better fit, or
the current equation may not be a good model for the data.

c =

   General model:
       c(x) = a*exp(b*x)+c*exp(d*x)
   Coefficients (with 95% confidence bounds):
       a =   -0.0237(-3.612e+004, 3.612e+004)
       b =      0.9074(-234.8, 236.6)
       c =   0.02348(-3.612e+004, 3.612e+004)
       d =      0.9077(-235.7, 237.5)

gof2 =

         sse: 6.5381e+012
       rsquare: -1.0479e+015
         dfe: 22
    adjrsquare: -1.1907e+015
          rmse: 5.4515e+005

ChaChing 发表于 2011-4-18 22:06

本帖最后由 ChaChing 于 2011-4-18 22:09 编辑

比较下与3F的差异, 不难发现是fittype的差异
至於两者的差异, 有空再看看help说明了, 汗, 还没详看

>> f=fittype('exp2');
>> =fit(x',y',f)

c =

   General model Exp2:
       c(x) = a*exp(b*x) + c*exp(d*x)
   Coefficients (with 95% confidence bounds):
       a =      0.1916(0.1792, 0.204)
       b =      -0.319(-0.3373, -0.3006)
       c =   0.04072(0.03814, 0.04329)
       d =    -0.04487(-0.0476, -0.04214)

gof2 =

         sse: 1.6686e-006
       rsquare: 0.9997
         dfe: 22
    adjrsquare: 0.9997
          rmse: 2.7540e-004

ChaChing 发表于 2011-4-20 00:09

回复 8 # meiyongyuandeze 的帖子

我也没发现问题的所在!
无编辑权限了, 不然真想从10F开始分割成另一帖, 因已是另一个问题

meiyongyuandeze 发表于 2011-4-20 08:54

回复 12 # ChaChing 的帖子

我已经将问题抽来,重新分割成另外的一个帖子,请关注讨论!

tre 发表于 2011-4-21 10:48

就那么实现呗!!!

matlabansys 发表于 2011-4-21 11:04

页: [1] 2
查看完整版本: matlab多参数指数拟合如何实现