フィルターのクリア

How can I define split-complex number?

6 ビュー (過去 30 日間)
oren fivel
oren fivel 2020 年 5 月 6 日
コメント済み: John D'Errico 2020 年 5 月 7 日
How can I define split-complex number a+j*b such that a and b are real and j is a new type an imaginary unit such that j^2=+1?

採用された回答

John D'Errico
John D'Errico 2020 年 5 月 6 日
編集済み: John D'Errico 2020 年 5 月 6 日
You would need to create a custom class for the object, where you will then define how arithmetic is to be performed. That is, you must overload the addition, subtraction, multiplication, etc., operators, as approriate and as necessary. That object would contain two fields, thus a and b. You would probably overload the disp/display functions too, since you will need to display this object.
  2 件のコメント
oren fivel
oren fivel 2020 年 5 月 6 日
Thanks.
Is it possible somehow to gain access to the the definition of j and change the syntax such that if (for example) I type in the command line (j^2), the display in the comand window will be 1?
John D'Errico
John D'Errico 2020 年 5 月 7 日
Sorry, but not possible. Well, not easily possible. Anything is possible. However, this would require you to create a new class of numbers (again) because i and j are built into MATLAB. You want that to be true, since this is what makes MATLAB highly efficient on computations with double precision arrays. It all gets fed into the BLAS, which in turn makes things like matrix multiplies and lots of operations blazingly fast. But that happens because complex numbers are embedded deeply into the guts of MATLAB's single and double numeric classes.
What you need to do is as I said in my answer - create a completely new class that can intercept operations on numbers. You need to refine arithmetic for complex numbers in a completely different way. Well, sufficiently different that what is done will not work any more.
It is doable. It should not be that inefficient. I've written far more complex tools, where all arithmetic computations are fully overloaded (if my memory serves) on six separate occasions. So I do know it is doable. But you cannot do this by simply setting a flag somewhere in a preference, or by anything that easy. Sorry.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by