Converting double-precision complex numbers to real and imaginary parts in the form of rational numbers

Source: Internet
Author: User

Some of the following functions are covered in Mathematica:

RealDigits
Representation of decimals in the form of individual digits and their decimal exponent (but missing sign bits)

FromDigits
RealDigitsrestores this number from the result, but is expressed as a rational number form (unable to recover missing symbol bit information)

Sign
Taking into account the loss of symbols, you need to get the symbols through the Sign function and multiply them.

These are mainly for real operations, when dealing with complex numbers, it is necessary to use Im and Re function to extract the imaginary part and the real part after processing, and then multiply the real and imaginary units by the imaginary unit to add the converted and restored complex number.

For vector and matrix operations, it is possible to use Map Apply commands (functions) such as.

An example might be more vivid and operable. For example, this mat binary data format file (if the link fails, the user can use the random number generator to generate some data as a practice), including x The complex matrix A And x1 The real vector b 。

How do you turn them into the form of a rational number representation?

ImportImport Data First:

data=Import["e:\\Downloads\\data1.mat"];

The resulting data one contains two elements List :

Complex matrices a 18 x 18 Placed indata[[1]], while the real vector b 18 x 1 Placed indata[[2]]In The code to convert them is:

(Map[FromDigits, [email protected]([email protected][[1]]), {2}]*   Sign[data[[1]] // Re] +   I *Sign[data[[1]] // Im]*    Map[FromDigits, [email protected]([email protected][[1]]), {2}])

And

(FromDigits @@@ RealDigits[data[[2]]])*Sign[data[[2]]]

As can be seen from the above, the conversion of vectors is simple, and the conversion of real numbers is especially. However, it is quite cumbersome to convert matrices, especially complex matrices. Fortunately original aim. After a little adjustment, this completes the conversion.

The pictures below don't know what's going on??










Converting double-precision complex numbers to real and imaginary parts in the form of rational numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.