投稿時間:2004/12/27(Mon) 22:30 投稿者名:ねろ
Eメール:
URL :
タイトル:Re: 虚数iの演算
> 初めまして、たくたくと申します。 > 超初心者ですので簡単なことかもしれませんが教えてください。 > > 虚数iをVBで演算させたいんですけど、虚数iはVBにどのように入力すれば良いのですか? > たぶん関数があるんでしょうけど、教えてください。 割り算が面倒なのよね 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
|