rounding to zero small numbers (NOT round function)
Show older comments
hey
so i want matlab to consider every number below a certain level (for example 0.001) as zero in the whole script. while right now it returns some computation result even in 10e-15, is there any defult value for matlab ?
Answers (1)
dpb
on 30 Oct 2019
No. ML basic numeric type is the floating point double which around zero has roughly the above magnitude of precision.
You'll have to set values less than your chosen threshold to zero explicitly.
The round function with the optional second option could be useful tool in this, but simply
x(x<threshold)=0;
will avoid the rounding that occurs in it. Of course, you'll want to use abs to get both positive and negative sides of the rounding that will likely occur.
You might also find ismembertol of use depending upon your actual code.
9 Comments
dpb
on 30 Oct 2019
OP Answer moved to Comment--dpb
thank a lot for your explaniation. in my case I`m trying to get a null space of a matrix which it`s determinat is very close to zero ( say like 1e-10 ) but since matlab does not is it as zero returns value of null as empty vector. do you know any solution for that?
dpb
on 30 Oct 2019
As above, you can set the elements <= some threshold to zero in one step and then the retrieval of zero elements will work.
Or, you can simply return only the values which are <= threshold instead of identically zero. ismembertol would be an ideal tool for that purpose letting you set a tolerance dependent upon the magnitude of the element instead of just some more or less arbitrary fixed value.
Walter Roberson
on 30 Oct 2019
Symbolic toolbox. Or use a different routine for null space determination.
atabak mostafavi
on 31 Oct 2019
Edited: atabak mostafavi
on 31 Oct 2019
Walter Roberson
on 31 Oct 2019
Which routine are you currently using for null space determination?
Did you try
null(sym(TheNumericArray))
atabak mostafavi
on 31 Oct 2019
Walter Roberson
on 31 Oct 2019
What result are you getting, exactly, for which there is "no explicit solution" ? Do you mean the result of null() on the symbolic numeric array is the empty array? If so then as far as the routine can tell, the array is full rank.
atabak mostafavi
on 31 Oct 2019
Walter Roberson
on 31 Oct 2019
I would be interested to see what shows up for
dets = det(sym(B))
detn = double(dets)
However for large B this can take a fair while.
You might want to look at https://cseweb.ucsd.edu/classes/wi15/cse252B-a/nullspace.pdf at how null space can be determined by SVD. That form would give you the flexibility to permit columns that you consider "close enough" to zero.
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!