Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
Hi all,
I'm having a little difficulty with extracting a specific point using the linear interpolation function.
The error function i'm getting is "the elements in this vector must be in ascending order"
I have attached the file, would much appreciate if someone could please show me how to get rid of this error and how I can extract a specific point from my RF(x) function.
Many thanks.
Solved! Go to Solution.
I'm not sure if that's a bug with Mathcad or your not allowed duplicate values in the Linterp function.
Have a look at the attached worksheet. A little trick in there you now don't need to define RF1.
Mike
I think its because your P2 and P3 values are the same.
Mike
Thanks Mike.
Mathcad is a strange beast. Check my attached document, by rounding down P3 I get a solutuon. Why is that?
I'm not sure if that's a bug with Mathcad or your not allowed duplicate values in the Linterp function.
Have a look at the attached worksheet. A little trick in there you now don't need to define RF1.
Mike
Yes, might be a bug. However nice trick, thanks Mike!
I'm not sure if that's a bug with Mathcad or your not allowed duplicate values in the Linterp function.
It's not a bug. Linterp calculates the slope and intercept of the line that passes through each pair of points. If the x-values of two points are the same then the slope is infinite.
Thanks for clarifying Richard.
It's not a bug. Linterp calculates the slope and intercept of the line that passes through each pair of points. If the x-values of two points are the same then the slope is infinite.
Of course, cheers Richard.
This is a case where Mathcad errors messages are poor. Why can't the error message say duplicate values are not allowed with this function.
Mike
This is a case where Mathcad errors messages are poor.
Yes. Unfortunately, that's like most other cases
I tend to view it as a designer bug. It is there by design, but for most folk it isn't a useful restriction.
Either linterp should accept an extra parameter to allow for the scan order and allowing the first equality to match (i.e. it would cope with oscillating data as well as level data, simply returning the first match along the data when (option) either searched from head (+1) or tail (-1), default (0).
Or, there would be a predefined routine that would strip out non strictly ascending data values, so that we could guarantee that linterp would return a value!
Philip
I tend to view it as a designer bug. It is there by design, but for most folk it isn't a useful restriction.
I totally disagree.
Either linterp should accept an extra parameter to allow for the scan order and allowing the first equality to match (i.e. it would cope with oscillating data as well as level data,
The problem is not oscillating data or level data, both of which linterp handles just fine anyway. It is duplicate x values with different y values. That means linear interpolation, which is what linterp does, between those two points is impossible. The solution is indeterminate.
Or, there would be a predefined routine that would strip out non strictly ascending data values, so that we could guarantee that linterp would return a value!
Absolutely not! That would potentially result in an incorrect interpolation for other values! A built-in function should NEVER arbitrarily strip data points! There is no way for someone at PTC to know what caused that problem in the data, and therefore no way for them to program a fix for it. Maybe the first point is an error, and it should be deleted. Maybe the second point is an error, and it should be deleted. Maybe they are duplicate readings, and should be averaged. Maybe it indicates that one half of the data is offset relative to the other. Maybe lots of things. The only person that could know the cause is the person that collected the data, so it's up to them to fix it.
Richard you're spot on. Mathematically my P2 and P3 in no way could have or should have been the same. Thank you all for highlighting the error of my ways. I have now resolved the issue, P2 should have been a negative value.
Richard, I'm happy with the default action, but not with the lack of options.
If I can plot the coordinates as a continuous line (some with some zero length sections even), I should be able to use a linear interpolator between the points. Especially if I know which option I want to use to get past such "problems" (I have been there). I know I could write a (slow) routine, but there is no reason for mathcad not to offer the extra OPTIONS (keeping default as is) to use various strict search methods.
There even should be one, like Match, which will returns multiple results if the curve crosses many times.
I could even suggest being able to search for the y-intercept values, but that is simply the swapping of the x & y vectors. A note in the help / manual would cover that.
The default is Ok, but the lack of defined options isn't in 2010.
Philip