octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should interp1.m function allow jumps in X-values?


From: vivek dogra
Subject: Re: Should interp1.m function allow jumps in X-values?
Date: Tue, 21 Aug 2012 17:45:02 +0530

On Tue, Aug 21, 2012 at 5:43 PM, vivek dogra <address@hidden> wrote:
On Tue, Aug 21, 2012 at 5:21 PM, Ben Abbott <address@hidden> wrote:

On Aug 21, 2012, at 7:42 AM, vivek dogra wrote:

> On Tue, Aug 21, 2012 at 4:34 PM, Ben Abbott <address@hidden> wrote:
>
>> On Aug 21, 2012, at 4:26 AM, vivek dogra wrote:
>>
>> > Hello,
>> > Currently, interp1.m allows at most one identical pair of values in X.  My concern is should it really do that? My arguments are as follows:
>> >
>> > In my opinion repeated values should not be allowed for interpolation. Let's say i have following data points:
>> >
>> >  x  f(x)
>> > 0    4
>> > 1    6
>> > 2    8
>> > 3    10
>> >
>> > Now if i want to get f(1.5) then i will take the value midway between f(1) and f(2) which would be 7. Now in case i have repeated values the data points will be:
>> >
>> > x   f(x)
>> > 0    4
>> > 1    6
>> > 1    7
>> > 2    8
>> > 3   10
>> >
>> > Now in this case what f(1.5) will be? 7 or 7.5? (What will you call the best interpolation?) There will be ambiguity in this case. Also in the present case the sample points are nicely behaving so there is not much difference between 7 and 7.5. Although in some cases (if let's say f(1) = 6 and f(1) = 9) there can be lot of difference between answers when we choose one data point over another.
>> > So Octave should not allow repeated x values.
>>
>> Is the ambiguity due to a lack of clarity of the documentation, or does interp1() not work in a consistent manner?
>>
>> Ben
>
> If we go by the documentation, then interp1.m is doing fine (which in turn creates confusion as to how the interp1 works).
>
> "The discontinuous interpolant is right-continuous if @var{x} is increasing, left-continuous if it is decreasing."
>
> I am not able to digest this statement "if @var{x} is increasing or decreasing". Increasing with respect to what?
> And what will happen in case when X is neither increasing nor decreasing.

Increasing or descreasing with respect to X ... meaning is the original X increasing or decreasing.  If X is unsorted, then it will be sorted with increasing values.

Ben



So it means whenever X is unsorted, interp1 will always give the "discontinuous interpolant" corresponding to increasing values of X. It means it is hard coded in the function that it will always sort X in increasing order. So, it is not symmetric. Why interp1 is favoring right-continuous?

Now looking from the practical point of view let's say (because of some error) we have following data points:
X = [ 1 2 2 3];
Y = [ 1 2 10 4];

In this case because X is increasing, interp1 will consider value of 2 as 10.

which is of course incorrect.
In this case it will be better for the user to do some pre-processing (as in whether to take the max., min., or the mean of 2 identical values)


By neither increasing nor decreasing, i meant if it is unsorted.
example:

X = [ 2 1 2 3];
Y = [ 2 1 3 4];


reply via email to

[Prev in Thread] Current Thread [Next in Thread]