473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Calculation of sine values in C

18
I have to complete a task related to calculation of Sine values.
I made whole of the program but the first value Im getting, i.e. a * Sin(0), is always displayed as 10 rather than 0.

This is the loop code I tried :
Expand|Select|Wrap|Line Numbers
  1. //All the values a,f,fs.... are of float type.           
  2.     for(n = 0;n <= N-1; n++)
  3.     {
  4.         double *s = malloc(sizeof(double));
  5.         double *x = malloc(sizeof(double));
  6.         *x = (2 *  PI  * (f / fs)* n);         
  7.                *s = a * sin(*x);
  8.         printf("%f\n",*s);
  9.     }
  10.  
Anyone can help...!
Thanks :):):)
Mar 28 '08 #1
2 2283
weaknessforcats
9,208 Expert Mod 8TB
Beats me. sin(0) is 0. 0 times anything is 0.
Mar 28 '08 #2
jhamb
18
Beats me. sin(0) is 0. 0 times anything is 0.

Yeah..!! That is what I know. But everytime it came out to be 10 instead 0..
So, I posted... I found a bug in the code, just above the loop.
That was printing an extra 1 before 0....

Now its done with full accuracy..! :))
Apr 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Xanax | last post by:
Hi all, I need to produce a sine wave and use the WaveOut APi to sound it on my sound card. I also need to compute Fast Fourier Transform to modify the Sine wave. Any ideas on where to start or...
143
by: suri | last post by:
Hello I downloaded glibc and tried looking for the code that implements the sine function i couldnt find the file. i went to the math directory and found math.h.. i guess that needs to be...
0
by: Pallav | last post by:
i'm trying to build a lookup sine table to run some code in an embedded processor without floating point unit. the table is 256 values for 360 degrees. my code is below. the fixed point base is...
2
by: Dan | last post by:
* 32 * * .5 * X * *********** I have a triangle with a Hypotenuse of 32 and height of .5. I am trying to determine what angle X is. On a calculator I take .5/32 = .015625...
5
by: MathNewbie | last post by:
Hi, I'm trying to do get my head around some, probably basic, math calculations. I checked some .net math libs, but the only thing I learn from studying those is humility ;-). Anyway, i have...
5
by: MandaRonnie | last post by:
I have an assignment im working on for my computer science class (c programming). My program compiles right, but doesn't run like its suppose to. Could someone help me? Here is the assignment: ...
7
by: company1484 | last post by:
I've been given an assignment to approximate the value of sine of an angle in degrees by using the formula: sin(x) = x −x3/3!+x5/5!−x7/7!+x9/9!· · · x is an angle in radians. He wants the program...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.