Numerieke functies worden hieronder in set 1 besproken Wiskundige functies in Python | Set 1 (numerieke functies) Logaritmische en machtsfuncties worden in deze set besproken. 1. exp(a) :- Deze functie retourneert de waarde van e verheven tot de macht a (e**a) . 2. logboek(a b) :- Deze functie retourneert de logaritmische waarde waarde van a met grondtal b . Als de basis niet wordt vermeld, is de berekende waarde een natuurlijke logwaarde.
Python# Python code to demonstrate the working of # exp() and log() # importing 'math' for mathematical operations import math # returning the exp of 4 print ('The e**4 value is : ' end='') print (math.exp(4)) # returning the log of 23 print ('The value of log 2 with base 3 is : ' end='') print (math.log(23))
Uitgang:
The e**4 value is : 54.598150033144236 The value of log 2 with base 3 is : 0.6309297535714574
Tijdcomplexiteit: O(1)
Hulpruimte: O(1)
3. log2(a) : - Deze functie berekent de waarde van log a met basis 2 . Deze waarde is nauwkeuriger dan de waarde van de hierboven besproken functie. 4. log10(a) : - Deze functie berekent de waarde van log a met grondtal 10 . Deze waarde is nauwkeuriger dan de waarde van de hierboven besproken functie.
Python
# Python code to demonstrate the working of # log2() and log10() # importing 'math' for mathematical operations import math # returning the log2 of 16 print ('The value of log2 of 16 is : ' end='') print (math.log2(16)) # returning the log10 of 10000 print ('The value of log10 of 10000 is : ' end='') print (math.log10(10000))
Uitgang:
netwerkbesturingssysteem
The value of log2 of 16 is : 4.0 The value of log10 of 10000 is : 4.0
Tijdcomplexiteit: O(1)
string parseren naar int
Hulpruimte: O(1)
5. pow(a b) : - Deze functie wordt gebruikt om de waarde van te berekenen a tot de macht b (a**b) . 6. sqrt() : - Deze functie retourneert de vierkantswortel van het nummer.
# Python code to demonstrate the working of # pow() and sqrt() # importing 'math' for mathematical operations import math # returning the value of 3**2 print ('The value of 3 to the power 2 is : ' end='') print (math.pow(32)) # returning the square root of 25 print ('The value of square root of 25 : ' end='') print (math.sqrt(25))
Uitgang:
The value of 3 to the power 2 is : 9.0 The value of square root of 25 : 5.0
Tijdcomplexiteit: O(1)
Hulpruimte: O(1)