turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-02-2013 11:18 AM

I've noticed that using a non-integer index on a vector returns a value. For example, if I set

x = 1:5;

y = x[{1.2 5.7}];

then y returns a 2-vector {1, 5}.

It seems that the indexes are having the floor function applied before being used to find elements of x. Is this correct?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-02-2013 11:29 AM

My experiment indicates that there is some fuzzing as well, so that x[1-epsilon] still returns x[1]:

x=1:5;

i = 2 - 10##-T(11:16);

y = x*;*

print i[format=20.16] y;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-02-2013 11:46 AM

Isn't that what we'd expect from the floor function? Anything less than 2 (even if just epsilon) is 1?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-02-2013 03:14 PM

Add this to the end of the previous program:

f = floor(i);

print i[format=20.16] f y;

You'll see that the conversion of noninteger subscripts is different from a simple floor. The fuzzing of near-integer values is important to correctly handle floating point arithmetic. If you reread my previous post, you'll see that I stated that x[1-epsilon] = x[1], not x[0] (which would be an error).