|
-
Oct 19th, 2002, 10:19 PM
#1
Thread Starter
Addicted Member
how does a calc do roots and trig functions?
How does a calculator calculate square roots and stuff like sin(10)? Does it do it mathamaticaly?
-
Oct 19th, 2002, 10:38 PM
#2
Stuck in the 80s
Re: how does a calc do roots and trig functions?
Originally posted by Flip
Does it do it mathamaticaly?
How else can you do math?
-
Oct 19th, 2002, 10:43 PM
#3
Good Ol' Platypus
You can calculate a cube root mathematically (what I think you mean by that is explain one math 'function' by combining others?), did you know that?
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Oct 20th, 2002, 06:35 AM
#4
Addicted Member
The Calculator uses approximation functions, in our second semester calculus class we derived approximations for cos(x),sin(x) and e^x
the approximation functions are just regular polynomials, if I remember correctly.
-
Oct 20th, 2002, 07:44 AM
#5
Fanatic Member
Really! if they have an approximation of sinx to the 9th digit of an polynomial for all angles, i'd love to see that polynomial!!!
anywayz i am not sure how a calculator does that, but it is possible to calculate sinx by using its taylor expansion.
Last edited by bugzpodder; Oct 20th, 2002 at 11:13 AM.
Massey RuleZ! ^-^__  Cheers!  __^-^ Massey RuleZ!
Did you know that...
The probability that a random rational number has an even denominator is 1/3 (Salamin and Gosper 1972)? This result is independently verified by me (2002)!
-
Oct 20th, 2002, 09:57 AM
#6
Addicted Member
I think that's what he was referring to, but don't quote me on it.
Not at all related to sheep...
-
Oct 20th, 2002, 11:02 AM
#7
Thread Starter
Addicted Member
like for example, how does the calculator calculate the square root of three? Is there a pencil-and-paper method that the calculator follows?
-
Oct 20th, 2002, 11:14 AM
#8
Fanatic Member
newton's square root approximation method would work. instead of sqrt(3) it can try to find a number x such that 3-x*x<0.00000001
Massey RuleZ! ^-^__  Cheers!  __^-^ Massey RuleZ!
Did you know that...
The probability that a random rational number has an even denominator is 1/3 (Salamin and Gosper 1972)? This result is independently verified by me (2002)!
-
Oct 20th, 2002, 11:45 AM
#9
Calculators and computers user Taylor series. They have infinite terms but if the variable lies in a specific range of values they converge and usually they do very rapidly. For example, for the sinus you have:
sin(x) = x - x3/3! + x5/5! - x7/7! + ...
so the nth term is: (-1)n+1x(2n-1)/(2n-1)!
This works for |x|<=? (I'm not sure if it's 1 or Pi/2, you'll have to check this out on a calculus book or insist to me that I do it myself as soon as I have one handy). If x is outside this range, then you can use a trigonometric formula such as:
sin(a + b)=sin(a)cos(b) + sin(b)cos(a) where a and b meet the requirement (if they don't, keep splitting them and use the formula recursively)
-
Oct 20th, 2002, 01:12 PM
#10
Addicted Member
it works for all x's but as x grows the number of terms in the series that we have to use to remain close to the actual sin value goes to infinity
-
Oct 20th, 2002, 03:32 PM
#11
So Unbanned
If you're using a program, to do the 3rd root is the same as
num ^ (1/3)
4th
num ^ (1/4)
etc.
-
Oct 21st, 2002, 02:36 AM
#12
Originally posted by Bjwbell
it works for all x's but as x grows the number of terms in the series that we have to use to remain close to the actual sin value goes to infinity
It doesn't actually work for all x, for instance, if x = Pi the series does not converge. Though it works only for 0<=x<=Pi/2, it can still be used for other values of x outside this range, by resourcing to "tricks" i.e. properties such as
sin(-x) = -sin(x), or sin(x + Pi/2) = cos(x), etc.
Just very few terms are really necessary for a high accuracy, only bear in mind x must be radiants, not degrees. For example, for 90 deg. you have approx. x = Pi/2 = 1.5708 and the result using just 5 terms is 1.000003543, not so different from the actual value 1
-
Oct 22nd, 2002, 09:58 AM
#13
Addicted Member
it does converge for x=Pi
try doing 10 taylor terms and evaluating it, it come out to 0.00679 which is pretty close to zero
-
Oct 22nd, 2002, 10:12 AM
#14
Originally posted by Bjwbell
it does converge for x=Pi
try doing 10 taylor terms and evaluating it, it come out to 0.00679 which is pretty close to zero
Yup...! I'll definitely have to take a new look into my calculus books...
Btw here's an applet to show you folks how accurate those series can get...
http://math.furman.edu/~dcs/java/taylor.html
-
Oct 25th, 2002, 02:26 PM
#15
Thread Starter
Addicted Member
The website "http://" doesn't really have much on it...
Repost the link or edit your post
ADDED FROM LAST POST: Yeah, im a retard. Just copy and paste. I am so observant...
Last edited by Flip; Oct 26th, 2002 at 06:19 PM.
-
Oct 25th, 2002, 04:50 PM
#16
Fanatic Member
The URL is displayed in the text. You can just copy and paste it if the liks doesn't work accidentally.
-
Oct 25th, 2002, 10:16 PM
#17
Addicted Member
There is a way to calculate square roots by hand, and it's kind of like a complicated form of division. Each time, two digits are dropped instead of one, and the previous quotient is multiplied by 20, while the new quotient is added to it. (Something like that)
-
Oct 25th, 2002, 11:59 PM
#18
Frenzied Member
There is at least one thread in this forum that discusses the Newton method for solving all sorts of problems. Square root is a special case, which works as follows.
Suppose you wanted the Square root of 100 and did not know that 10 was the answer. Take a wild guess, say 20.
Then 100/20 = 5, and answer is between 5 & 20.
Take average: (20 + 5) / 2 = 12.5, which is a lot better than 20.
100/12.5 = 8
Average: (12.5 + 8) / 2 = 10.25, we are getting closer.
If you keep it up, you get the following.
20
12.5
10.25
10.003 048 781
10.000 000 465
10.000 000 000
Note that when two successive values are almost equal, you know you are very close, even if you did not know what the final answer should be. If you started with a first guess of 100, it would only take a few more iterations to get an accurate result. A modern PC or calculator is so fast that a few extra iterations are not noticable. The first guess is not important.
The methods used by calculators & computers use some simple algorithm for the first guess. The (number + 1)/2 is not a terrible first guess. It is a compromise catering to original numbers less than one and greater than one. Trying half or 10% of the number is better for big numbers, but worse for numbers less than one.
Trig functions use power series as mentioned in a previous post. For an angle in radians (Pi * degrees / 180), Sine(x) is approximated by the following.
x - x3/3! + x5/5! - x7/7! . . .
3! = 3*2*1
5! = 5*4*3*2*1
et cetera.
Tricks are used to avoid calculating for large values of x, which require many terms of the polynomial. Some tricks are as follows.
For angles between 45 & 90, compute cosine of (90-angle).
Compute both Sine & Cosine of 1/2 or 1/4 of the angle and use formula for twice the angle.
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.
-
Oct 26th, 2002, 04:45 AM
#19
Frenzied Member
To calculate square roots we can iterate the following equation:
x = x/2 + k/2x
Solving the above U get x 2 = k
In VB
VB Code:
Public Function SquareRoot(thenumber As Double) as Double
Dim theVals() As Double
ReDim theVals(1 To thenumber)
theVals(1) = (1 / 2) + (thenumber / 2)
For i = 2 To thenumber
theVals(i) = (theVals(i - 1) / 2) + (thenumber / (2 * theVals(i - 1)))
If theVals(i) = theVals(i - 1) Then
SquareRoot = theVals(i)
Exit Function
End If
Next i
End Function
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 26th, 2002, 08:40 AM
#20
Frenzied Member
KayJay: Why use an array? If you do not have a lot of memory, you might have a problem finding the square root of a really large number like one billion.
Iterating until an exact match is overkill. If two successive values match in the first 6-7 digits, you have about 12 or more correct digits.
Can you Redim an array with a Double, which might not be an integer? Does this program compile?
BTW: Can your program find the square root of two or three? It seems to me that you would only iterate once or twice.
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.
-
Oct 26th, 2002, 11:09 AM
#21
Frenzied Member
Very true. It does not need an array, but this was not a final optimized routine. that said i'll optimize it. Yes to find out square roots of three and two are a problem with this. But we can use a "STEP" statement in the Loop to increment by 0.01 or 0.001 or whatever. An yes again the array cannot be dimensioned for as a double. But as U rightly pointed an array is not required at all. And yes this code will compile. And using the Round() function to test the results will make life easier.
http://www.vbforums.com/showthread.p...ber+squareroot
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
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
|