1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Richardson extrapolation matlab error

  1. Sep 21, 2014 #1
    Hi everyone, I am trying to differentiate a function by means of Richardson Extrapolation in MATLAB. However, I could not run the program. Here are the outputs and its codes. Could anyone explain to me
    what is my mistake? The codes are based on "Numerical Methods Using MATLAB by John H. Matthews and
    Kurtis D. Fink (International Edition)".

    >> f = @(x) x^2;
    >> toler = 0.005;
    >> function [L,n] = difflim(f,x,toler)
    function [L,n] = difflim(f,x,toler)
    Error: Function definitions are not permitted in this context.


    function [L,n] = difflim(f,x,toler)
    %Input - f is the function input as a string 'f'
    % - x is the differentiation point
    % - toler is the tolerance for the error
    %Output - L=[H' D' E']
    % H is the vector of step sizes
    % D is the vector of approximate derivatives
    % E is the vector of error bounds
    % n is the coordinate of the "best approximation"
    max1 = 15;
    h = 1;
    H(1) = h;
    D(1) = (feval(f,x+h)-feval(f,x-h))/(2*h);
    E(1) = 0;
    R(1) = 0;

    for n = 1:2
    h = h/10;
    H(n+1) = h;
    D(n+1) = (feval(f,x+h)-feval(f,x-h))/(2*h);
    E(n+1) = abs(D(n+1)+abs(D(n))+eps);

    n = 2;


    L=[H' D' E'];
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted