Hello,
I would like to test if an integer is a triangular number, and am wondering what the best way to achieve this is. I am aware that a triangular number is given by
And that x is triangular if and only if 8x + 1 is a square.
However, what is the best way to actually test this in Matlab, giving consideration to floating point arithmetic?
I can think of methods like:
check x is an integer find if sqrt(8x + 1) is an integer to some floating point error
but there must be better ways.
2 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/47533-best-way-to-determine-if-number-is-triangular-number#comment_97912
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/47533-best-way-to-determine-if-number-is-triangular-number#comment_97912
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/47533-best-way-to-determine-if-number-is-triangular-number#comment_97946
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/47533-best-way-to-determine-if-number-is-triangular-number#comment_97946
Sign in to comment.