From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help! Rounding without using preset MATLAB functions
Date: Sat, 20 Nov 2010 23:34:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 22
Message-ID: <ic9ltc$rtb$>
References: <ic9io4$792$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1290296044 28587 (20 Nov 2010 23:34:04 GMT)
NNTP-Posting-Date: Sat, 20 Nov 2010 23:34:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:688648

"Steven " <> wrote in message <ic9io4$792$>...
> Hi everybody, 
> I'm supposed to write a code that will round any values to a specified numeric placement, such as the tens, hundredths, etc...  without using any built in functions such as 'round','ceil',etc.. I'm at a complete loss. 
> Say, for example I'm testing on a single value 10.23, and I wanted to round it to 10.2. 
>  I have no idea how to make MATLAB check to see if it should round up or down, or how to add or subtract the correct numbers to get to where I need it. It's one of those times where I'm pretty sure if I get one good brainwave I'll be able to get a lot more done, but for now, I'm just sitting here. 
> I suppose I'm essentially trying to write the 'round' 'ceil' and 'floor' functions from the ground up. 
> I really appreciate any advice!
> Steve
- - - - - - - - - - -
  You could approximate the 'round' function with

 y = x - atan(tan(pi*x))/pi;

However, it does seem rather absurd allowing 'tan' and 'atan' if one is not allowed to use 'round'.  Also it suffers a serious accuracy loss when x is near the halfway point between integers.

Roger Stafford