Path: news.mathworks.com!not-for-mail From: "John D'Errico" <woodchips@rochester.rr.com> Newsgroups: comp.soft-sys.matlab Subject: Re: 3rd derivative function Date: Thu, 10 May 2012 17:04:30 +0000 (UTC) Organization: John D'Errico (1-3LEW5R) Lines: 41 Message-ID: <jogseu$e05$1@newscl01ah.mathworks.com> References: <jogmqk$hqn$1@newscl01ah.mathworks.com> <jogs3h$cat$1@newscl01ah.mathworks.com> Reply-To: "John D'Errico" <woodchips@rochester.rr.com> NNTP-Posting-Host: www-01-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1336669470 14341 172.30.248.46 (10 May 2012 17:04:30 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 10 May 2012 17:04:30 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 869215 Xref: news.mathworks.com comp.soft-sys.matlab:767427 "Roger Stafford" wrote in message <jogs3h$cat$1@newscl01ah.mathworks.com>... > "Nina " <ninakuklisova@uchicago.edu> wrote in message <jogmqk$hqn$1@newscl01ah.mathworks.com>... > > I know this is really simple but I can't see what's wrong now. I'm trying to write a 3rd derivative approximation that uses the first derivative, of an initial function that is the exponential. I've been trying to run this code: > > > > if x >=0 > > then f(x) = exp((x)); > > end > > if x <0 > > then f(x) = 1/(exp((-x))); > > end > > f1(x) = (f(x+h)-f(x-h))/(2*h); > > f3(x) = (3/(h^3))*(f(x+h)-f(x-h)-2*h*f1(x)) > - - - - - - - - - > Besides the difficulty you are having defining f, your difference equation approximating the third derivative is incorrect. It should be: > > f'''(x) = (f(x+2*h)-f(x-2*h)-2*(f(x+h)-f(x-h)))/(2*h^3) > > This means that after receiving the value of x you must evaluate f at four different points, f(x-2*h), f(x-h), f(x+h), and f(x+2*h), and the value of f(x) is not needed. Also somewhere you need to define h. > > I am puzzled as to why you wish to distinguish between negative and non-negative values of x. The single definition > > f = @(x) exp(x) > > will cover both cases since exp(x) = 1/(exp(-x) for all x. > > Roger Stafford There is at least one other error. For example, if x <0 then f(x) = 1/(exp((-x))); end But, we should know that 1/exp(-x) == exp(x) so I'm not at all sure why one would bother to try making a piecewise function out of this. John