Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.2 - 日本語

Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilabヘルプ >> Development tools > Assert > assert_comparecomplex

assert_comparecomplex

許容誤差を指定して複素数を比較する.

呼び出し手順

order = assert_comparecomplex ( a , b )
order = assert_comparecomplex ( a , b , reltol )
order = assert_comparecomplex ( a , b , reltol , abstol )

パラメータ

a :

1行1列のdouble行列,比較する最初の値

b :

1行1列のdouble行列,比較する2番目の値

reltol :

1行1列のdouble行列,相対許容誤差 (デフォルト: reltol=sqrt(%eps)).

abstol :

1行1列のdouble行列,絶対許容誤差 (デフォルト: abstol=0).

order :

1行1列のdouble行列,整数値,順番. aがbにほぼ等しい場合にorder=0, a < bの場合に order=-1, a > bの場合に order=+1.

説明

まず実部,次に虚部を比較します. 相対および絶対許容誤差による判定を組み合わせることで 数値的な問題を考慮します.

オプションの入力引数が空の行列に等しい場合, そのデフォルト値に置換されます.

以下のアルゴリズムを使用します.

まず実部を比較します.それが等しい場合, 虚部を比較します.

IEEE値を処理し,順番を選択します: -%inf < 0 < %inf < %nan. どの値も特殊な値でない場合, 以下の条件を使用します:

cond = ( abs(a-b) <= reltol * max(abs(a),abs(b)) + abstol )

このアルゴリズムはソート用アルゴリズムの中で使用される よう設計されています. これにより, 複素数のdoubleの行列を出力する関数の出力に関連した 移植性の問題を考慮することができます. このアルゴリズムがソート用関数に組み込まれた場合, 順番をオペレーティング・システム,コンパイラまたは (値ではなく)順番を変更する他の問題に依存させずに, 一貫してソートされた行列を出力することができるようになります.

// 実数値を比較
assert_comparecomplex ( 1 , -1 ) // 1
assert_comparecomplex ( -1 , 1 ) // -1
assert_comparecomplex ( 1 , 1 ) // 0
// 複素数を比較 #1
assert_comparecomplex ( 1+2*%i , 1+3*%i ) // -1
assert_comparecomplex ( 1+3*%i , 1+2*%i ) // 1
assert_comparecomplex ( 1+2*%i , 1+2*%i ) // 0
// 複素数を比較 #2
assert_comparecomplex ( 1+%i , -1+%i ) // 1
assert_comparecomplex ( -1+%i , 1+%i ) // -1
assert_comparecomplex ( 1+%i , 1+%i ) // 0
[order,msg] = assert_comparecomplex ( 1+%i , 1+%i )
// 許容誤差を指定して比較: 等号の場合
assert_comparecomplex ( 1.2345+%i , 1.2346+%i , %eps , 1.e-3 ) // 0
assert_comparecomplex ( 1.2345+%i , 1.2346+%i , 1.e12*%eps , 0 ) // 0
assert_comparecomplex ( 1+1.2345*%i , 1+1.2347*%i , %eps , 1.e-3 ) // 0
assert_comparecomplex ( 1+1.2345*%i , 1+1.2347*%i , 1.e12*%eps , 0 ) // 0
// より実際的なデータの比較
x = [
-0.123452 - 0.123454 * %i
-0.123451 + 0.123453 * %i
0.123458 - 0.123459 * %i
0.123456 + 0.123457 * %i
];
// 上位4桁以下を考慮
for i = 1 : size(x,"*")-1
order = assert_comparecomplex ( x(i) , x(i+1) , 1.e-4 );
mprintf("compare(x(%d),x(%d))=%d\n",i,i+1,order)
end
// バグ#415からのデータを比較
x = [
-1.9914145
-1.895889
-1.6923826
-1.4815461
-1.1302576
-0.5652256 - 0.0655080 * %i
-0.5652256 + 0.0655080 * %i
0.3354023 - 0.1602902 * %i
0.3354023 + 0.1602902 * %i
1.3468911
1.5040136
1.846668
1.9736772
1.9798866
];
// 上位4桁以下を考慮
for i = 1 : size(x,"*")-1
order = assert_comparecomplex ( x(i) , x(i+1) , 1.e-5 );
mprintf("compare(x(%d),x(%d))=%d\n",i,i+1,order)
end

履歴

バージョン記述
5.4.0 関数が導入されました

参考文献

http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/polynomials/tests/nonreg_tests/bug_415.tst;h=0c716a3bed0dfb72c831972d19dbb0814dffde2b;hb=HEAD

http://gitweb.scilab.org/?p=scilab.git;a=blob_plain;f=scilab/modules/cacsd/tests/nonreg_tests/bug_68.tst;h=920d091d089b61bf961ea9e888b4d7d469942a14;hb=4ce3d4109dd752fce5f763be71ea639e09a12630

Report an issue
<< assert_checktrue Assert assert_computedigits >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Feb 14 15:02:37 CET 2019