Question:

Convert ax^2+bx+c into ax^2 - Curve fitting using MATLAB?

by  |  earlier

0 LIKES UnLike

Hi,

I am using MATLAB to fit a curve to data. I have a physics formula of the form y=ax^2 and I am trying to determine the value of the constant _a_ using the data. When I fit a second degree polynomial to the data (using polyfit), MATLAB gives me the constants a b and c of the polynomial in the form of ax^2 + bx + c. Of course, that doesn't help me find a for my formula. The extra terms of power<2 throw me off. I need a polynomial of the form ax^2 + 0x + 0 that fits the data. How can I accomplish this?

 Tags:

   Report

3 ANSWERS


  1. a more creative approach:

    polyfit(log(x),log(y),1) gives two constants say ‘p’ and ‘q’

    so ln(y)=pln(x)+q

    originally y=a*x^2

    so ln(y)=2ln(x)+2ln(a)

    100*(p-2)/2 is the approximation error and a=e^(q/2)

    --------------------------------------...


  2. Just a thought.  You may try doing this iteratively in MATLAB.  Start out with the ax^2 + bx + c you get from polyfit, then just set b and c to 0.  Next, using a for loop, iteratively adjust the a-value until the error between the curve and the points are minimized.

  3. This can be solved in closed form. Say you have N data points (xi, yi), and you want to find variable A that minimizes the least-squares error

    E = sum [(A*xi^2 - yi)^2]

    Taking the derivative with respect to A and setting to zero gives:

    sum [2*(A*xi^2 - yi) * xi^2] = 0

    sum[A * xi^4 - xi^2 * yi] = 0

    A * sum[xi^4] = sum[xi^2 * yi]

    A = sum[xi^2 * yi] / sum[xi^4]

    So, in matlab, this is a one-liner:

    A = sum(x.^2 .* y) / sum(x.^4)

    Of course, if your values in vectors x and y are big, this won&#039;t be very well conditioned, so you can precondition (normalize) the data first and then un-normalize after solving if that&#039;s a problem.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions