From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 3rd derivative function
Date: Thu, 10 May 2012 11:06:24 -0500
Organization: NNTP Server
Lines: 50
Message-ID: <jogp25$h4s$>
References: <jogmqk$hqn$> <jognlo$d1u$> <jogogj$pnm$>
Reply-To: <HIDDEN>
NNTP-Posting-Host: JFgm6aMVwmC/
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
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: 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


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

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.