Android Question calculating natural log(ln)

tarique

Member
I am trying to take natural log (edittext1.text) using complexe library with following syntax
dim ln as complexe
ln=ln.log(edittext1.text)
or
variable=ln.log(edittext1.text)
or
variable=edittext1.text.log()
nothing works
it gives an error
anyone had tried this library or function then plz guide me
 

tarique

Member
B4X:
     Dim ln As complexe
     Dim real, imag As Double
     ' parse your real and imaginary parts into doubles
     real = 1.1
     imag = 2.2
     ln.setComplexe(real, imag)
     ln = ln.log
     Dim res As String = ln.Re  & "+i" & ln.Im
Sorry still I don't understand, b/c i want to get data from edittext
 
Upvote 0

Albert Kallal

Active Member
Licensed User
I am trying to take natural log (edittext1.text) using complexe library with following syntax
dim ln as complexe
ln=ln.log(edittext1.text)

B4A has a native built in Log function. So, you can use this code:
B4X:
Sub Button1_Click
    
    Dim const e As Double = 2.718281828459

    EditText2.Text = Logarithm(EditText1.Text,10)
    
    EditText3.Text = Logarithm(EditText1.Text,e)

The results on the screen should thus look like:

1589170310300.png


I don't know if the "e" constant is built in some place, but the above shows a log base 10 (used that in high school), and then we do a natural log based on the e constant.

So, above should work just fine. I did not even have to do a type conversion from the "text" value in the edit text boxes, but one should consider setting the format of the text box to number.

Regards,
Albert D. Kallal
Edmonton, Alberta Canada
 
Upvote 0

Albert Kallal

Active Member
Licensed User

Well, Bob's your uncle on that one! (thank you for that)

-So, to original poster?

code is now:
B4X:
    EditText2.Text = Logarithm(EditText1.Text,10)
    
    EditText3.Text = Logarithm(EditText1.Text,cE)

Regards,
Albert D. Kallal
Edmonton, Alberta Canada
 
Upvote 0

Albert Kallal

Active Member
Licensed User
I think that you have missed the point. It is complex numbers that the OP wishes to manipulate and that can't be (easily) done with B4X code.

You are quite right.

To original poster:

I am not sure if the/your problem was using only one text box for both numbers, or using that libary?

So, this would work:
B4X:
    Dim cX As complexe
    Dim cXLog As complexe
    
    Dim strArray() As String = Regex.Split(",",EditText1.text)
    
    cX.setComplexe(strArray(0),strArray(1))
    
    cXLog = cX.log
    
    EditText2.Text = cXLog.Re     ' show real part (log(e))
    EditText3.Text = cXLog.Im      ' show imaginary part (log(e))

So, the complex parts (real, imaginary) parts can be feed from one text box, we assume a "," between the two values.
If screen real estate is not at a preimum? I would go with two EditText boxes on the screen - not one text box.

R
Albert
 
Upvote 0
Top