Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab and Root Mean Square help

  1. Apr 16, 2006 #1
    Matlab and Root Mean Square help plz...

    So I have this given data:

    year = [1928:4:1936 1948:4:1956 1964:4:2000];

    time = [12.2 11.9 11.5 11.9 11.5 11.5 11.4 11.08 11.07 11.08 11.06 10.97 10.54 10.82 10.94 10.75];

    and after plotting it (time vs. year), I am told to find the best first order least squares fit to the data by a line using the polyfit function.

    I am then told to find the root mean square error in this line and then plotting that best line?

    How would I go about doing this?

    When I did this, I used the function Fit1=polyfit(year, time, 1);

    Fit1 came out to equal -0.0185 47.6837 which, when plotted on the same graph as the original data resembled nothing like it.

    What am I doing wrong?
  2. jcsd
  3. May 21, 2006 #2
    You did everything right, you probably just didnt interpret the answer right

    Fit1 is a vector of the polynomial coefficient in descending order

    In this case its telling you the best linear fit for the data is
    time = -0.0185*year + 47.6837

    One easy way of plotting this thing would be to plot your old data first and then make a new time vector corresponding to the linear fit

    timefit = Fit1(1)*year + Fit1(2);

    hold on;

    This will plot the linear fit over the original data in green

    To find the standard deviation we need to sum up the squares of the differences from the linear fit to the actual data, and then take the square root of all that junk.

    for n = 1:length(year)
    vect_error(n) = abs(time(n)^2 - timevect(n)^2);

    stan_dev = sqrt(sum(vect_error));

    (I get 6.7437 for the standard deviation - which seems reasonable from the plot of the two when comparing)
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Matlab and Root Mean Square help
  1. Roots in Matlab (Replies: 4)