Ask Your Question
1

N(): is it possible to display less digits than those use to compute?

asked 2014-10-17 00:42:39 +0200

afullo gravatar image

Is there a way to do numerical computations in a certain precision, while displaying a lower number of digits, for example if I want to output a matrix of a certain dimension, and I would prefer a consistent layout?

An example with another CAS is format short in Matlab and Octave, which allows to compute in double precision (15 or 16 digits) by displaying only 5 digits.

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-10-17 08:47:56 +0200

ndomes gravatar image

An example:

M = matrix(RR,3,3,range(1,10))
M ; M.n(digits=4)
edit flag offensive delete link more

Comments

It works, manies of thanks. :) By the way, is there a similar command in order to display only the real part of the matrix elements? I have some computations in the complex field where imaginary parts should have cancellation, but due to roundoff they remain with a decimal magnitude of -13 or -14. Usual commands real and imag, along with their synonyms real_part and imag_part, both by writing real(x) and x.real(), seem not to work for matrices. Thanks again... EDIT: a workaround like (1/2)*A+(1/2)*A.conjugate() seems to work...

afullo gravatar imageafullo ( 2014-10-17 17:35:46 +0200 )edit

If you are satisfied with the answer, you should click the tick mark to the left of the answer, to mark it as accepted.

slelievre gravatar imageslelievre ( 2014-10-17 22:08:04 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-10-17 00:42:39 +0200

Seen: 443 times

Last updated: Oct 17 '14