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
 
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:
Code: Copy
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
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:
Code: Copy
    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
Back
Top