Enter forum description here ...
0
Завершен

'OverrideDoubleBasicArrays' option and 'double' method

john doe 8 лет назад обновлен Pavel Holoborodko 8 лет назад 1

Reason why someone would activate the option "OverrideDoubleBasicArrays" is to work with the desired precision (superior to that offered by type "double").


On the other hand, in "classic" Matlab, no one uses the builtin function "double" with explicit intentionality to reduce the precision for data (most often on the contrary).

In order to shoot not themselves in the foot I suggest altering the method "double" like this:


if ~(mp.OverrideDoubleBasicArrays && ismp(x))
r = mpimpl(402,x); else r = x; end


0
На рассмотрении

toolbox updater tool - a elementary implementation

john doe 8 лет назад обновлен Pavel Holoborodko 8 лет назад 4

the intuition tells me that in the very near future this tool will be very useful; It seems that Pavel prepares a lot of updates (very pleasing, I think)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function advanpix_update()
% check for a newer version than the locally installed,
% download the new version and then launches the installer


v = sscanf (version, '%d.%d.%d') ; % /matlabcentral/fileexchange/17285-getversion
v = 10.^(0:-1:-(length(v)-1))*v ;
if ~(v>=8.4), disp(' ... this implementation requires Matlab R2014b or newer.')
return; end

try
text = webread('http://www.advanpix.com/download/','Timeout',5);
% get version available for download
newver = strtrim(strtok(regexprep(text,'.+Download Trial.+Ver.',''),'<'));
% get local installed version
info = evalc('mp.Info');
text = regexp(info,'Version.*','ignorecase','dotexceptnewline','match');
curver = regexprep(strtrim(regexprep(char(text),'[^0-9.\s]','')),'\s+','.');
if ~strcmp(newver,curver)
instdir = winqueryreg('HKEY_CURRENT_USER','Software\Advanpix','InstallDir');
if exist(fullfile(instdir,'download'),'dir')~=7
mkdir(fullfile(instdir,'download'));
end
Url = 'http://www.advanpix.com/wp-content/plugins/download-monitor/download.php?id=1';
exe_name = ['AdvanpixMCT-',newver,'-Setup.exe'];
disp('Try downloading the newest version of the toolbox. Wait, please ...');
% Check for supported Microsoft .NET Framework
if NET.isNETSupported
disp('Supported .NET Framework not found')
% create .Net object to handle the file download
NET.addAssembly('System.Net');
client = System.Net.WebClient;
installer = fullfile(instdir,'download',exe_name);
client.DownloadFile(Url,fullfile(instdir,'download',installer));
else
options = weboptions('Timeout',30,'ContentType','binary');
olddir = cd(fullfile(instdir,'download'));
try installer = websave(exe_name,Url,options);
catch, cd(olddir); end
cd(olddir);
end
% run the installer
system(installer);
else
disp('The latest version of the toolbox is already installed.');
end
catch ME
rethrow(ME)
end
end
0
Отвечен

Real generalized eigenvalue problem

Stefan Güttel 8 лет назад обновлен Pavel Holoborodko 8 лет назад 2

I have a generalized eigenvalue problem Ax = lambda*Bx, where A and B are real multiprecision matrices. I used eig(A,B) and expected that non-real eigenvalues came out in perfectly complex conjugate pairs (because I want to group them in pairs), but this is not the case. I'm not sure this should be considered a bug, or rather a question about whether there is a way to enforce that EIG returns perfectly conjugate pairs when A and B are real mp matrices?


Here is a simple example (tested in MATLAB 2015A and MCT version 3.9.4.10443):


H = [ 2.285927555469414e-03 -9.683344516608315e-03 0 0 ;

2.835630264340973e+03 1.995068176067767e+02 0 -3.217604282987038e-01 ;
-1.995068176067769e+02 2.835630264340972e+03 0 1.973947878435759e+00 ;
0 0 9.875839323886169e-01 -1.403672780503961e+01 ];
K = [ -6.767269167134378e-04 -2.108684486049049e-04 0 0 ;
1.424833496089810e+01 0 0 -1.608802141493519e-03 ;
0 1.424833496089809e+01 0 9.869739392178797e-03 ;
0 0 1.002472007707650e+00 0 ];

ee = eig(mp(H),mp(K)); % eigenvalue with real(ee)~100 not a conjugate pair
cplxpair(ee) % hence this fails

% Note: could use cplxpair with a tolerance, but for a real problem the
% eigenvalues should be exactly complex conjugate.
0
Завершен

CAST method may also be useful to others

john doe 8 лет назад обновлен 8 лет назад 9

current status:


>> a = mp(mprandn(2,1))
b = [0, 1]
a =
0.4334207802637199612271739466794224
-0.2701469591393686343297786869883695
b =
0 1


>> cast(a,'double')
ans =
0.43342
-0.27015
>> cast(a,'like',b)
ans =
0.43342
-0.27015
>> cast(b,'mp')
Error using cast
Unsupported data type for conversion: 'mp'.


>> cast(b,'like',a)
Error using cast
Unsupported data type for conversion: 'mp'.


>> cast(a,'ss')
Error using cast
Unsupported data type for conversion: 'ss'.


with a CAST method like below ...


function r = cast(A,newclass,varargin) %#ok<INUSL>
narginchk(2,3);
if strcmp(newclass,'like')
narginchk(3,3); newclass = class(varargin{1});
end
try r = eval([newclass,'(A)']);
catch, r = eval([newclass,'(double(A))']); end
end


... the new status:


>> cast(b,'mp')
Error using cast
Unsupported data type for conversion: 'mp'.


>> cast(b,'like',a)
ans =
0 1


>> cast(a,'ss')
ans =

d =
u1
y1 0.4334
y2 -0.2701

Static gain.


Of course, my version is incomplete, but enough for me :)

By the way, on what grounds 'mp' inherits not 'double' ?


0
Завершен

another case of undocumented syntax

john doe 8 лет назад обновлен Pavel Holoborodko 8 лет назад 7

from Version History:

...

[US,TS, Success] = ordschur(...) % three-outputs, with status as last one.

Note:

ORDQZ has the same peculiarity - see GCARE or GDARE code:


[HH,JJ,~,z(perm,:),Success] = ordqz(HH,JJ,q,z,'lhp') % five outputs

0
Завершен

chol (~call) again

john doe 9 лет назад обновлен 9 лет назад 15
Pavel, for you in no case should underline the important function chol; unfortunately there are still some problems...
Please run the following few lines on the last version.


% *** ASSERTIONS *** (This has been incorporated into the documentation in R14SP3):
%
% CHOL expects its input matrix to be symmetric and only looks at the
% upper triangular portion of the matrix.

% CHOL function will return an error if it is only provided with a single
% output argument, and is also given a matrix that is not positive
% definite.

% CHOL function provides an optional second output argument "p" which
% is zero if the matrix is found to be positive definite. If the input
% matrix is not positive definite, then "p" will be a positive integer.

% *** ASSUMPTION ***

% Your implementation uses ?potr routine ...

% >>>>>>>>>> Let's test ...

%% A is scalar
% clc
mp.FollowMatlabNumericFormat(1) % just for convenience
A = mp(9) %#ok<*NOPTS>

R = chol(A) %#ok<*NASGU>
L = chol(A,'lower')
R = chol(A,'upper')

try [L,p] = chol(A,'lower'), catch, fprintf('mp [L,p] = chol(A,''lower'') BOOOM !!!\n\n'),...
[L,p] = chol(double(A),'lower'), fprintf('matlab ok\n\n'), end %#ok<*ASGLU>
try [P,p] = chol(A,'upper'), catch, fprintf('mp [L,p] = chol(A,''upper'') BOOOM !!!\n\n'), ...
[L,p] = chol(double(A),'upper'), fprintf('matlab ok\n\n'), end

%% A is matrix
% clc
A = mprand(4); A = A.'*A;

R = chol(A) %#ok<*NASGU>
L = chol(A,'lower')
R = chol(A,'upper')

try [L,p] = chol(A), catch, fprintf('mp [L,p] = chol(A) BOOOM !!!\n\n'),...
[L,p] = chol(double(A),'lower'), fprintf('matlab ok\n\n'), end %#ok<*ASGLU>
try [L,p] = chol(A,'lower'), catch, fprintf('mp [L,p] = chol(A,''lower'') BOOOM !!!\n\n'),...
[L,p] = chol(double(A),'lower'), fprintf('matlab ok\n\n'), end %#ok<*ASGLU>
try [P,p] = chol(A,'upper'), catch, fprintf('mp [L,p] = chol(A,''upper'') BOOOM !!!\n\n'), ...
[L,p] = chol(double(A),'upper'), fprintf('matlab ok\n\n'), end

%% Why is so important P?
% if your implementation (as I assumed) uses ?potr routine, the value of p will be
% the ?potr's INFO output

% clc
nice = false;
while ~nice
A = rand(4,6);
A = A.'*A;
[~,p] = chol(A);
if p > 2, nice = true; end
end

[L,p] = chol(A)
assert(all(all(L == chol(A(1:p-1,1:p-1)))))
[ma,na] = size(A)
[ma,nl] = size(L)







0
Отвечен

quad my own function with mp object

hongtaowei 10 лет назад обновлен Pavel Holoborodko 9 лет назад 5
hi, i have a function with its parameters of mp object, for example, k is a mp object, x is syms, and the function:phi=@(x,k,B) A*sin(k*x)+B*cos(k*x)-A*sinh(k*x)-B*cosh(k*x), I found it does not allow me to multiply k*x, how can I quad this function?
0
Завершен

Error occurs when multiplying function's results with mps - -

Harry Li 10 лет назад обновлен Pavel Holoborodko 10 лет назад 2
Image 5
All variables including d1n, d2n are mps, and N(.) is the normcdf written by myself.

Either (-n*cx)*(L2/L1)^(n*cx)/L1, or '( N(d1n)-N(d2n) )' can be shown on the matlab. But when I multiply them all, the result is error. Can someone help me with that?

The following is the function N(.)
Image 6
0
Отвечен

eigenvalues/vectors of asymmetric matrix

Gang Yan 11 лет назад обновлен Pavel Holoborodko 11 лет назад 1

I am using an old version (more than 2 years ago) and can not compute the eigenvalues/vectors of asymmetric matrix. I do not know whether it can be computed in the new version. If not, please develop one. Appreciate it!

0
Исправлен

Roots of negative numbers

Michael_ 9 лет назад обновлен Pavel Holoborodko 9 лет назад 2
Hello.

The following statement does not work in multiprecision:

mp(-1)^(1/2) = nan

sqrt(mp(-1)) = 0 + 1i (but this is only an option for the square root)

Maybe it is not a Bug, but it is real necessary to implement it.

Thank you.


Сервис поддержки клиентов работает на платформе UserEcho