Path: news.mathworks.com!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 3rd derivative function
Date: Thu, 10 May 2012 11:06:24 -0500
Organization: Aioe.org NNTP Server
Lines: 50
Message-ID: <jogp25$h4s$1@speranza.aioe.org>
References: <jogmqk$hqn$1@newscl01ah.mathworks.com> <jognlo$d1u$1@speranza.aioe.org> <jogogj$pnm$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: JFgm6aMVwmC/YQNQyUTYRQ.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:767419

On 5/10/2012 10:57 AM, Nina wrote:
> Thank you, Nasser!
>
> The full code is this:
>
> h = input ('Type the value of h: ');
> x = input ('Type the value of x: ');
> h = str2num('h');
> x = str2num('x');
> 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))
>
> I was thinking it had the necessary values for evaluating the function, but apparently, it still doesn't...


my version of Matlab does not have 'then'. I do not know what version
you have that has this keyword.

But try this

---------------------------
h=0.1;
x=1;

if x >=0
     f = @(x) exp((x));
else
     f = @(x) 1/(exp((-x)));
end

f1 = (f(x+h)-f(x-h))/(2*h)
f3 = (3/(h^3))*(f(x+h)-f(x-h)-2*h*f1(x))
---------------------------------------------

No need to deal with input from keyboard at initial
pass. Just define your variables in the code. Once
the algorithm works ok, then you can go fancy
and read the input from the keyboard. Do one thing at
a time. Also I think the way you are reading the input
from keyboard is not quite right.

--Nasser