Web版のEditorはこちら
メソッド一覧
以下、変数を下記のように定める。
- C,c : new CompVis(~,~);で作成したCompVisクラス変数
- x : 実数
- n : 整数
- l : 実数値を二つ持った配列([x,y])
- l_c・l_x : c・xの一次元配列
- l2 : lを要素とする配列
追加は「 <- new ver:~~」、削除は取り消し線と「 <- ver:~~」、変更は「 - ver:~~ -」または「 - ver:~~ ->」で表す。
-
引数ありのメソッド
- C.round(n)
- C.add(c)
- C.dif(c)
- C.pro(c)
- C.div(c)
- C.log_n(x)
- C.pow_by(c)
- C.pow_of(c)
- C.rotate(x)
-
引数なしのメソッド
- C.value
- C.str
- C.real
- C.imag
- C.conj
- C.abs
- C.arg
- C.log
- C.exp
-
静的メソッド
- CompVis._list - ver:1.02.03 -,
CompVis._list_ja<- ver:1.02.03 - CompVis._value(c)
- CompVis._str(c)
- CompVis._round(c,n)
- CompVis._toComp(l),CompVis._toComp(x) - ver:1.02.03 -
- CompVis._DFT(l) <- ver:1.02.03
- CompVis._Real(c),CompVis._Real(l_c) <- new ver:1.02.03
- CompVis._Imag(c),CompVis._Imag(l_c) <- new ver:1.02.03
- CompVis._list - ver:1.02.03 -,
-
Graph関連
- CompVis._create_canvas(element) - ver:1.02.03 -
- CompVis._clear_canvas(id_ctx) <- new ver:1.03.01
- CompVis._graph(id_ctx,func,start,end,step,params)
- CompVis._re_graph(data)
- CompVis._draw_text(id_ctx,text,position,params) <- new ver:1.02.04
ViewThreeクラスのメソッド一覧
- CompVis.ViewThree.showError(msg)
- async CompVis.ViewThree.addGraoh(f, a, b, span=100, option={})
- CompVis.ViewThree.animate()
- async CompVis.ViewThree.exec(callback)
Matrixクラスのメソッド一覧
- CompVis.Matrix.matrix [get,set]
- CompVis.Matrix.size
- CompVis.Matrix._inverse
メソッドの詳細
-
引数ありのメソッド
-
C.round(n)
Cの実部、虚部をそれぞれ特定の桁数で四捨五入する。
n>0の場合、小数第n位で四捨五入する。
n=0の場合、そのまま四捨五入して整数値にする。
n<0の場合、10nの位で四捨五入する。 -
C.add(c)
Cにcを足した値を返す
例:
const C = new CompVis(1,2); const c = new CompVis(-2,1); console.log(C.add(c).str); -
C.dif(c)
Cからcを引いた値を返す。
例:
const C = new CompVis(1,2); const c = new CompVis(-2,1); console.log(C.dif(c).str); -
C.pro(c)またはC.pro(x)
Cを cまたはx倍した値を返す。
引数が実数の場合はCの実部と虚部両方がx倍される。
例:
const C = new CompVis(-1,3); const c = new CompVis(2,1.5); const x = 3; console.log(C.pro(c).str); //C*c console.log(C.pro(x).str); //C*x -
C.div(c)またはC.div(x)
Cを cまたはxで割った値を返す。
引数が実数の場合はCの実部と虚部両方がxで割られる。
例:
const C = new CompVis(-1,3); const c = new CompVis(0,1); const x = 3; console.log(C.div(c).str); //C/c console.log(C.div(x).str); //C/x -
C.log_n(x)
logx(C)を返す。
例:
const C = new CompVis(-1,3); const x = 2; console.log(C.log_n(x).str); //log_x(C) -
C.pow_by(c)またはC.pow_by(x)
CcまたはCxを返す。
例:
const C = new CompVis(-1,3); const c = new CompVis(3,1.5); const x = 2; console.log(C.pow_by(c).round(3).str); //C^c console.log(C.pow_by(x).round(3).str); //C^x -
C.pow_of(c)またはC.pow_of(x)
cCまたはxCを返す。
例:
const C = new CompVis(-1,3); const c = new CompVis(3,1.5); const x = 2; console.log(C.pow_of(c).str); //c^C console.log(C.pow_of(x).str); //x^C -
C.rotate(x)
Cを原点中心でx[rad]回転させる。
例:
const C = new CompVis(-1,Math.sqrt(3)); const x = Math.PI/4; console.log(C.rotate(x).round(3).str); //C*(cos(x)+i*sin(x))
-
-
引数なしのメソッド
-
C.value
Cを配列[C.real,C.imag]で返す。
例:
const C = new CompVis(1,2); console.log(C.value); //[1,2] -
C.str
Cを文字列「'C.real'+'C.imag'i」で返す。
例:
const C = new CompVis(1,2); console.log(C.str); //"1+2i" -
C.real
Cの実部を実数値で返す。
例:
const C = new CompVis(1,2); console.log(C.real); //1 -
C.imag
Cの虚部を実数値で返す。
例:
const C = new CompVis(1,2); console.log(C.imag); //2 -
C.conj
Cの共役な複素数を返す。
例:
const C = new CompVis(1,2); console.log(C.conj.str); //1-2i -
C.abs
Cの絶対値を返す。
例:
const C = new CompVis(1,2); console.log(C.abs); //√5 -
C.arg
Cの偏角を返す。
例:
const C = new CompVis(1,Math.sqrt(3)); console.log(C.arg); //π/3 -
C.log
loge(C)を実数値で返す。
例:
const C = new CompVis(1/2,Math.sqrt(3)/2); console.log(C.log.str) //iπ/3 -
C.exp
eCを返す。
例:
const C = new CompVis(0,Math.PI); console.log(C.exp.round(5).str); //e_iπ (=-1)
-
-
静的メソッド
-
CompVis._list,
CompVis._list_ja使えるメソッドのリスト
と簡単な説明を返す。 <- ver:1.02.03で変更
._listは英語版、_list_jaは日本語版--> ._listは日本語。
例:
console.log(CompVis._list.slice(0,7).join(',')); /*console.log(CompVis._list_ja.join(',')); ver:1.02.03以降使えなくなりました。*/ -
CompVis._value(c)
c.valueと同じ結果を得られる。なぜ作ったのかは分からない。
若干式の中だと使いやすいのかも。
例:
const c = new CompVis(1,3); console.log(CompVis._value(c)); //[1,3] console.log(c.value); -
CompVis._str(c)
c.strと同じ結果を得られる。なぜ作ったのかは分からない。
複雑な式の出力に多少使えるかも。
例:
const c = new CompVis(1,3); console.log(CompVis._str(c)); //1+3i console.log(c.str); -
CompVis._round(c,n)
c.round(n)と同じ。何故作ったのだろう。
正直使うメリットが思いつかない。。
例:
const c = new CompVis(1,3).pow_by(1/2); //√(1+3i) console.log(CompVis._round(c,3).str); console.log(c.round(3).str); -
CompVis._toComp(l)またはCompVis._toComp(x)またはCompVis._toComp(l2) - ver:1.02.03 -
引数が配列lの場合、l[0]を実部,l[1]を虚部とするCompVisクラスを作成する。
引数が実数xの場合は実部x,虚部0のCompVisクラスが作成される。
引数が二次元配列(さらに、要素が長さ2の配列)l2の場合、配列lと同様の操作を
全ての要素に対して行い、戻り値でCompVisクラスの配列を返す。
静的メソッドの中で、数少ない使えそうなメソッドである。
例:
const l = [1,3]; const x = -2; console.log(CompVis._toComp(l).str); //1+3i console.log(CompVis._toComp(x).str); //-2 -
CompVis._DFT(l_c,return_type)またはCompVis._DFT(l_x,return_type)
引数を離散フーリエ変換したものを戻り値として与える。
return_typeは'normal'と'text_list'の二種類。
-
normal[default]
戻り値を[{value,abs,arg},...]で返す。
配列の長さはl_cまたはl_xと同じ。
- value:離散フーリエ変換の結果(indexに対応した周波数での値を返す)。
- abs:valueの絶対値。
- arg:valueの偏角。
-
text_list
normalの結果を整形して文字列にした一次元配列を返す。
長さはl_cまたはl_xと同じ。
構造:
['value:~~,abs:~~,arg:~~',...,'~~~']
value,abs,argについては上記のnormalを参照
const l_c = CompVis._toComp([[1,0],[0,1],[-1,0],[0,-1]]); const l_x = CompVis._toComp([1,2,3,4]); console.log(CompVis._DFT(l_c)); console.log(CompVis._DFT(l_x,'text_list').join('/n')); -
-
CompVis._Real(c)またはCompVis._Real(l_c)
C.realを配列に対しても使えるようにしたもの。
const c = new CompVis(-3,-2); const l_c = CompVis._toComp([[1,2],[3,-4]]); console.log(c.real); console.log(CompVis._Real(l_c)); -
CompVis._Imag(c)またはCompVis._Imag(l_c)
C.imagを配列に対しても使えるようにしたもの。
例:
const c = new CompVis(-3,-2); const l_c = CompVis._toComp([[1,2],[3,-4]]); console.log(c.imag); console.log(CompVis._Imag(l_c));
-
-
Graph関連
-
CompVis._create_canvas(element)
canvasのelementとelement.getContext("2d");の配列を返す。
CompVis._graphの引数id_ctxに代入する必要があるため必須。
詳しくはこちら
以下のように使う。
const element = document.getElementById('canvas'); <-- CompVis Editorではこれで取得する。
const id_ctx = CompVis._create_canvas(element);
-
CompVis._clear_canvas(id_ctx)
canvasに書かれた物を消す。
詳しくはこちら -
CompVis._graph(id_ctx,func,start,end,step,params)
グラフの初期描画を行う。詳しくはこちら
変更点:ver:1.02.03以降は、描画の値が共役な複素数になっていたものを修正しました。 -
CompVis._re_graph(data)
グラフの再描画を行う。詳しくはこちら
-
CompVis._draw_text(id_ctx,text,position,params)
Textの表示を行う。詳しくはこちら
-
-
ViewThreeクラス
-
CompVis.ViewThree.showError(msg)
div(canvas)上部に赤字で表示する。
-
async CompVis.ViewThree.addGraoh(f, a, b, span=100, option={})
グラフを描画。
-
f: 描画する関数。
指定の仕方は二種類
-
(x) => xの関数
xy平面上に描画する。
もちろん、変数名はx以外でもOK。 -
(t) => [X(t), Y(t), Z(t)]
媒介変数表示で描画する。
もちろん、変数名はt以外でもOK。
-
(x) => xの関数
-
a・b: 変数の定義域(a→b)
-
span: 変数をaからbに動かす際の、分割数(≒精度)
-
-
CompVis.ViewThree.startAnimate()
Animationを停止する。
※AnimationはViewThreeインスタンスが
作成された時点で実行されています。
つまり、後述のstopAnimate()を
使用しない場合、このメソッドを
実行することは(基本)ありません。
※このメソッドと、後述のstopAnimate()を
使用する際は、必ずstart/stopAnimate()のように、
'()'を使用して実行してください。
でないと、正しく動作しない場合があります。
例: × setTimeout(startAnimate, 1000);
○ setTimeout(() => startAnimate(), 1000); -
CompVis.ViewThree.stopAnimate()
前述のstartAnimate()の赤字を読んでください。
概要: startAnimate、stopAnimateの実行には
必ずstart/stopAnimate()のように
'()'を使用してください。 -
async CompVis.ViewThree.exec(callback)
-