All About Circuits Forum  

Go Back   All About Circuits Forum > Software, Microcomputing, and Communications Forums > Programmer's Corner

Notices

Programmer's Corner Discussion forum for all aspects of programming and software engineering. Any software programming language welcome: C, C++, C#, Fortran, Java, Matlab, etc.

Reply   Post New Thread
 
Thread Tools Display Modes
  #1  
Old 04-28-2007, 12:53 PM
circuit2000 circuit2000 is offline
Junior Member
 
Join Date: Jul 2006
Posts: 33
Question C program for sine series

1)I am unable to write a C program to find the sum to n terms of a sine series. The concept used to find the sum to n terms of a cosine series is as follows:
First take Sum=1,t=1,i=1
So we have the first term. Now the second term is got by
t=(t*M) (where M= -x*x/(2i-1)*2i)
t= (-t*x*x/(2i-1)*2i
So we get the second term as,
t= (-1)*x*x/1*2 = -x^2/2
The multiplying term M can be got by dividing the (n+1)th term of the series by the nth term of the series. I applied the same method for sine series also and I got M as:
M=t(n+1)/t(n) = -x^2/2n(2n+1) Or, M= -x^2/2i(2i+1)
But using this expression of M, I am unable to generate the sine series.
The nth term of sine series is (-1)^(i+1)*x^(2i-1)/(2i-1)!
But no factorial function is available in C. So what is the way to write this program?
Reply With Quote
  #2  
Old 04-28-2007, 01:13 PM
recca02's Avatar
recca02 recca02 is offline
Senior Member
 
Join Date: Apr 2007
Location: India-22.35 N 82.68 E.
Posts: 1,211
Default

i know one thing abt factorials
u will have to define a function factorial by using for loop.
and call this function by the main function at the same time sending the arguments.
i hope u have learned abt functions ,if not try reading from some book
it will certainly have an example of the kind where call to a function is made
the function then returns the value to the main function.
Reply With Quote
  #3  
Old 04-28-2007, 06:13 PM
Papabravo's Avatar
Papabravo Papabravo is offline
Senior Member
 
Join Date: Feb 2006
Location: Michigan, USA (GMT-5)
Posts: 5,521
Default

Quote:
Originally Posted by recca02 View Post
i know one thing abt factorials
u will have to define a function factorial by using for loop.
and call this function by the main function at the same time sending the arguments.
i hope u have learned abt functions ,if not try reading from some book
it will certainly have an example of the kind where call to a function is made
the function then returns the value to the main function.
Nonsense! Factorial is the classic case of a recursive function. Two things to watch out for. First is overflow, and second is stack depth.

N.B. Try Ackermann's function for a really wicked example of runaway recursion.
__________________
We never have time to do it right,
But we always have time to do it over.
Reply With Quote
  #4  
Old 04-28-2007, 07:51 PM
recca02's Avatar
recca02 recca02 is offline
Senior Member
 
Join Date: Apr 2007
Location: India-22.35 N 82.68 E.
Posts: 1,211
Default

well i did mean recursive function,
i just wasnt able to recall the case correctly,
i dont deal with c programming that much.
Reply With Quote
  #5  
Old 04-28-2007, 10:02 PM
circuit2000 circuit2000 is offline
Junior Member
 
Join Date: Jul 2006
Posts: 33
Default

Now, I have only one way of solving it. I will have to write the program for cosine series and then adding an extra instruction sinx=sqrt(1- cosx*cosx). Anyway, thanx guys.
Reply With Quote
Reply   Post New Thread

Tags
, ,


Related Site Pages
Section Title
Textbook Selsyn (synchro) motors : Ac Motors
Worksheet Mixed-frequency signals
Worksheet Phasor mathematics
Worksheet Trigonometry for AC circuits


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I create line numbers for a QBASIC program and reconvert it to a program without lemuel rapsuk Programmer's Corner 4 11-11-2008 09:53 PM
Assembler program using 89c2051 for (IR remote ) manjula m Deshpande Embedded Systems and Microcontrollers 2 04-19-2007 01:59 PM
C program jjimenez01 Programmer's Corner 5 02-04-2007 09:49 AM
i need for help,error on z80 program red_008 Programmer's Corner 2 09-19-2006 10:39 PM
the term "common" shelly50 General Electronics Chat 27 01-23-2006 04:02 AM

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:57 AM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.