Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Opérations sur nombres complexes

9 réponses
Avatar
jean-pierre sarteaux
Bonjour,

je n'arrive pas à y trouver des exemples de procédures EN VB
d'opérations sur le nombres et expressions complexes.
(Addition de complexe, multiplication de complexe, ect...)

Pouvez vous me dire et m'indiquer ou je pourrai trouver ces exemples.

En vous remerciant par avance,

Bien cordialement à tous.
Jean-Pierre

9 réponses

Avatar
Patrice Henrio
Je ne sais pas si ça existe mais cela me semble facile à implanter.


"jean-pierre sarteaux" a écrit dans le
message de news:
Bonjour,

je n'arrive pas à y trouver des exemples de procédures EN VB
d'opérations sur le nombres et expressions complexes.
(Addition de complexe, multiplication de complexe, ect...)

Pouvez vous me dire et m'indiquer ou je pourrai trouver ces exemples.

En vous remerciant par avance,

Bien cordialement à tous.
Jean-Pierre



Avatar
Jean-Marc
"jean-pierre sarteaux" a écrit dans le
message de news:
Bonjour,

je n'arrive pas à y trouver des exemples de procédures EN VB
d'opérations sur le nombres et expressions complexes.
(Addition de complexe, multiplication de complexe, ect...)

Pouvez vous me dire et m'indiquer ou je pourrai trouver ces exemples.




voir ma reponse sur fr.comp.lang.basic

--
Jean-marc
Avatar
ng
Salut,

Tu peux essayer ce module (on aurait pu faire une classe aussi) :

Option Explicit

Public Type tComplexe
dImg As Double
dReel As Double
End Type

Public Enum eCompOperation
ecAddition = 0
ecSoustraction = 1
ecDivision = 2
ecMultiplication = 3
ecConjugue = 4
End Enum

Public Function CompNul() As tComplexe: End Function

Public Function CompOperation(eOperation As eCompOperation, tComplexe1 As
tComplexe, tComplexe2 As tComplexe) As tComplexe
Select Case eOperation
Case ecAddition
CompOperation.dReel = tComplexe1.dReel + tComplexe2.dReel
CompOperation.dImg = tComplexe1.dImg + tComplexe2.dImg
Case ecSoustraction
CompOperation.dReel = tComplexe1.dReel - tComplexe2.dReel
CompOperation.dImg = tComplexe1.dImg - tComplexe2.dImg
Case ecDivision
CompOperation.dReel = tComplexe1.dReel / tComplexe2.dReel -
tComplexe1.dImg / tComplexe2.dImg
CompOperation.dImg = tComplexe1.dReel / tComplexe2.dImg +
tComplexe2.dReel / tComplexe1.dImg
Case ecMultiplication
CompOperation.dReel = tComplexe1.dReel * tComplexe2.dReel -
tComplexe1.dImg * tComplexe2.dImg
CompOperation.dImg = tComplexe1.dReel * tComplexe2.dImg +
tComplexe2.dReel * tComplexe1.dImg
Case ecConjugue
CompOperation.dReel = tComplexe1.dReel
CompOperation.dImg = -tComplexe1.dImg
End Select
End Function


Public Function CompToString(tComplexe1 As tComplexe) As String
If tComplexe1.dImg < 0 Then
CompToString = tComplexe1.dReel & tComplexe1.dImg & "i"
Else
CompToString = tComplexe1.dReel & "+" & tComplexe1.dImg & "i"
End If
End Function

Public Function CompSet(dReel As Double, dImg As Double) As tComplexe
CompSet.dImg = dImg
CompSet.dReel = dReel
End Function

Exemple d'utilisation :

Option Explicit

Private Sub Form_Load()
Dim cA As tComplexe
Dim cB As tComplexe
Dim cC As tComplexe

cA = CompSet(5, 5)
cB = CompSet(2, -8)

'//ou

cA.dReel = 5
cA.dImg = 5
cB.dReel = 2
cB.dImg = -8

cC = CompOperation(ecAddition, cA, cB)

Debug.Print CompToString(cC)

cC = CompOperation(ecMultiplication, cC, cA)

Debug.Print CompToString(cC)

cC = CompOperation(ecConjugue, cC, CompNul)

Debug.Print CompToString(cC)

End Sub





--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/



jean-pierre sarteaux a écrit :

Bonjour,

je n'arrive pas à y trouver des exemples de procédures EN VB
d'opérations sur le nombres et expressions complexes.
(Addition de complexe, multiplication de complexe, ect...)

Pouvez vous me dire et m'indiquer ou je pourrai trouver ces exemples.

En vous remerciant par avance,

Bien cordialement à tous.
Jean-Pierre


Avatar
jean-pierre sarteaux
Jean-Marc
Merci pour tes exemples.
Bien cordialement
Jean-Pierre

Jean-Marc a *crit :

"jean-pierre sarteaux" a écrit dans le
message de news:
> Bonjour,
>
> je n'arrive pas à y trouver des exemples de procédures EN VB
> d'opérations sur le nombres et expressions complexes.
> (Addition de complexe, multiplication de complexe, ect...)
>
> Pouvez vous me dire et m'indiquer ou je pourrai trouver ces exemples.
>

voir ma reponse sur fr.comp.lang.basic

--
Jean-marc


Avatar
jean-pierre sarteaux
Nicolas
Merci pour tes exemples.
Bien cordialement
Jean-Pierre


ng a *crit :

Salut,

Tu peux essayer ce module (on aurait pu faire une classe aussi) :

Option Explicit

Public Type tComplexe
dImg As Double
dReel As Double
End Type

Public Enum eCompOperation
ecAddition = 0
ecSoustraction = 1
ecDivision = 2
ecMultiplication = 3
ecConjugue = 4
End Enum

Public Function CompNul() As tComplexe: End Function

Public Function CompOperation(eOperation As eCompOperation, tComplexe1 As
tComplexe, tComplexe2 As tComplexe) As tComplexe
Select Case eOperation
Case ecAddition
CompOperation.dReel = tComplexe1.dReel + tComplexe2.dReel
CompOperation.dImg = tComplexe1.dImg + tComplexe2.dImg
Case ecSoustraction
CompOperation.dReel = tComplexe1.dReel - tComplexe2.dReel
CompOperation.dImg = tComplexe1.dImg - tComplexe2.dImg
Case ecDivision
CompOperation.dReel = tComplexe1.dReel / tComplexe2.dReel -
tComplexe1.dImg / tComplexe2.dImg
CompOperation.dImg = tComplexe1.dReel / tComplexe2.dImg +
tComplexe2.dReel / tComplexe1.dImg
Case ecMultiplication
CompOperation.dReel = tComplexe1.dReel * tComplexe2.dReel -
tComplexe1.dImg * tComplexe2.dImg
CompOperation.dImg = tComplexe1.dReel * tComplexe2.dImg +
tComplexe2.dReel * tComplexe1.dImg
Case ecConjugue
CompOperation.dReel = tComplexe1.dReel
CompOperation.dImg = -tComplexe1.dImg
End Select
End Function

Public Function CompToString(tComplexe1 As tComplexe) As String
If tComplexe1.dImg < 0 Then
CompToString = tComplexe1.dReel & tComplexe1.dImg & "i"
Else
CompToString = tComplexe1.dReel & "+" & tComplexe1.dImg & "i"
End If
End Function

Public Function CompSet(dReel As Double, dImg As Double) As tComplexe
CompSet.dImg = dImg
CompSet.dReel = dReel
End Function

Exemple d'utilisation :

Option Explicit

Private Sub Form_Load()
Dim cA As tComplexe
Dim cB As tComplexe
Dim cC As tComplexe

cA = CompSet(5, 5)
cB = CompSet(2, -8)

'//ou

cA.dReel = 5
cA.dImg = 5
cB.dReel = 2
cB.dImg = -8

cC = CompOperation(ecAddition, cA, cB)

Debug.Print CompToString(cC)

cC = CompOperation(ecMultiplication, cC, cA)

Debug.Print CompToString(cC)

cC = CompOperation(ecConjugue, cC, CompNul)

Debug.Print CompToString(cC)

End Sub

--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/

jean-pierre sarteaux a écrit :

> Bonjour,
>
> je n'arrive pas à y trouver des exemples de procédures EN VB
> d'opérations sur le nombres et expressions complexes.
> (Addition de complexe, multiplication de complexe, ect...)
>
> Pouvez vous me dire et m'indiquer ou je pourrai trouver ces exemples.
>
> En vous remerciant par avance,
>
> Bien cordialement à tous.
> Jean-Pierre


Avatar
jean-pierre sarteaux
Nicolas,
Au fait comment tansformerai tu ton code ci dessous pour en faire une
classe??
Merci par avnce pour ton futur exemple. J
ean-Pierre

ng a *crit :

Salut,

Tu peux essayer ce module (on aurait pu faire une classe aussi) :

Option Explicit

Public Type tComplexe
dImg As Double
dReel As Double
End Type

Public Enum eCompOperation
ecAddition = 0
ecSoustraction = 1
ecDivision = 2
ecMultiplication = 3
ecConjugue = 4
End Enum

Public Function CompNul() As tComplexe: End Function

Public Function CompOperation(eOperation As eCompOperation, tComplexe1 As
tComplexe, tComplexe2 As tComplexe) As tComplexe
Select Case eOperation
Case ecAddition
CompOperation.dReel = tComplexe1.dReel + tComplexe2.dReel
CompOperation.dImg = tComplexe1.dImg + tComplexe2.dImg
Case ecSoustraction
CompOperation.dReel = tComplexe1.dReel - tComplexe2.dReel
CompOperation.dImg = tComplexe1.dImg - tComplexe2.dImg
Case ecDivision
CompOperation.dReel = tComplexe1.dReel / tComplexe2.dReel -
tComplexe1.dImg / tComplexe2.dImg
CompOperation.dImg = tComplexe1.dReel / tComplexe2.dImg +
tComplexe2.dReel / tComplexe1.dImg
Case ecMultiplication
CompOperation.dReel = tComplexe1.dReel * tComplexe2.dReel -
tComplexe1.dImg * tComplexe2.dImg
CompOperation.dImg = tComplexe1.dReel * tComplexe2.dImg +
tComplexe2.dReel * tComplexe1.dImg
Case ecConjugue
CompOperation.dReel = tComplexe1.dReel
CompOperation.dImg = -tComplexe1.dImg
End Select
End Function

Public Function CompToString(tComplexe1 As tComplexe) As String
If tComplexe1.dImg < 0 Then
CompToString = tComplexe1.dReel & tComplexe1.dImg & "i"
Else
CompToString = tComplexe1.dReel & "+" & tComplexe1.dImg & "i"
End If
End Function

Public Function CompSet(dReel As Double, dImg As Double) As tComplexe
CompSet.dImg = dImg
CompSet.dReel = dReel
End Function

Exemple d'utilisation :

Option Explicit

Private Sub Form_Load()
Dim cA As tComplexe
Dim cB As tComplexe
Dim cC As tComplexe

cA = CompSet(5, 5)
cB = CompSet(2, -8)

'//ou

cA.dReel = 5
cA.dImg = 5
cB.dReel = 2
cB.dImg = -8

cC = CompOperation(ecAddition, cA, cB)

Debug.Print CompToString(cC)

cC = CompOperation(ecMultiplication, cC, cA)

Debug.Print CompToString(cC)

cC = CompOperation(ecConjugue, cC, CompNul)

Debug.Print CompToString(cC)

End Sub

--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/

jean-pierre sarteaux a écrit :

> Bonjour,
>
> je n'arrive pas à y trouver des exemples de procédures EN VB
> d'opérations sur le nombres et expressions complexes.
> (Addition de complexe, multiplication de complexe, ect...)
>
> Pouvez vous me dire et m'indiquer ou je pourrai trouver ces exemples.
>
> En vous remerciant par avance,
>
> Bien cordialement à tous.
> Jean-Pierre


Avatar
François Picalausa
Hello,

Tu pourrais le faire comme ceci:
Option Explicit

Private mR As Double
Private mI As Double

Public Property Get RealPart() As Double
RealPart = mR
End Property

Public Property Get ImaginaryPart() As Double
ImaginaryPart = mI
End Property

Public Property Let RealPart(NewValue As Double)
mR = NewValue
End Property

Public Property Let ImaginaryPart(NewValue As Double)
mI = NewValue
End Property

Public Sub Add(Complex As CComplex)
If Not Complex Is Nothing Then
mR = mR + Complex.RealPart
mI = mI + Complex.ImaginaryPart
End If
End Sub

Public Sub Add2(Real As Double, Imaginary As Double)
mR = mR + Real
mI = mI + Imaginary
End Sub

Public Sub Substract(Complex As CComplex)
If Not Complex Is Nothing Then
mR = mR - Complex.RealPart
mI = mI - Complex.ImaginaryPart
End If
End Sub

Public Sub Substract2(Real As Double, Imaginary As Double)
mR = mR - Complex.RealPart
mI = mI - Complex.ImaginaryPart
End Sub

Public Sub Multiply(Complex As CComplex)
If Not Complex Is Nothing Then
mR = mR * Complex.RealPart - mI * Complex.ImaginaryPart
mI = mI * Complex.RealPart + mR * Complex.ImaginaryPart
End If
End Sub

'...

Public Sub SetNull()
mR = 0
mI = 0
End Sub

Public Sub SetValue(Real As Double, Imaginary As Double)
mR = Real
mI = Imaginary
End Sub

Public Function ToString() As String
If mI <> 0 And mR <> 0 Then
ToString = mR & " + " & mI & "i"
ElseIf mI Then
ToString = mI & "i"
Else
ToString = mR
End If
End Function

Private Sub Class_Initialize()
'On initialise à 0+0i=0
mR = 0
mI = 0
End Sub

--
François Picalausa (MVP VB)
http://faq.vb.free.fr --- http://msdn.microsoft.com

"jean-pierre sarteaux" a écrit dans le
message de news:
Au fait comment tansformerai tu ton code ci dessous pour en faire une
classe??


Avatar
ng
J'allais le dire :D

--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/



François Picalausa a écrit :

Hello,

Tu pourrais le faire comme ceci:
Option Explicit

Private mR As Double
Private mI As Double

Public Property Get RealPart() As Double
RealPart = mR
End Property

Public Property Get ImaginaryPart() As Double
ImaginaryPart = mI
End Property

Public Property Let RealPart(NewValue As Double)
mR = NewValue
End Property

Public Property Let ImaginaryPart(NewValue As Double)
mI = NewValue
End Property

Public Sub Add(Complex As CComplex)
If Not Complex Is Nothing Then
mR = mR + Complex.RealPart
mI = mI + Complex.ImaginaryPart
End If
End Sub

Public Sub Add2(Real As Double, Imaginary As Double)
mR = mR + Real
mI = mI + Imaginary
End Sub

Public Sub Substract(Complex As CComplex)
If Not Complex Is Nothing Then
mR = mR - Complex.RealPart
mI = mI - Complex.ImaginaryPart
End If
End Sub

Public Sub Substract2(Real As Double, Imaginary As Double)
mR = mR - Complex.RealPart
mI = mI - Complex.ImaginaryPart
End Sub

Public Sub Multiply(Complex As CComplex)
If Not Complex Is Nothing Then
mR = mR * Complex.RealPart - mI * Complex.ImaginaryPart
mI = mI * Complex.RealPart + mR * Complex.ImaginaryPart
End If
End Sub

'...

Public Sub SetNull()
mR = 0
mI = 0
End Sub

Public Sub SetValue(Real As Double, Imaginary As Double)
mR = Real
mI = Imaginary
End Sub

Public Function ToString() As String
If mI <> 0 And mR <> 0 Then
ToString = mR & " + " & mI & "i"
ElseIf mI Then
ToString = mI & "i"
Else
ToString = mR
End If
End Function

Private Sub Class_Initialize()
'On initialise à 0+0i=0
mR = 0
mI = 0
End Sub


"jean-pierre sarteaux" a écrit dans le
message de news:
Au fait comment tansformerai tu ton code ci dessous pour en faire une
classe??




Avatar
jean-pierre sarteaux
François
Merci pour ton aide et aussi merci à Nicolas pour son intention.
Bien cordialement à vous deux et aussi a tous ceux qui mon répondu.
JP

"François Picalausa" a *crit :

Hello,

Tu pourrais le faire comme ceci:
Option Explicit

Private mR As Double
Private mI As Double

Public Property Get RealPart() As Double
RealPart = mR
End Property

Public Property Get ImaginaryPart() As Double
ImaginaryPart = mI
End Property

Public Property Let RealPart(NewValue As Double)
mR = NewValue
End Property

Public Property Let ImaginaryPart(NewValue As Double)
mI = NewValue
End Property

Public Sub Add(Complex As CComplex)
If Not Complex Is Nothing Then
mR = mR + Complex.RealPart
mI = mI + Complex.ImaginaryPart
End If
End Sub

Public Sub Add2(Real As Double, Imaginary As Double)
mR = mR + Real
mI = mI + Imaginary
End Sub

Public Sub Substract(Complex As CComplex)
If Not Complex Is Nothing Then
mR = mR - Complex.RealPart
mI = mI - Complex.ImaginaryPart
End If
End Sub

Public Sub Substract2(Real As Double, Imaginary As Double)
mR = mR - Complex.RealPart
mI = mI - Complex.ImaginaryPart
End Sub

Public Sub Multiply(Complex As CComplex)
If Not Complex Is Nothing Then
mR = mR * Complex.RealPart - mI * Complex.ImaginaryPart
mI = mI * Complex.RealPart + mR * Complex.ImaginaryPart
End If
End Sub

'...

Public Sub SetNull()
mR = 0
mI = 0
End Sub

Public Sub SetValue(Real As Double, Imaginary As Double)
mR = Real
mI = Imaginary
End Sub

Public Function ToString() As String
If mI <> 0 And mR <> 0 Then
ToString = mR & " + " & mI & "i"
ElseIf mI Then
ToString = mI & "i"
Else
ToString = mR
End If
End Function

Private Sub Class_Initialize()
'On initialise à 0+0i=0
mR = 0
mI = 0
End Sub

--
François Picalausa (MVP VB)
http://faq.vb.free.fr --- http://msdn.microsoft.com

"jean-pierre sarteaux" a écrit dans le
message de news:
> Au fait comment tansformerai tu ton code ci dessous pour en faire une
> classe??