Classiclll's Blog

an old boy

class Vec(任意長の行ベクトルのモデル)強化版

class Vec(任意長の行ベクトルのモデル)強化版

[class] Vec              5/23/2008 by Classiclll
 線形代数(ベクトル演算)のモデル
   添字の基数は0。すなわち
    elem(0)     : 左端のベクトル要素(double)
      elem(idx)   : 左端から(idx+1)番目の要素
 Matで線形連立方程式を解けるんだから、Vecでも高次多項式の求解ができなきゃ・・・
  → Σ(me[k])*x^(n-k) - b = 0 の【全て】の根をDKA法で求める
  →返値はMat(2,n)の複素数表現 (k+1)番目の解はm[0][k]+img*m[1][k]と解釈すること

Body

 [members]
  no public member.
 
 [constructors]
 Vec()				:construct empty
 Vec(int length)		:construct zero vector sized by "length"
 Vec(Vec v)			:construct same to v
 Vec(double[] d)		:construct having d 
 Vec(Loc v)			:construct 3D vector, (x,y,z)
 

[methods]

<group #1 - Vector Operation - generator>
 Vec copy()			:return the copy of me.
 Vec add(Vec m)			:return me[i] + m[i]
 Vec add(double d)		:return me[i] + d (scalar)
 Vec sub(Vec m)			:return me[i] - m[i]
 Vec sub(double d)		:return me[i] - d (scalar)
 Vec mul(Vec v)			:return me[i] * v[i]
 Vec mul(double d)		:return me[i] * d (scalar)
 Vec div(Vec v)			:return me[i] / v[i]
 Vec div(double d)		:return me[i] / d (scalar)
 Vec setSubVec(Vec subVec, int row)  :ret[row+i] <= subVec[i][j] 
 Vec SubVec(int start, int end)	     :return me[sRow->eRow]
 Vec SubVec(int[] selected)  :retturn {{.},..{me[selRow][selCol]},..{.}}
 Mat transpose()	:return the transpose of me.
 Vec inverse()		:"me" must be square, otherwize NaN returned 
 Mat cross(Vec v)	:return Mat it's trace has me[i]*v[i]
 
<group #2 - Scalar - information>
 int length()			:return the number of rows
 double dot(Vec v)		:return sum of me[i]*v[i]
 double elem(int idx)		:return the specified element
 double norm()			:return the infinit(=maximum) norm of me.
 double normL2()		:return the L2 norm of me.
 double sqNormL2()		:return the sqare of the L2 norm of me.
 double dist()			:same as norm().
 double dist2()			:return square of norm().
 boolean equals(Object object)	:return shallow equoality between me and object 
 boolean hasNaN()		:return has me some Double.NaN 
 boolean hasInf()		:return has me some Double.Infinity
 boolean isNaN()		:return is me containing NaN or Infinity
 
  【6月8日更新】
 <group #3 - Utilities - generator>
 double[] toArray()		:return 2d array of me
 Loc toloc()			:return Loc of me (length must be 3)
 double[] arrayRef()		:retuen the reference to 2d array of "me"
 				  modification may cause some trouble.
 String toString()             	:get the string expression of me.
 
 <group #4 - High level operator>
 Mat solvePoly(double b)
 : Returns the all roots of the following polynomial equation by the DKA Method.
            me[0]*x^n + ...+me[k]*x^(n-k)+... + me[n-1]*x - b = 0.
   returned matrix has
     ret.rowDim()      always 2, (number of parts of the complex expression)
     ret.colDim()       the number of solution pairs
     ret[0][k]          the real part of (k+1)th solution
     ret[1][k]          the imaginary part of (k+1)th solution