 0

# Integer matrix

keuguz 4 years ago updated by Pavel Holoborodko 4 years ago

I have matrices they are made of integers. Do I need to define mp even for integers? For example:

N=100;

A=(zeros(N+1,N+1));

for l=1:N;

for k=mod(l-1,2):3:l;

A(k+1,l+1)=3*l;

end

end

and

p=0:1:N;

kron(p',p);

and

I=ones(N+1,1);

II=(-1).^(0:N);

G=kron(I,II);

Integer is normally considered as infinite precision. I use these matrices in further calculation with non-integer matrices, therefore, results. But using mp.Digits(100) for example costs me a lot in here for no gain actually. Integer matrices have to be converted to mp only if they participate in floating-point operations later on.

In this particular cases, just convert the matrices to mp after forming them as integers:

```% 1. Compute elements of matrices as integers:
% ... (your code from above)

% 2. Convert them to mp:
A = mp(A);
G = mp(G);

% 3. Floating-point code with A and G goes afterwards:
% ...
```

P.S.

There is no integer matrices in MATLAB (unless you create them with explicit type - zeros(...,'int32')).

By default, zeros, ones, and everything else is created as double matrices. The floating-point is just not shown if number has no fractional part.