how to calculate this logarithmic operation

Could you help me translate this logarithmic operation in the swift ui?

Operation:

Answered by ForumsContributor in
Accepted Answer

Welcome to the forum.

Some simple math here. Your expression is:

10 log (2 * 10**(x/10))

That is

10 log(2) + 10 log (10**(x/10) = 10 log(2) + 10 * x / 10 * log(10)

So result is simply:

10 log(2) + x log(10) = 6.931472 + 2.3025851 x

Works for log or log10 as you want.

That's much simpler (and gives a slightly more accurate result because there are less rounding effects) than the brute force computation):

var x : Float = 15 // Set the value of x

func compute(_ x: Float) -> Float {
    let x1 = x / 10
    let lnx = x1 * log(10)

    let p = exp(lnx)  // 10 ** (x/10)   //  log is Neper log, not log10

    let r = 10 * log(p + p)
    return r
}
print(compute(x))
let r = 10*log(2) + x*log(10)
print(r)

And check you get exactly the same result…

If that answers your question, don't forget to close the thread by marking the correct answer. Otherwise explain what you don't understand.

Thank you!!

how to calculate this logarithmic operation
 
 
Q