|
|
|
|
![]() ![]() |
Sep 5 2005, 08:49 AM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 407 Joined: 13-December 04 Member No.: 2,696 |
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 |
|
|
|
Sep 6 2005, 07:25 AM
Post
#2
|
|
|
Neurotical Squirrel ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 590 Joined: 4-November 04 From: Novi Sad, Vojvodina Member No.: 2,127 |
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 |
|
|
|
Oct 20 2005, 02:34 AM
Post
#3
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 73 Joined: 21-September 05 Member No.: 12,113 |
Hi. It is must be a same result. Because mathemathics didn't change. Check your code.
|
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 13th October 2008 - 06:55 PM |