GB3- Fonctions mathématiques( Temps de lecture estimé à 3 min 06 sec )
Aujourd'hui, juste une visite de différentes fonctions mathématiques utilisables dans Gambas.
Voici le lien pour télécharger notre exemple : fonctions Mathématiques
Gambas class file Private Sub calcTrigo() '<----------------------- private car procédure interne à la class vbAngleRad.Value = CFloat(Val(Format(Rad(vbAngleDeg.Value), "0.########"))) '<--angle en radian vbSinus.Value = CFloat(Val(Format(Sin(vbAngleRad.Value), "0.########"))) '<--sinus de l'angle vbCosinus.Value = CFloat(Val(Format(Cos(vbAngleRad.Value), "0.########"))) '<--cosinus de l'angle vbTangente.Value = Round(CFloat(Val(Format(Tan(vbAngleRad.Value), "0.########"))), -7) '<--tangente de l'angle vbSinusH.Value = CFloat(Val(Format(Sinh(vbAngleRad.Value), "0.########"))) '<--sinus hyperbolique vbCosinusH.Value = CFloat(Val(Format(Cosh(vbAngleRad.Value), "0.########"))) '<--cosinus hyperbolique vbTangenteH.Value = (CFloat(Val(Format(Tanh(vbAngleRad.Value), "0.########")))) '<--tangente hyperbolique vbArcCos.Value = CFloat(Val(Format(ACos(vbCosinus.Value), "0.########"))) '<--arccosinus vbArcSin.Value = CFloat(Val(Format(ASin(vbSinus.Value), "0.########"))) '<--arcsinus vbArcCosH.Value = CFloat(Val(Format(ACosh(vbCosinusH.Value), "0.########"))) '<--arccosinus hyperbolique vbArcSinH.Value = CFloat(Val(Format(ASinh(vbSinusH.Value), "0.########"))) '<--arcsinus hyperbolique vbArcTangente.Value = CFloat(Val(Format(ATan(vbTangente.Value), "0.########"))) '<--arctangente vbArcTangenteH.Value = CFloat(Val(Format(ATanh(vbTangenteH.Value), "0.########"))) '<--arctangente hyperbolique End Private Sub calcLog() '<------------------------- private car procédure interne à la class If vbNombre.Value = 0 Then '<--pour éviter log(0) vbLog10.Value = 0 vbLogn.Value = 0 vbLog2.Value = 0 vbLogp.Value = 0 vbSqr.Value = 0 vbExp.Value = 0 vbExp2.Value = 0 vbExp10.Value = 0 Return Endif vbLog10.Value = CFloat(Val(Format(Log10(vbNombre.Value), "0.#######"))) 'log 10 vbLogn.Value = CFloat(Val(Format(Log(vbNombre.Value), "0#.#######"))) 'log n vbLog2.Value = CFloat(Val(Format(Log2(vbNombre.Value), "0.#######"))) 'log 2 vbLogp.Value = CFloat(Val(Format(Logp(vbNombre.Value), "0.#######"))) 'log p vbSqr.Value = CFloat(Val(Format(Sqr(vbNombre.Value), "0.#######"))) 'sqr If vbNombre.value > 709 Then 'pour éviter la saturation mémoire vbExp.Value = 0 vbExp2.Value = 0 vbExp10.Value = 0 Return Endif vbExp.Value = (Val(Format(Exp(vbNombre.Value), "0.#######"))) 'exp vbExp2.Value = (Val(Format(Exp2(vbNombre.Value), "0.#######"))) 'exp2 vbExp10.Value = (Val(Format(Exp10(vbNombre.Value), "0.#######"))) 'exp10 End Private Sub calcComplex() '<--------------------- private car procédure interne à la class Dim Z As New Complex '------------ sans utilisation de gb.complex --------------------------------- TextBox1.Text = CStr(vbReel.Value) & " + " & CStr(vbImag.Value) & " i" 'Nombre complexe TextBox2.Text = CStr(vbReel.Value) & " - " & CStr(vbImag.Value) & " i" 'son conjugué vbAbs2.Value = Val(Format(Sqr(vbReel.Value ^ 2 + vbImag.Value ^ 2), "0.########")) 'module If vbImag.Value >= 0 Then 'And vbReel.Value <> 0 vbArg.Value = Val(Format(ACos(vbReel.Value / vbAbs2.Value), "0.########")) 'argument si part imaginaire=0 Endif If vbReel.Value >= 0 Then 'And vbImag.Value <> 0 vbArg.Value = Val(Format(ASin(vbImag.Value / vbAbs2.Value), "0.########")) 'argument si part réelle =0 Endif If vbReel.Value < 0 Or vbReel.value > 0 Then vbArg.Value = Val(Format(ATan(vbImag.Value / vbReel.Value), "0.########")) 'argument Else vbArg.Value = 0 Endif vbArg2.Value = Round(CFloat(Val(Format(Deg(vbArg.Value), "0.#######"))), -2) 'argument en degrés '---------- avec utilisation de gb.complex ---------------------------------- z.Real = vbReel.value z.Imag = vbImag.Value ' z = Complex(vbReel.Value, vbImag.Value) 'fonctionne aussi vbModule.Value = Val(Format(Sqr(z.Abs2()), "0.########")) 'attention Abs2 donne le carré du module vbArgument.Value = Round(CFloat(Val(Format(Deg(z.Arg()), "0.#######"))), -6) vbConjugue.Text = z.Conj() 'penser aux parenthèses sinon les fonctions renvoient les fonctions et non le résultat des fonctions vbZ.Text = z.ToString(True) 'z ' les deux fonctionnent End Private Sub logique() '<------------------------- private car procédure interne à la class If vbReel.Value > vbImag.Value Then lblSup.Text = "Vrai" Else lblSup.Text = "Faux" If vbReel.Value < vbImag.Value Then lblInf.Text = "Vrai" Else lblInf.Text = "Faux" If vbReel.Value = vbImag.Value Then lblEgal.Text = "Vrai" Else lblEgal.Text = "Faux" If vbReel.Value <> vbImag.Value Then lblDiff.Text = "Vrai" Else lblDiff.Text = "Faux" If vbReel.Value >= vbImag.Value Then lblSupouEgal.Text = "Vrai" Else lblSupouEgal.Text = "Faux" If vbReel.Value <= vbImag.Value Then lblInfouEgal.Text = "Vrai" Else lblInfouEgal.Text = "Faux" End
C'était juste un petit tour de fonctions mathématiques connues et incontournables.
======= Documentation ========