Nov 8, 2009

Log Function

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > VB Programming

Log Function

kvarnerexpress
Hi all.

I have some prob with log function.
The code below is not working, it returns a false value.
The value is not same with what I calculate using scientific calculator.

Using my program:
N=2
Na=1
log(N/Na)=0.6931

Using scientific calculator:
N=2
Na=1
log(N/Na)=0.30102999566

Code:

CODE
Na = 0
temp = 0
temp1 = 0
rs.MoveFirst
Do
   For column = 1 To rs.Fields.Count - 1
       'If rs.Fields(column) <> Null Then
       If Not IsNull(rs.Fields(column).Value) Then
           Na = Na + 1
       End If
   Next column
   N = rs.Fields.Count - 1
   temp = Log(N / Na)
   temp1 = Format(temp, "0.0000")
   rs2.AddNew
   rs2!Na = temp1
   rs2.Update
Na = 0
rs.MoveNext
Loop Until rs.EOF



kvarnerexpress

 

 

 


Comment/Reply (w/o sign-up)

Galahad
Yes, I had that same problem once...
In Visual Basic, LOG function is returning a value of natural logarithm (base2), whereas in math LOG specifies Base10 logarithm (or at least I think so). Now, in scientific calculator, you might have noticed LN button, just above the LOG button. If you do that function, you will get the value you want. So, in order to get the numbers you need, use this code or put it in a function:
CODE

Public Function MyLog(ByVal Number As Double) As Double
 MyLog = Log(Number) / Log(10)
End Function


This should give you the values you need, so your code might look something like this:
CODE

Na = 0
temp = 0
temp1 = 0
rs.MoveFirst
Do
  For column = 1 To rs.Fields.Count - 1
      'If rs.Fields(column) <> Null Then
      If Not IsNull(rs.Fields(column).Value) Then
          Na = Na + 1
      End If
  Next column
  N = rs.Fields.Count - 1
  temp = Log(N / Na) / Log(10)
  temp1 = Format(temp, "0.0000")
  rs2.AddNew
  rs2!Na = temp1
  rs2.Update
Na = 0
rs.MoveNext
Loop Until rs.EOF

 

 

 


Comment/Reply (w/o sign-up)

dul
Hi. It is must be a same result. Because mathemathics didn't change. Check your code.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


Searching Video's for log, function
See Also,
advertisement


Log Function

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com