0
Résolu

Exchanging a value in a double precision array

Michael_ il y a 9 ans mis à jour par Pavel Holoborodko il y a 9 ans 2
Hello.

I am not sure if the following is really intended:

Adding a mp number to a double number:
a=mp('1.1');
b=1.1;
test=a+b;

The variable test is a mp number, so the variable 'b' was cast to mp.
If I assign a mp number to a double array, it will be cast to double.

A=1:10;
A(1,1)=A(1,1)+a;

The array A is still double.
Probably this is done intentionally, but I think it was different in an older version. (I have the newest one)

Best regards,
Michael
Résolu
This is one of OOP rules in MATLAB. It does the conversion automatically without asking the toolbox and we have no control over this behavior (and it is always been like this).

In case of scalar operands - MATLAB casts to more powerful or custom type.
In case of arrays - the scalar RHS entity is converted to LHS type.

Actually it is a good solution. Otherwise, the whole array A would be converted to 'double' in the case:

A=mp(1:10)
A(1,1)=10;
% A becomes 'double' !

This would be much more unexpected behavior, isn't it?


Btw, newest version has some improvements in matrix multiplication in quadruple precision.
You might notice some speed-up for large matrices (~10-15%).