Funcții matematice în Python | Setul 2 (Funcții logaritmice și de putere)

Funcțiile numerice sunt discutate în setul 1 de mai jos Funcții matematice în Python | Set 1 (funcții numerice) Funcțiile logaritmice și de putere sunt discutate în acest set. 1. exp(a) :- Această funcție returnează valoarea lui e ridicat la putere a (e**a) . 2. log(a b) :- Această funcție returnează logaritmul valoarea lui a cu baza b . Dacă baza nu este menționată, valoarea calculată este de log natural. 

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  (  2    3  ))   

Ieșire:

The e**4 value is : 54.598150033144236 The value of log 2 with base 3 is : 0.6309297535714574 

Complexitatea timpului: O(1)

Spațiu auxiliar: O(1)


3. log2(a) :- Această funcție calculează valoarea lui log a cu baza 2 . Această valoare este mai precis decât valoarea funcției discutate mai sus. 4. log10(a) :- Această funcție calculează valoarea lui log a cu baza 10 . Această valoare este mai precis decât valoarea funcției discutate mai sus. 

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  ))   

Ieșire:

The value of log2 of 16 is : 4.0 The value of log10 of 10000 is : 4.0 

Complexitatea timpului: O(1)

Spațiu auxiliar: O(1)


5. pow(a b) :- Această funcție este folosită pentru a calcula valoarea lui a ridicat la putere b (a**b) . 6. sqrt() :- Această funcție returnează rădăcină pătrată a numărului. 

Python
   # 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  (  3    2  ))   # returning the square root of 25    print   (  'The value of square root of 25 : '     end  =  ''  )   print   (  math  .  sqrt  (  25  ))   

Ieșire:

The value of 3 to the power 2 is : 9.0 The value of square root of 25 : 5.0 

Complexitatea timpului: O(1)

Spațiu auxiliar: O(1)