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

Matlab loglog scale

  1. Jan 19, 2008 #1
    I am taking a Math/Cmpt class and I am useless with this program that we need to use Matlab.

    Q: The derivative of a function f(x) can be approximated at the point x=x(sub)0 by a forward divided difference

    f'(x(sub)0) ≈ [f(x(sub)0 + h) - f(x(sub)0)] / h

    or by a central divided difference

    f'(x(sub)0) ≈ [f(x(sub)0 + h) - f(x(sub)0)] / 2h

    For the function f(x)= sin x, plot the error as a function of h when these divided differences are used to approximate f'(1) = cos1 for h = 10^-1, 10^-2, 10^-3, ..., 10^-16. Use loglog scale and display your results in one window using subplot.

    As far and the loglog and subplot is concerned I understand what to do... it is the rest of the question that is causing a lot of difficulties. if there are any pointers on where to begin it would be much appreciated.
  2. jcsd
  3. Jan 19, 2008 #2


    User Avatar

    You question is still a bit broad, but I'll bite.

    Firstly I don't think the central difference is defined correctly... it should be
    f'(x_0) = [f(x_0+h/2) - f(x_0-h/2)] / h

    You're being asked to compute the convergence of the error of forward and central differentials, by comparing to the best answer you have available.
    Fortunately your function has a well known analytic differential, otherwise you would have to compare to your best numerical estimate (you will we see how this works when you do the analytical comparison).

    That aside, it seems that the main part of your question is how to compute the numerical differentials. I'm not going to tell you the answer, but you need to set up a vector for h (perhaps using logspace) and calculate the formulas as written. Just remember to use ./h not /h
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Matlab loglog scale
  1. Axis scale in matlab (Replies: 1)