473,414 Members | 1,599 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,414 software developers and data experts.

approximating a series

The value ex can be approximated by the sum
1 + x + x2/2! + x3/3! + … + xn/n!
Write a program that takes a value x as input and outputs this sum for n taken
to be each of the values 1 to 100. The program should also output ex
calculated using the predefined function exp. The function exp is a predefined
function such that exp(x) returns an approximation to the value ex. The
function exp is in the library with the header file cmath. Your program should
repeat the calculation for new values of x until the user says she or he is
through.
Use variable of type double to store the factorials or you are likely to produce
integer overflow (or arrange your calculation to avoid any direct calculation of
factorials). 100 lines of output might not fit comfortably on your screen. Output
the 100 output values in a format that will fit all 100 values on the screen. For
example, you might output 10 lines with 10 values on each line.
Mar 13 '07 #1
8 3265
sicarie
4,677 Expert Mod 4TB
The value ex can be approximated by the sum
1 + x + x2/2! + x3/3! + … + xn/n!
Write a program that takes a value x as input and outputs this sum for n taken
to be each of the values 1 to 100. The program should also output ex
calculated using the predefined function exp. The function exp is a predefined
function such that exp(x) returns an approximation to the value ex. The
function exp is in the library with the header file cmath. Your program should
repeat the calculation for new values of x until the user says she or he is
through.
Use variable of type double to store the factorials or you are likely to produce
integer overflow (or arrange your calculation to avoid any direct calculation of
factorials). 100 lines of output might not fit comfortably on your screen. Output
the 100 output values in a format that will fit all 100 values on the screen. For
example, you might output 10 lines with 10 values on each line.
Ok, so what is your question about that?
Mar 13 '07 #2
DeMan
1,806 1GB
First work through the problem in the most obvious way, creating a method that works out x^n/n!, and create a loop to iterate through adding these values from 1 to 100.

You'll find your output may not be so accurate (factorials get REALLY big, even at 10! we're already up to 3628800.....) This is why the problem suggests that you try to avoid using a direct fatorial calculation). Likewise x^100 could be a reasonably large value, so you may like to find a shortcut for that also....
HINT: you can simplify an individual (x^n)/n! to something like (x/1) * (x/2) * (x/3) * .. .. * (x/n). While this may talke longer to calculate, you'll find the answer is more likely to be accurate, as you are always dealing with manageable quantities.
Mar 13 '07 #3
Ok, so what is your question about that?
i need to write a programe for this equation .. i have no idea how to start it
Mar 14 '07 #4
DeMan
1,806 1GB
How much do you know about programming?
how well do you understand the equation?


The experts here are more than happy to help, but they won't give you a complete answer (after all that defeats the purpose of doing an assignment).

When you say you don't know how to start, you obviously have a lot of Mathematical information in the question, so I assume you need help with the actual programming. I doubt the question would have been posed if you had had no exposure to programming, so I'm not really sure where you are at.

Basically if you plan how to do it first, and then try to implement some basic things. You might first like to start by making a function that adds x consecutive numbers.....
Having done this, you might like to refine that method into something more useful.

If you get stuck, please post again, but please understand that we like to see that you have made an effort. You will never learn without doing, and while I appreciate that sometimes it may be difficult, the best way to get help is to show how much you know....
Mar 14 '07 #5
can sm one plz tell me how to declare the variables ///
Mar 14 '07 #6
How much do you know about programming?
how well do you understand the equation?


The experts here are more than happy to help, but they won't give you a complete answer (after all that defeats the purpose of doing an assignment).

When you say you don't know how to start, you obviously have a lot of Mathematical information in the question, so I assume you need help with the actual programming. I doubt the question would have been posed if you had had no exposure to programming, so I'm not really sure where you are at.

Basically if you plan how to do it first, and then try to implement some basic things. You might first like to start by making a function that adds x consecutive numbers.....
Having done this, you might like to refine that method into something more useful.

If you get stuck, please post again, but please understand that we like to see that you have made an effort. You will never learn without doing, and while I appreciate that sometimes it may be difficult, the best way to get help is to show how much you know....

am a biggner not very sure of c++ coding i want to learn but i am unable to do this equation . if i have the answer i can try it and learn how it works
Mar 14 '07 #7
horace1
1,510 Expert 1GB
am a biggner not very sure of c++ coding i want to learn but i am unable to do this equation . if i have the answer i can try it and learn how it works
you need to start by implementing some sime program defining variables and executing loops, have a look at the tutorial
http://www.cplusplus.com/doc/tutorial/
Mar 14 '07 #8
DeMan
1,806 1GB
can sm one plz tell me how to declare the variables ///
some examples.....(before you have a look at the tutorial listed above)

Expand|Select|Wrap|Line Numbers
  1. int i;  /* i is now of type int */
  2. float f; /* f has been declared as a floating-point type */
  3. char c; /* c has been declared as a character (8bit integer) */
  4.  
  5. int k = 0; /* k has been declared an int, and initialised to 0 */
  6.  
  7. /* There are other base types also, but i leave it for you to find them out */
  8.  
  9.  
Mar 14 '07 #9

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

Similar topics

2
by: Grant Edwards | last post by:
I've been looking for some way to approximate scattered 3D data points in Python. The data doesn't seem to be amenable to fitting functions like polymials, so I may have to use something more...
1
by: Sriram Krishnan [at] gmx [dot] net | last post by:
Given an arbitrary number series, how do I identify the series and find the Nth number... for e.g 1,3,5,7 is an AP and the next number will be 9 1,8,27,64 is the series of cubes and the next will...
7
by: bryo1001 | last post by:
Hi, im writing a prog to approximate pi as im teaching myself c++. I was just wondering if i wanted to calculate pi to a certain tolerance, say like (pi - .001) or some other tolerance, what kind...
6
by: Daniel Kabs | last post by:
Hello there, I have a Nokia 6630 phone that is based on the Series 60 Software Platform. -> http://www.series60.com/ These "smartphones" are said to support HTML 4.01 and "a subset of...
4
by: aW | last post by:
I have an interesting dilemma. I have a table with the following records: =================================================== Box | Series Start | Series End...
1
by: Sriram Krishnan [at] gmx [dot] net | last post by:
Given an arbitrary number series, how do I identify the series and find the Nth number... for e.g 1,3,5,7 is an AP and the next number will be 9 1,8,27,64 is the series of cubes and the next will...
4
by: geoffp | last post by:
I need to generate reproducible random number series. I've done the obvious - use mt_srand with the same seed. This supposedly will create the same series every time. Is this true? Its not...
4
by: keirnus | last post by:
Hello, I've been coding in Access VBA to create an Excel Graph and it was good. Until I got this error: Please check the code below: Private Sub TestGraph3()
1
by: Scholar | last post by:
Hi,i am working on a c++ project which will find the nth term of a given series.The series would be given in the form of first 4 or 5 terms.I have the basic alogorithm which can find the nth term of...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.