GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Jan-2005, 14:10
Sancho Sancho is offline
New Member
 
Join Date: Jan 2005
Posts: 2
Sancho is on a distinguished road

Really amatuer to C++, trigonometry trouble


Heya all,

I'm really not very good at C++ at all, the most that I do is dabble in it, but at the moment I'm just trying to set up a program where I can do some trigonometry a lot easier than having to use a scientific calculator.

The problem that I'm having is with using arctan, arc-cosine and arcsine. normal tan(x*Pi/180) is working fine (as I know you have to convert into radians), but the problem is that no matter how I enter my value to use as atan(x)
it doesn't give a corrent answer. I've tried entering it as radians, both converting it before and by using:
atan(x*Pi/180)

and I've also tried the other way, converting from radians to decimal again, using x*180/pi

I just can't seem to get any answer that is correct out of it.

Sorry if this seems like a really simple thing to most, but I just can't get it to work.
  #2  
Old 12-Jan-2005, 17:13
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Sancho
Heya all,

I
The problem that I'm having is with using arctan, arc-cosine and arcsine. normal tan(x*Pi/180) is working fine (as I know you have to convert into radians), but the problem is that no matter how I enter my value to use as atan(x)


All trig function angles are in radians, just as a real mathematician would do it.

CPP / C++ / C Code:
#include <stdio.h>
#include <math.h>

int main()
{
  double Pi;
  double x;
  double y;

  /* here's a way to get pi without typing in a bunch of digits */
  Pi = 4.0 * atan(1.0);

  printf("Pi             = %.15f\n", Pi);

  x = Pi / 4.0;
  printf("Pi / 4.0       = %f\n", x);
  y = sin(x);
  printf(" sin(%f) = %f\n", x, y);
  x = asin(y);
  printf("asin(%f) = %f radians (%f degrees)\n\n", y, x, x * 180.0 / Pi);

  x = Pi / 8.0;
  printf("Pi / 8.0       = %f\n", x);
  y = tan(x);
  printf(" tan(%f) = %f\n", x, y);
  x = atan(y);
  printf("atan(%f) = %f radians (%f degrees)\n\n", y, x, x * 180.0 / Pi);

  return 0;
}

Regards,

Dave
  #3  
Old 13-Jan-2005, 03:16
Sancho Sancho is offline
New Member
 
Join Date: Jan 2005
Posts: 2
Sancho is on a distinguished road
Thanks dave, thats cleared it up a hell of a lot for me

Going to break out my old maths work books from A-level and try to remember how to do radians
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Binary Tree Trouble neufunk C Programming Language 4 06-Dec-2004 09:52
C programming trouble Newworld C Programming Language 8 12-Sep-2004 23:06
Ram Trouble Please HELP ademnaz Computer Hardware Forum 3 10-Sep-2004 20:39
Having trouble trying to format C: Nickster64 Computer Software Forum - Windows 2 27-Jul-2004 07:31
Trouble with htdocs on network drive. kibboy Apache Web Server Forum 0 11-Nov-2003 08:22

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:36.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.