|
|
Title | Calculate logarithms in different bases in Visual Basic 2005 |
Description | This example shows how to calculate logarithms in different bases in Visual Basic 2005 |
Keywords | log, ln, logarithm, base, log base, calculate, exponent, exponentiation, power, VB.NET |
Categories | Algorithms, Tips and Tricks |
|
|
Visual Basic .NET's Math.Log function calculates the natural log of a number. Its Math.Log10 calculates the logarithm in base 10. To calculate a log in a different base, use this formula:
Log(N) = Log(N)/Log(Base)
When you enter a number and a base and click the Find Log button, the program calculates the log of the number using that base. It displays the result and then raises the base to the calculated power to verify the result.
|
|
Private Sub btnFindLog_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnFindLog.Click
Dim num As Double = Val(txtNumber.Text)
Dim base As Double = Val(txtBase.Text)
Dim result As Double = Math.Log(num) / Math.Log(base)
txtResult.Text = result.ToString()
txtVerify.Text = (base ^ result).ToString()
End Sub
|
|
|
|
|
|