473,404 Members | 2,178 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,404 software developers and data experts.

problem calculating factorials

hi guys, i have a homework assigment that i have to complete but im a bit lost on how to do one part of it.

the part of the question im having trouble with is this "

Calculate sin^2(x) approximately by using n terms (n>0)
the Taylor series

sin(x)=Sum[(-1)^k x^(2k+1)/(2k+1)!] (k goes from 0 to n-1)

"
im not exactly sure how to evaluate the factorial in the equation. I know we should use a for loop but lets say i used
for(k=0;k<n;k++)
j=(2k+1)*j

that wont work because lets say n=3 it would say (1)*(3)*(5) ect. and not actually do (1)(2)(3)(4)(5).
Feb 12 '08 #1
2 1235
JosAH
11,448 Expert 8TB
Suppose you have the k-th term of that Taylor series; express the k+1st term
in terms of the k-th term; note hat (2k+1)! == (2k-1)!*k*(k+1)

kind regards,

Jos
Feb 12 '08 #2
Laharl
849 Expert 512MB
n!, mathematically, is the product n(n-1)...(2)(1). Thus, (2k-1)!=(2k-1)(2k-2)...

To represent this in code, start by writing a loop to calculate n!, where n is any integer. A function is a good way to do this. Then, apply the function to your current problem.
Feb 12 '08 #3

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

Similar topics

19
by: snowdy | last post by:
I am using Interactive C with my handboard (68HC11) development system but I've got a problem that I am asking for help with. I am not new to C but learning all the time and I just cant see how to...
5
by: sugaray | last post by:
Hi, my problem with calculating the size of an array is when I pass an array as a parameter to a function which perform the calculation, the result never comes right, like below: int...
35
by: strictly_mk | last post by:
Hi all, forgive me if there is a simple solution for this. I am going through the following piece of code which simply calculates factorials out of a book, but when i run it I get the answer 0 for...
26
by: Schizoid Man | last post by:
Hi, I have a very strange arithmetic problem in C: double t = 0.1; int steps = 10; double time_step = t / (double)steps; I would expect the output of time_step to be 0.01000 (my output is...
5
by: skyline789 | last post by:
Hello guys! Just started learning java and kind of struggling my way through the code of factorials. Well, basically we were asked to write a code that displays the factorials of numbers from 1 to...
2
by: Nkhosinathie | last post by:
can Anyone please help me with this program. i'm halfway to finish it.my problem is i don't know how to end it. i'm calculating certain number of males who are between 20-30,with their highest...
59
by: Py-Fun | last post by:
I'm stuck trying to write a function that generates a factorial of a number using iteration and not recursion. Any simple ideas would be appreciated.
1
by: pakixd | last post by:
I'm having issues with a program I'm developing for a class. It is a Lucas Number calculation program that requires a pipe and fork to be used. The source code for the file can be found at <link...
11
by: ladan | last post by:
hi i have to write a c++ program that can calculate big factorials using a vector sized 17(for example c)and c can hold 8 digits i need help plz help me
5
by: catgreg | last post by:
I am currently working on a c++ program that computes factorials and I can't get it to work for some reason, i could really use a hint, this is what I have thus far for code: #include<iostream>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.