# Maximum PC

 It is currently Wed Jul 30, 2014 10:07 pm

 All times are UTC - 8 hours

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Sine/Cosine/Tangent FunctionsPosted: Fri Aug 06, 2004 1:04 pm
 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

 Post subject: Posted: Fri Aug 06, 2004 1:14 pm
 Java Junkie

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24222
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

 Post subject: Posted: Fri Aug 06, 2004 1:41 pm
 Bitchin' Fast 3D Z8000

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

 Post subject: Posted: Fri Aug 06, 2004 1:43 pm
 Bitchin' Fast 3D Z8000

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

 Post subject: SinePosted: Mon Aug 16, 2004 11:05 am
 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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC - 8 hours

#### Who is online

Users browsing this forum: No registered users and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ Maximum FAQs    Forum Rules, Posting Guidelines & Announcements    The Good, The Bad & The Banned    FAQs Help/Do It Yourself    PC Building Lab    The Help Desk    PC Modding    Education & Certification Hardware    Nuts & Bolts    Portable Talk    Appraisals, Deals & Bargains (oh my!) OS/Software/Programming    Windows Parlor    Alt.OS.Abode    Games Arena    Programmers' Paradise Networking/Internet    Internet Truckstop    Network Nook In/Out    Magazine and Book Feedback    Forum & Website Feedback    Dog Pound Team Maximum PC Folding at Home    Team Maximum PC - Folding at Home - FIND CURES TO DISEASES    Team MPC - Folding Gauntlets