1

I have the following equation:

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.

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.

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

1
  • 5
    You could do a polynomial regression by fitting to the log(y) data instead of the y data. Commented Jan 23, 2015 at 15:06

2 Answers 2

3

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:

We get:

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:

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

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

X = A^{*} * 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) 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.

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_statistics

Sign up to request clarification or add additional context in comments.

15 Comments

@A.Donda - ok. I'll remove them then. That's very true. The second and third lines were unnecessary.
@A.Donda - Nope! I deal with linear algebra and numerical methods almost every day. It just so happens that I have found someone who knows more about it than I do :). I certainly welcome your edits. Please suggest more changes if there are more!
Thanks to both of you; your discussion was very informative for me haha +1 each :)
@A.Donda - I embarrassingly forgot to include the assumption that the errors come from a normal distribution as you have stated in your post. I've amended my post some more.
The OP will be well educated by our combined efforts. :-)
|
3

One approach is to use a linear regression of log(y) with respect to u² and a³:

Assuming that u, a, and y are column vectors of the same length:

AB = [u .^ 2, a .^ 3] \ log(y)

After this, AB(1) is the fit value for A and AB(2) is the fit value for B. The computation uses Matlab's mldivide operator; an alternative would be to use the pseudo-inverse.

The fit values found this way are Maximum Likelihood estimates of the parameters under the assumption that deviations from the exact equation are constant-variance normally distributed errors additive to A u² + B a³. If the actual source of deviations differs from this, these estimates may not be optimal.

3 Comments

ah shoot. I didn't see this answer here. I spent all this time typing up the equations in LaTeX lol. Nice job. I'll leave my answer in so someone can see how the above code is justified.
@rayryeng, yours has just been accepted by the OP. :-) But have a look at my comment, there are some minor problems in your answer.
Oops :) Sorry to do that lol.... but I do thank you for your comments. I'll amend my post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.