【问题标题】:Exponential Curve Fitting in MatlabMatlab中的指数曲线拟合
【发布时间】:2014-06-08 19:10:19
【问题描述】:

我有一个加载到matlab 的数据集。我需要在不使用曲线拟合工具cftool的情况下对绘制的曲线进行指数拟合。

我想通过执行一个代码/函数手动执行此操作,该代码/函数将输出与等式对应的ab的值:

 y = a*exp(b*x)

然后使用这些值,我将进行错误优化并创建最适合我拥有的数据。

有什么帮助吗?

提前致谢。

【问题讨论】:

  • 您好,您的曲线是函数图吗,即(x,a*exp(b*x))?在这种情况下,我建议使用标准方法,通过 Levenberg-Marquardt、梯度下降、Gauß-Newton 最小化最小二乘误差。如果您想节省时间并且可以使用优化工具箱的功能lsqnonlin。示例:data_x = [0,1,2,3]; data_y = [0.5,1.5,4.5,13.5]; residua = @(x) x(1) * exp(data_x * x(2)) - data_y; lsqnonlin(residua,[1,1])

标签: matlab curve-fitting


【解决方案1】:

试试这个...

f = fit(x,y,'exp1');

【讨论】:

    【解决方案2】:

    我认为这种类型分配的典型目标是认识到通过取两边的对数,可以使用各种多项式拟合方法。

        ln(y) = ln(a) + ln( exp(x).^b ) 
        ln(y) = ln(a) + b * ln( exp(x) )
    

    当由于 ln 接近零时的行为而涉及诸如噪声之类的错误时,这种方法可能会遇到困难。

    【讨论】:

      【解决方案3】:

      在本练习中,我有一组呈现指数曲线的数据,我想以指数方式拟合它们并获得 a 和 b 的值。我使用了以下代码,它与我拥有的数据一起工作。

      "trail.m" file: 
       %defining the data used 
       load trialforfitting.txt;
       xdata= trialforfitting(:,1); 
       ydata= trialforfitting(:,2); 
      
       %calling the "fitcurvedemo" function
       [estimates, model] = fitcurvedemo(xdata,ydata)
       disp(sse); 
      
       plot(xdata, ydata, 'o'); %Data curve
      
       hold on
       [sse, FittedCurve] = model(estimates);
      
       plot(xdata, FittedCurve, 'r')%Fitted curve
      xlabel('Voltage (V)')
      ylabel('Current (A)')
      title('Exponential Fitting to IV curves');
      legend('data', ['Fitting'])
      hold off
      
      "fitcurvedemo.m" file: 
      function [estimates, model] = fitcurvedemo(xdata, ydata)
      %Call fminsearch with a random starting point.
      start_point = rand(1, 2);
      model = @expfun;
      estimates = fminsearch(model, start_point);
      %"expfun" accepts curve parameters as inputs, and outputs 
      %the sum of squares error [sse] expfun is a function handle;
      %a value that contains a matlab object methods and the constructor
      %"FMINSEARCH" only needs sse
      %estimate returns the value of A and lambda
      %model computes the exponential function 
          function [sse, FittedCurve] = expfun(params)
              A = params(1);
              lambda = params(2);
              %exponential function model to fit
              FittedCurve = A .* exp(lambda * xdata); 
              ErrorVector = FittedCurve - ydata;
              %output of the expfun function [sum of squares of error]
              sse = sum(ErrorVector .^ 2);
      
           end
       end
      

      我有一组新数据不适用于此代码,并为绘制的数据曲线提供适当的指数拟合。

      【讨论】:

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