It says:
"LINSPACE(X1, X2, N) generates N points between X1 and X2."
Notice, it says BETWEEN.
But when I ask for 2 points, between 2 and 2:
----------------
EDU>> linspace(2,2,2)
ans =
2 2
---------------
May be mathematically this is ok? i.e. there are infinite points between
the point and itself? (on the real line), but from programming point of
view, it is confusing. no?
--Nasser
What did you expect to get back as an answer from issuing linspace(2,2,2)?
I didn't understand your statement "there are infinite points between the point and itself?" How do you have an infinite number of points between 2 and 2? I can see an infinite number of points between 2 and something that's not itself, like 2.00000000000000001, but if they are absolutely perfectly identical how are you getting an infinite number of points?
I was just not expecting it to "work". may be an error message. That is
not the point. The point is that it did work.
> I didn't understand your statement "there are infinite points between the point and itself?"
> How do you have an infinite number of points between 2 and 2?
But that is my point. How come? Matlab says so. Ask matlab for one
million points between 2 2 and it will return one million points between
2 and 2.
I am was trying to possibly given some hand waving pure mathematical
justification of why Matlab did that. The idea is that some pure math
person could argue that there are infinite points on the real point. No
matter how small the delta gets, there are still infinite more point.
But since we are on a real discrete machine, this should not apply.
I was not supporting what linespace does, merely trying to think
out-loud what was in the mind of who wrote it to work this way.
>I can see an infinite number of points between 2 and something that's not itself.
Exactly. That is why I posted this. So you agree with me that there is
"something" wrong here. May be we agree that the documentation needs to
be more clear to justify this result.
--Nasser
I understand they are "linearly equally spaced" from the previous sentence of the help. i.e., it will returns (for N>=2):
y(k) = X1+(k-1)*(X2-X1)/(N-1), for k=1,...N
If I plug X1 = 2, X2 = 2, and N = 2 It will returns y(1)=2 and y(2) =2. It looks perfectly consistent to me.
The help says it returns "N points in between" (of the closed-inverval), it does not claims there are at least "N *distinct* points in between". So I don't see any problem mathematically either.
Bruno
>
> The help says it returns "N points in between" (of the closed-inverval),
> it does not claims there are at least "N *distinct* points in between".
For me, "in between" implies distinct points.
"between" implies a delta, hence different points, hence distinct.
You said yourself, there can't be points between a point and itself.
Hence, the points returned must be distinct points.
>
> Bruno
--Nasser
Mathematically, a point X is in between A and B if
A<=X<=B
> You said yourself, there can't be points between a point and itself.
Did I said that?
Bruno
If you were the programmer to program up linspace, what you *you* do? Sounds like you would throw an exception if someone passed in X1 = X2. I'm not sure I or others would like that, especially since you can always check for this situation before calling linespace:
if abs(X1-X2) < eps
warndlg()
else
linspace()
end
It doesn't seem right to generate an error for those who have no problem with the way it operates. You always have the choice to check, but why remove the choice to use it that way for them?
>
>> You said yourself, there can't be points between a point and itself.
>
> Did I said that?
>
> Bruno
Sorry, mixed you up with ImageAnalyst, who said:
" I can see an infinite number of points between 2 and something that's
not itself"
Was not looking too carfully on who I was answering.
--Nasser
> If you were the programmer to program up linspace, what you *you* do?
But that is NOT the point.
You are jumping on an implementation issue.
First, we decide if the "behavior" is correct based on the
specification/documentation.
Next, if we agree that the "behavior" is inconsistent with the the
specification/documentation, then the next point is what to do.
We can measure the cost of making it behave as documented in this case,
vs. leaving things the way they are and may be improve the documentation.
You already jumped on the cost of changing the implementation, before we
agreed that the "behavior" is not consistent with the specifications.
For me, what to do, is a separate design issue, I am merely pointing
what I think is an inconsistent behavior of a function. That is all.
>Sounds like you would throw an exception if someone passed in X1 = X2. I'm not sure I or others would
>like that, especially since you can always check for this situation
before calling linespace:
> if abs(X1-X2)< eps
> warndlg()
> else
> linspace()
> end
> It doesn't seem right to generate an error for those who have no problem with the way it operates.
> You always have the choice to check, but why remove the choice to use
it that way for them?
You already suggested what I would, and then starting to argue that what
I would not is not right? You'd make a good lawyer :)
--Nasser
"Nasser M. Abbasi" <n...@12000.org> wrote in message
news:i8sv1m$5k3$1...@speranza.aioe.org...
linspace(x1, x2, N) returns a 1-by-max(0, N) vector containing N equally
spaced points. If N > 0, the first element of the vector is x1; if N > 1
then the last element of the vector is x2. If x1 == x2, then the equal
spacing between points is 0 and the vector will consist of N copies of x1.
--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
It seems like you describe "colon" operator. No where LINSPACE documentation states it must ensure a strictly positive step, thus distinct output.
In fact the second input can be larger or smaller or EQUAL than the first input. The output are linear spaced between then regardless which one is larger.
The doc is perfectly consistent.
Bruno
>> a=linspace(1,1+eps);
>> length(a)
ans =
100
>> length(unique(a))
ans =
2
>> sum(a==1)
ans =
50
>> sum(a==1+eps)
ans =
50
>>
% Bruno
I don't see how it could be more logical (or simple) than this.
Francis
It's more complicates than that
>> for i = -2:3, linspace(2,2,i),end
ans = 2
ans = 2
ans = 2
ans = 2
ans = 2 2
ans = 2 2 2
>> for i = -2:3, linspace(2,1,i),end
ans = 1
ans = 1
ans = 1
ans = 1
ans = 2 1
ans = 2 1.5 1
Hope this helps.
Greg
So would you change the documentation or the implementation,
and how?
Francis
IMO, no, not really.
Although, perhaps it could say "on the range of x1 to x2" instead and be
more precise.
--
> "LINSPACE(X1, X2, N) generates N points between X1 and X2."
What about this:
"LINSPACE(X1, X2, N) generates N equally spaced points from X1 to X2."
(as ever, I'm not sure if this is correct English)
Anyhow, this mathematically vague help text does not seem to be a problem for a lot of Matlab users. In opposite to that the functional form of SAVE ("save('FileName', 'Variable')") is described exactly and correctly in the help section, but you can find a pile of posts conerning this in CSSM.
Jan
Current version
>> help linspace
LINSPACE Linearly spaced vector.
LINSPACE(X1, X2) generates a row vector of 100 linearly
equally spaced points between X1 and X2.
LINSPACE(X1, X2, N) generates N points between X1 and X2.
For N < 2, LINSPACE returns X2.
See also LOGSPACE, :.
Modification
LINSPACE Vector with equally spaced elements.
LINSPACE(X1, X2) generates a row vector of 100 equally
spaced points between X1 and X2, inclusive.
LINSPACE(X1, X2, N) returns X2 for N < 2.
For N >=2, LINSPACE(X1, X2, N) generates a row vector
of floor(N) equally spaced points between X1 and
X2, inclusive.
See also LOGSPACE, :.
Hope this helps.
Greg