|
-
Mar 21st, 2002, 03:09 PM
#1
Thread Starter
Dazed Member
Logarithms?
Ive been trying to do some logarithms and i seem to get the right answers when doing them but i am still having trouble understanding the concept of them.
x = ay
log a(x) = log a(ay)
log a(x) = y
The logarithm is the exponent of the power to which a base number must be raised to equal a given number.
A logarithm is the inverse of an exponent.
Each exponent has an inverse logarithm.
So i basically have two questions.
1.) Can anyone explain the first definition in easier terms?
2.) I thought roots were the inverse of exponents.
So how i a logarithm the inverse of an exponent?
-
Mar 21st, 2002, 03:58 PM
#2
Fanatic Member
A root is in fact an exponent.
a ^ 1/n = nth root of a
Example: sqrt(a) = a^(1/2)
-
Mar 21st, 2002, 04:09 PM
#3
Thread Starter
Dazed Member
Thank you for replying riis. So if finding the given root of a number is the inverse of finding the exponent. sqrt(a) = a^(1/2) how a
logarithm be the the inverse of an exponent?
-
Mar 21st, 2002, 04:23 PM
#4
Thread Starter
Dazed Member
For instance take 24 = 16
log 2 (24) = log 2(16)
4 = log 2 (16)
The logarithm is the exponent of the power to which a base number must be raised to equal a given number.
4 = log 2 (16)
So how does 4 actually = log 2 (16) ?
-
Mar 21st, 2002, 04:26 PM
#5
Fanatic Member
What do you mean with "inverse"? The inverse of functions is something completely different than the inverse of numbers (2 vs. 1/2)
The inverse of a function works like this:
y = f(x)
x = g(y)
The function g is the inverse of the function f. (This also means that y = f(g(y)), although this depends on the domain and range of a function.)
The logarithm function of a given base a is the inverse of raising the number a with a certain power.
-
Mar 21st, 2002, 04:28 PM
#6
Fanatic Member
Originally posted by Dilenger4
So how does 4 actually = log 2 (16) ?
That's just how logarithms are defined. There's nothing more I can add, but perhaps a math guru can?
-
Mar 21st, 2002, 11:45 PM
#7
Frenzied Member
If y = ln(x), then e^y = x (Base e logs, where e = 2.71828 . . .)
If y = Log(x), then 10^y = x (Base 10 logs.).
If y = e^x, then x = ln(y)
If y = 10^x, then x = ln(y)
The above relationships are the reason that log and exponentials are called inverses of each other. Some people understand it better with the latter two equations; Some are more comfortable with the first two. Obviously, they are equivalent, and neither pair should be easier.
Log(100) = 2
Log(1000) = 3
Log(3.162 277 . . .) = 1/2 Note 3.162 277 = SquareRoot(10)
For some reason, it is a confusing relationship to understand. Most people have a problem with it, even though it is conceptually not different from saying that divide is the inverse of multiply & vice versa, as indicated by the following.
If y = a*x, then x = y / a
Due to the above, you get various other relationships.
If y = u*v, then ln(y) = ln(u) + ln(v) & ditto for logs base ten.
If y = u / v, then ln(y) = ln(u) - ln(v)
If y = a^x, then ln(y) = x*ln(a)
If you work with the above for a while, it seems easy. If you do not work with it for a year or so, it seems confusing again. If you work with it long enough, it becomes like riding a bicycle; You never forget.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Mar 22nd, 2002, 01:58 PM
#8
Hyperactive Member
If y = 10^x, then x = ln(y)
Just a little slip of the keyboard!
There are 10 types of people in the world - those that understand binary, and those that don't.
-
Mar 24th, 2002, 05:10 AM
#9
So how does 4 actually = log 2 (16) ?
That's just how logarithms are defined. There's nothing more I can add, but perhaps a math guru can?
Yeah, that's basically right. Logarithms are worked out so that 4 = log 2 (16).
In general, log x (x^y) = y
The most common log bases are log 10 -shortened to just log
and log e -shortened to ln
Logs come in handy for stuff to do with e, (=2.718281828....) and for figureing out how many digits a number has.
e.g. find the smallest power of three that has 45 digits.
=> 3^x > 10^45
=> log 3^x = log 10^45
=> x * log 3 = 45
=> x = 45 / log 3 = 95 (closest integer above answer)
=> 3^95 is the first that has 46 digits.
Note that above, log x stands for log 10 (x)- as log 10 is shortened to just log.
-
Mar 24th, 2002, 07:11 PM
#10
Frenzied Member
2^4 = 16
Therefore, 4 = log(16), base 2.
As Sql_lall said, it is based on the definiiton of what a logarithm is.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Mar 29th, 2002, 08:28 PM
#11
Fanatic Member
How would you go about implementing this in code??
It looks like loops will be involved... but i might be wrong.
Anyone??
BTW: I found a quick and dirty sollution to SIN function's implementation which is accurate to so many digits...
Code:
Sin(x) = 0.9998921 * x - 0.165961 * x ^ 3 + 0.0076032 * x ^ 5
Try it out.
-
Mar 31st, 2002, 05:11 AM
#12
What do you mean??
What do you mean by 'implement'?? Can't you just say somthing like:
I know you can in c++, not sure about VB. By the looks of the colouring above, it seems you might not. Anyway, i'm sure there is some command to let you use log.
-
Mar 31st, 2002, 05:17 AM
#13
Fanatic Member
no, no, no....
I mean the actual formulae... the algorythm... i WANT TO MAKE A LOG FUNCTION!!
I found some stuff about this but didnt like the fact that it was all crazy...
There are several kinds of logs, i want to focus on the two main ones: Log base 10 (which is just log) and log base e (which is ln).
Now how would I go about "computing" the log (or ln) of any given number?
Thanks,
MoMad
-
Mar 31st, 2002, 05:35 AM
#14
Fanatic Member
Im looking for something like:
Code:
ln(a) = 0.9991150*(a-1) - 0.4899597*(a-1)^2 + 0.2856751*(a-1)^3
- 0.1330566*(a-1)^4 + 0.03137207*(a-1)^5
Anyways, the formula... I am also looking for:
-- Log - Log base 10
-- Ln - Log base E
-- ATan - Arc Tangent
-- Sqrt - Square root
and maybe...
-- ASin - Arc Sine
-- nRt - Any root
-- Logn - Log base any
But I also need something that considers speed...
Regards,
MoMad
-
Mar 31st, 2002, 11:52 AM
#15
Frenzied Member
MoMad: Apparently you enjoy reinventing wheels. Sometimes it is lots of fun to redo what others have already done.
Converging series are almost always used to compute transcendental functions, although successive approximation methods are used for square root, cube root, et cetera.
I am too lazy to list all that you want. Try an internet search or go to a local library. The following are some examples.
Sin(x) = x - x^3/3! + x^5/5! - x^7/7! . . . (x in radians for all trig functions).
Cos(x) = 1 - x^2/2! + x^4/4! -x^6/6! . . .
Tan(x) = x + x^3/3 + 2*x^5/15 + 17*x^7/315 + 62*x^9/2835 . . . (??? pattern x^2 < 1)
e^x = 1 + x + x^2/2! + x^3/3! + x^5/5! . . .
Ln(1+x) = x - x^2/2 + x^3/3 - x^4/4 . . . . (x^2 must be less than one).
Various tricks are used to speed up the computations.
For example, the above series converge much faster for smaller values of x. When computing e^x, divide x by some power of two first. To find e^10, compute e^.625 (e^5/8) and square the result four times.
Chebyshev approximations to truncated versions of the above series are often used. Look this technique up in a college library that has good mathematics texts.
It is important to evaluate the above series using stored coefficients and start the computation with the coefficient of the highest order term. For example.
Code:
Compute Ax^3 + Bx^2 + Cx + D as the following
[(Ax + B)x + C]x + D
This method can be coded in a neat For . . . Next Loop, and provides better precision that other methods.
Square root and higher roots are done by successive approximations. There is a Thread here that describes the Newton Raphson methods in detail. For square root, you take a guess, divide, average the quotient and the guess. Use result as next guess. For example to find square root of 100 starting with a bad guess of 20.
100/20 = 5, then (5+20)/2 = 12.5 (better value than 20)
100/12.5 = 8, then (8 + 12.5)/2 = 10.25 (It is getting closer)
Find the Thread for a lot more information on Newton-Raphson for calculating roots.
I hope the above gets you started. It is a long road ahead, and you are unlikely to improve on the functions provided by VB, C, and other compilers.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Mar 31st, 2002, 06:23 PM
#16
Fanatic Member
Hehe, Believe me... I already improved some so much!! Its not even funny!
Like:
Code:
Function Sin(x as double) as double
sin = 0.9998921 * x - 0.165961 * x ^ 3 + 0.0076032 * x ^ 5
End function
That is a bit faster than the C compiler's (if done in C) method and much faster than the VB compiler's method (if done in C)...
ALso, it approximates upto 5 decimal places!!
Now for the other ones (atan, log, etc...) I will need to use loops and bitshifting to get quick and accurate results. That will slow things down... so.... i will try to find ways or "tricks" to speed things up.
I have been reading on what some people from major math newsgroups have said about these things... So I will try to put together what they have and make mine own... otherwise I will just use the math.h library, but I just wanna know how they are done and how complex it gets just for the fun of it!!
Math is FUN, but not when you're failing the class!! LOL.
-
Mar 31st, 2002, 07:46 PM
#17
Frenzied Member
MoMad: Where or how did you get the coefficients?
5-digit precision is not much to brag about. Over what range do you get 5-digit precision? How would you get 5-digit precision for an angle of 250 degrees?
BTW: I used your approximation to calculate sin(85 degrees), and did not quite get 4 digit precision. Results as follows.
Via HP calculator Sin Function: .996 194 698
Via your approximation: .996 135 894 Converted to radians prior to calculations.
The first four digits agree, but when rounded to four digits, they disagree. This is not quite 4-digit precision. An old circular slide rule of mine does about that well.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Mar 31st, 2002, 10:56 PM
#18
Fanatic Member
Guv: I am not bragging, I am just saying that my method uses no loops or anything like that and it is "Accurate" to the significance that i need it for... I am using this for a game, so even 2-digit is fine. The precision is a derivative or some sort of integral involving newton's and this other guy's methods... I found this in a newsgroup and the person who posted it says its much faster than both lookup tables and the built in method.
Is this neat or what??
But thats not the point, I want a FAST way of computing this value. And this method works, so thats good. But I want something like this (Cheap and dirty way) of computing the following:
Atn
Log
Ln
Sqrt
BTW: Thanks for the help Guv.
Regards,
MoMad the NoMad
-
Apr 1st, 2002, 05:07 AM
#19
-
Apr 1st, 2002, 06:34 PM
#20
Fanatic Member
sql_lall: Thank you very much for the helpful math definitions. But to find log(x) itself is a pain in the @$$. Anyways, I will give it a try tonight... prove log(x) in terms of arithmatic operations, then put that in code.
The only problem is that all the log(x) formulas that i found only work for (integers) so no decimals, i think this is only a matter of dividing or something... but I will give it a shot. and the other thing is x has to be in the range 1 <= x < 2 (between 1 and 2 but not including 2).
I will try to post it here as soon as possible.
Thanks for all the help guys!!
-
Apr 1st, 2002, 11:02 PM
#21
Frenzied Member
Using logarithms to do square root seems silly. Successive approximation methods are pretty efficient, even with a bad first guess.
BTW: The MoMad coefficients for the sin function look like a Chebychev approximation to a truncated standard sin series.
For general purpose usage, mathematical functions are expected to handle almost any range of arguments. The basic routines lose speed and compactness due to being able to cope with a wide range of arguments.
The MoMad approximation to the sin function would provide hardly any precision if given an angle like 150 degrees. An exponential function which can handle e^50 has some work to do.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Apr 1st, 2002, 11:23 PM
#22
Fanatic Member
The MoMad approximation to the sin function would provide hardly any precision if given an angle like 150 degrees. An exponential function which can handle e^50 has some work to do.
Guv: Are you going to help me or keep telling me things that I either know or dont care for??
If you do know a way to do square roots that is both faster and easier to implement than what sql_lall suggested, then let it out please, dont hold it back (this is after all a sharing of ideas/code community). Anyways, i couldnt find any "quick & dirty" or fast ways to implement logarithms (or in this case any of: Log,Ln,Atan,Sqrt).
If you do know about these, please lemme know. Thanks!
-
Apr 2nd, 2002, 12:30 AM
#23
Frenzied Member
MoMad: Is there some reason why you do not want to do your own research?
Hardly anybody has memorized the coefficients for approximating transcendental functions. It would be a tedious job for me to type up all the coefficients for series from handbooks I have. I would be likely to make mistakes, and you would have to go to source material to verify what I typed. Most transcendental functions are approximated using polynomials based on the infinite series defining the functions. I provided a few examples in a previous post to this thread. Merely truncating these series is not the best method.
There is a Thread at VB Forums with a detailed description of the Newton-Raphson method for doing square root. It is probably the fastest method, especially if you work out an algorithm for getting a good first approximation. (1 + n) / 2 is a not terrible first guess, but there are better ones. I already posted a clue to Newton-Raphson for square root to this thread.
There have been many books published on approximations for digital computers. I used one called Approximations For Digital Computers by Cecil Hastings back in the 1950's. It is obsolete by now. I am sure that dozens with similar titles have been published since then. Any good college library should have a lot of pertinent books.
An Internet search is likely to turn up all sorts of information. You might try checking back issues of the Journal published by the Association For Computing Machinery (They have a website). There used to be an organization called S.I.A.M (Society for Industial and Applied Mathematics), which published a journal. If you contacted either of these organizations, they could give you citations.
If you are interested in approximations like the one you posted for the sin function, you might have to learn about Chebyshev polynomials. You can use them to improve the accuracy of truncated infinite series.
If you compare your sin approximation with the first three terms of the infinite series for the sin function (see a previous post of mine to this thread), you will see that your coefficients are approximately equal to the coefficients of that series.
The Chebyshev method is used to determine such coefficients, and I suspect that your polynomial is a Cebyshev adjustment to the standard series for the sin function. This method is more precise than merely truncating the infinite series, and tends to allow the use of a polynomial with less terms than a truncated series. It is the method most used in determining coefficients for polynomials to approximate transcendental functions.
Any good handbook of mathematics will provide the pertinent series for trig functions, exponentials, logs, et cetera.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Apr 2nd, 2002, 12:53 AM
#24
Fanatic Member
oooh... I got that from another forum at a newsgroup (comp.math or somethig) and I tried, and it worked so i used it.
But I think I got the basics of log, the easiest one ive seen after spending several weeks searching the web (im not a book person -- hate them cuz it takes forever to find something specific), I found many, many, many ways to do the same things, with each way having its fall back. But all of them are too much for what I want, I also found one that was EXACTLY what i wanted but lost it due to a computer crash and could not find it again...
Anyways, As i can understand, by "truncated series" you must mean:
Code:
log(1-x) = x - x^2/2 + x^3/3 - x^4/4 + x^5/5 ...
So maybe if i do something similar...
...
this is taking waay too long...
-
Apr 2nd, 2002, 01:16 AM
#25
Fanatic Member
BTW: The following method gets 2-3 digit precision from 1 <= a < 2.
But anything else, it gets off real badly..
Code:
Function ln(ByVal a As Double)
ln = 0.999115 * (a - 1) - 0.4899597 * (a - 1) ^ 2 + 0.2856751 _
* (a - 1) ^ 3 - 0.1330566 * (a - 1) ^ 4 + 0.03137207 * (a - 1) ^ 5
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|