Quantcast

Maximum PC

It is currently Fri Dec 26, 2014 6:27 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Sine/Cosine/Tangent Functions
PostPosted: Fri Aug 06, 2004 1:04 pm 
8086
8086

Joined: Mon Aug 02, 2004 10:59 am
Posts: 50
Does anyone know how to do these (sin(x), cos(x), ln(x)) or other higher transcendals in C? Can't use any librarys, so just good old +-*/. Psuedocode is OK, as long as the math is there for me to see.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 1:14 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24238
Location: Granite Heaven
http://www.grc.nasa.gov/WWW/Wright/airplane/trig.html

That should do it.

What info do you have that you can work with? There are various methods of determining these values.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 1:41 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Wed Jun 16, 2004 11:30 am
Posts: 368
Location: San Antonio, TX
The math for approximating sine is below using the Taylor series. (x3 is x to the 3rd power).

sin x = x - x3/3! + x5/5! - x7/7! + ...

http://www.homeschoolmath.net/other_top ... ulator.php

x has to be in radians. Using just the first 4 terms should give you a value accurate to 7 decimal places. You may want to also write functions for raising a value to a power (Yes, this function already exists but its in the math library, same for factorial) as well as factorial.

Code:
double sin(double x) {
  return (x - ((x*x*x)/(3*2*1)) + ((x*x*x*x*x)/(5*4*3*2*1)) - ((x*x*x*x*x*x*x)/(7*6*5*4*3*2*1)));
}


The following would be a nasty quick and dirty way of approximating it using no math library functions.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 1:43 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Wed Jun 16, 2004 11:30 am
Posts: 368
Location: San Antonio, TX
I don't know for cosine, tanget, etc. You should be able to come up with a close approximation of them. In regards to the above formula, to get even closer you could do a recursive function im sure but I don't have time to code it out right now.


Top
  Profile  
 
 Post subject: Sine
PostPosted: Mon Aug 16, 2004 11:05 am 
8086
8086

Joined: Mon Aug 02, 2004 10:59 am
Posts: 50
Thank you so much DaBrain. That's what I wanted, the series, but I did not want a table. Now there are still a few more higher transcendals, like logb x, but I still don't know the series for that, or even if there is one.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.