0
Answered

input multiprecision values

Gleb Beliakov 7 years ago updated by Pavel Holoborodko 5 years ago 2
Hi, how do I input/read from a file multiprecsion values (calculated elsewhere) into mp objects?
Hi Gleb,

Multiprecision values produced by toolbox can be saved/read as usual:

>> A = magic(3);
>> save('test.mat', 'A')
...
>> load('test.mat', 'A')

However if your file contains multiprecision values generated by other software - you need to do the conversion.

The simplest way would be to convert computed values to string and then create 'mp' object from that string.
Answered
Recently we have added new I/O features for easy exchange with other packages.
Export matrix to text file of simple format (all packages like Mathematica, Maple allow this):
A11 A12 A13 ..... A1n
....
Am1 Am2 Am3 ..... Amn
Every row is stored in one line, with space as an element separator.
Now you can load it with toolbox using the function:
function A = read_mp(filename)
%READ_MP Reads multiprecision matrix from a file
s = fileread(filename);
A = mp(strcat('[',s,']'));
end
Important note. Please store matrix elements in text file using higher number of decimal digits than you specify in Mathematica/Maple. This will make sure that numbers are correctly rounded and accuracy is not lost when converted back to numeric by toolbox.