【问题标题】:Exponential fitting for matlabmatlab的指数拟合
【发布时间】:2017-04-19 17:49:41
【问题描述】:

我有我的数据在像 e^(ax+c)+d 这样的指数型数组中。我正在尝试为他们画一个合适的。

a = data1 (:,1);
b = data1 (:,2);
log(b);
p = polyfit (a,log(b),1);

但我现在不知道该怎么办。我通过 polyfit 找到了一个方程,我希望将我从 polyfit 得到的方程的指数与

exp (0.5632x+2.435) 

但我发现它不是那样工作的。有人有什么建议吗?

【问题讨论】:

    标签: matlab exponential


    【解决方案1】:

    尝试非线性拟合:

    %% PARAMETERS (you need this part)
    clear all;
    clc, clf;
    
    N        = 128; % number of datapoints
    Nint     = N*10; % number of datapoints for curve interpolation
    fun      = @(prms,x)  prms(4).^(prms(1)*x+prms(2))+prms(3); % write your function
    iniPrm = rand(4,1); % find some initial values for the parameters (choose meaningful values for better results)
    
    %% SIMULATE DATA (this is only for testing purposes)
    SNR      = .01; % signal to noise ratio for simulated data 
    noise    = (rand(1,N)-.5)*SNR; % create some random noise 
    x        = linspace(0,10,N); % create the x axis
    y        = fun(iniPrm,x) + noise; % simulate a dataset that follows the given function
    x        = x(:); % reshape as a vector
    y        = y(:); % reshape as a vector
    X        = linspace(x(1),x(end),Nint); % interpolate the output to plot it smoothly
    plot(x,y,'.r','markersize',10); hold on; % plot the dataset
    %% FIT AND INTERPOLATE YOUR MODEL
    [out.BETA,out.RESID,out.J,out.COVB,out.MSE] = nlinfit(x,y,fun,iniPrm,[]); % model your data
    [out.YPRED,out.DELTA]  = nlpredci(fun,X,out.BETA,out.RESID,'Covar',out.COVB); % interpolate your model
    out.YPREDLOWCI         = out.YPRED - out.DELTA; % find lower confidence intervals of your fitting
    out.YPREDUPCI          = out.YPRED + out.DELTA; % find upper confidence intervals of your fitting
    out.X                  = X; % store the interpolated X
    %% PLOT FITTING
    plotCI = @(IO,spec) patch([IO.X(:);flipud(IO.X(:))],[IO.YPREDLOWCI(:);flipud(IO.YPREDUPCI(:))],spec{:}); % create patches: IE: patch(0:10,10:-1:0,ones(10,1)-1,1,{'r','facealpha',0.2})
    plot(X,out.YPRED,'-b','linewidth',3);
    plotCI(out,{'r','facealpha',.3,'edgealpha',0})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-22
      • 1970-01-01
      • 1970-01-01
      • 2013-05-22
      • 2014-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多