- 日時: 2010/01/07 15:00
- 名前: 花ちゃん
- ***********************************************************************************
* カテゴリー:[アルゴリズム][応用コード][] * * キーワード:関数,複素数型,虚数単位,2乗して負になる数,, * ***********************************************************************************
元質問:虚数iの演算 - たくたく 2004/12/25-21:05 No.1376
虚数iをVBで演算させたいんですけど、虚数iはVBにどのように入力すれば良いのですか? たぶん関数があるんでしょうけど、教えてください。
---------------------------------------------------------------------------------- Re: 虚数iの演算 - ねろ 2004/12/27-22:30 No.1388 ----------------------------------------------------------------------------------
割り算が面倒なのよね Private Type CompNo Realp As Single '実数部 Imagep As Single '虚数部 End Type Private Function Plus(a As CompNo, b As CompNo) As CompNo '足し算 Plus.Realp = a.Realp + b.Realp Plus.Imagep = a.Imagep + b.Imagep End Function Private Function Minus(a As CompNo, b As CompNo) As CompNo '引き算 Minus.Realp = a.Realp - b.Realp Minus.Imagep = a.Imagep - b.Imagep End Function Private Function Times(a As CompNo, b As CompNo) As CompNo '掛け算 Times.Realp = a.Realp * b.Realp - a.Imagep * b.Imagep Times.Imagep = a.Realp * b.Imagep + a.Imagep * b.Realp End Function
Private Function Divide(a As CompNo, b As CompNo) As CompNo '割り算 Dim b1 As CompNo '共訳複素数 Dim denomi As CompNo '分母 Dim nume As CompNo '分子
'共訳複素数 b1.Realp = b.Realp b1.Imagep = b.Imagep * (-1) denomi = Times(b, b1) '分母の計算 共訳複素数をかける nume = Times(a, b1) '分子の計算 共訳複素数をかける If denomi.Realp <> 0 Then '分母<>0の場合 Divide.Realp = nume.Realp / denomi.Realp Divide.Imagep = nume.Imagep / denomi.Realp Else Divide.Realp = 0 Divide.Imagep = 0 MsgBox ("分母が0になりました") End If End Function
'表示は参考につき大幅に省略 (^^; Private Sub Command1_Click() Dim a As CompNo, b As CompNo, c As CompNo a.Realp = Text1(0).Text a.Imagep = Text1(1).Text b.Realp = Text1(2).Text b.Imagep = Text1(3).Text c = Plus(a, b) '足し算 'c = Minus(a, b) '引き算 'c = Times(a, b) '掛け算 'c = Divide(a, b) '割り算 Text1(4).Text = c.Realp Text1(5).Text = c.Imagep End Sub
-------------------------------------------------- Re: 虚数iの演算 - LESIA 2004/12/27-18:06 No.1383 -------------------------------------------------- 複素数のクラスなら、こういうのがあります。
VB6用 http://www.vb-helper.com/howto_complex_number_class.html VB.NET用 http://www.vb-helper.com/howto_net_complex_number_class.html
|