そのような:
に等しい:
2 ** x = 11 を使った式は?</p>
x
一般に、底を底とする対数はn
として計算されlog(x)/log(n)
ます。
一部のライブラリでは、ショートカットを使用できます。たとえば、Python では次のようになります。
>>> import math
>>> math.log(11)/math.log(2)
3.4594316186372978
>>> math.log(11,2)
3.4594316186372978
>>> 2**_ # _ contains the result of the previous computation
11.000000000000004
これがあなたが知りたいことだと思います:
b^x=y
x=log(y)/log(b)
b=2とy=11の場合、次のように記述できます。
x=log(11)/log(2)、
ここで、bは対数の底、yは対数の引数です。
したがって、プログラミング言語で対数を計算するには、最初に 10 を底として評価し、それを底の対数で割り、10 を底とする対数も使用します。
さまざまなプログラミング言語での例を次に示します。
C#
using System;
namespace ConsoleApplicationTest
{
class Program
{
static void Main(string[] args)
{
double x = Math.Log10(11) / Math.Log10(2);
Console.WriteLine("The value of x is {0}.", x);
}
}
}
C++
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = log10(11)/log10(2);
cout << "The value of x is " << x << "." << endl;
return 0;
}
JavaScript
var x = Math.log(11)/Math.log(2);
document.write("The value of x is "+x+".");
Tim はすでに Python の例を示しています。