指数曲线拟合Matlab [英] Exponential curve fit matlab

查看:700
本文介绍了指数曲线拟合Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下等式:

我想对上述方程使用MATLAB进行指数曲线拟合,其中y = f(u,a). y是我的输出,而(u,a)是我的输入.我想找到一组提供的数据的系数A,B.

I want to do a exponential curve fitting using MATLAB for the above equation, where y = f(u,a). y is my output while (u,a) are my inputs. I want to find the coefficients A,B for a set of provided data.

我知道如何通过定义状态来对简单多项式执行此操作.例如,如果使用states= (ones(size(u)), u u.^2),则会得到L+Mu+Nu^2,其中LMN是回归系数.

I know how to do this for simple polynomials by defining states. As an example, if states= (ones(size(u)), u u.^2), this will give me L+Mu+Nu^2, with L, M and N being regression coefficients.

但是,上述公式并非如此.如何在MATLAB中执行此操作?

However, this is not the case for the above equation. How could I do this in MATLAB?

推荐答案

在@eigenchris所说的基础上,只需取等式两边的自然对数(在MATLAB中为log).如果这样做,我们实际上将在log空间中将方程线性化.换句话说,根据您的原始方程式:

Building on what @eigenchris said, simply take the natural logarithm (log in MATLAB) of both sides of the equation. If we do this, we would in fact be linearizing the equation in log space. In other words, given your original equation:

我们得到:

但是,这并非完全是多项式回归.这更像是最小二乘拟合.具体来说,您将获得一组y点和一组(u,a)点对,您将构建一个方程组,并通过最小二乘法求解该系统.换句话说,给定集合y = (y_0, y_1, y_2,...y_N)(u,a) = ((u_0, a_0), (u_1, a_1), ..., (u_N, a_N)),其中N是您拥有的点数,您将像这样构建方程组:

However, this isn't exactly polynomial regression. This is more of a least squares fitting of your points. Specifically, what you would do is given a set of y and set pair of (u,a) points, you would build a system of equations and solve for this system via least squares. In other words, given the set y = (y_0, y_1, y_2,...y_N), and (u,a) = ((u_0, a_0), (u_1, a_1), ..., (u_N, a_N)), where N is the number of points that you have, you would build your system of equations like so:

这可以用矩阵形式写成:

This can be written in matrix form:

要求解AB,您只需要找到最小二乘解.您可以看到它的形式为:

To solve for A and B, you simply need to find the least-squares solution. You can see that it's in the form of:

Y = AX

要解决X,我们使用称为 pseudoinverse .因此:

To solve for X, we use what is called the pseudoinverse. As such:

X = A^{*} * Y

A^{*}是伪逆.这可以在MATLAB中使用\mldivide运算符雄辩地完成.您要做的就是使用log构建y值的向量,以及构建ua值的矩阵.因此,如果将点(u,a)分别存储在UA中,并将y的值存储在Y中,则只需执行以下操作:

A^{*} is the pseudoinverse. This can eloquently be done in MATLAB using the \ or mldivide operator. All you have to do is build a vector of y values with the log taken, as well as building the matrix of u and a values. Therefore, if your points (u,a) are stored in U and A respectively, as well as the values of y stored in Y, you would simply do this:

x = [u.^2 a.^3] \ log(y);

x(1)将包含A的系数,而x(2)将包含B的系数.正如A. Donda在回答中指出的那样(我尴尬地忘记了这一点),AB的值是在假定相对于您要拟合的精确曲线的误差正常(高斯)的情况下获得的以恒定的方差分布.误差也需要加法.如果不是这种情况,则您获得的参数可能无法代表最佳拟合.

x(1) will contain the coefficient for A, while x(2) will contain the coefficient for B. As A. Donda has noted in his answer (which I embarrassingly forgot about), the values of A and B are obtained assuming that the errors with respect to the exact curve you are trying to fit to are normally (Gaussian) distributed with a constant variance. The errors also need to be additive. If this is not the case, then your parameters achieved may not represent the best fit possible.

有关最小二乘拟合采用的假设的更多详细信息,请参见此Wikipedia页面:

See this Wikipedia page for more details on what assumptions least-squares fitting takes:

http://en.wikipedia.org/wiki/Least_squares#Least_squares.2C_regression_analysis_and_statistic

这篇关于指数曲线拟合Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆