469,329 Members | 1,374 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

Can anyone please help me with these? I did save America, a few times...

#1 in Calculus you learned that
log(1+x) = x - x^2/2 + x^3/3 - x^4/4 + ...

for x in the interval (-1,1] (here x^2 means "x squared", etc.).
Write a program which asks the user to type a number in the interval
[1,2] and then calculates the natural logarithm of that number using
this series with 6 decimal places accuracy (you can use the
alternating harmonic series program as a template).
#2 Modify the program from the first problem and define a function
caled mylog which gives the natural logarithm of a number in the
interval [1,2] using the above series with the six decimal places
accuracy. Use this function in a program which to prints a table which
has 1.0, 1.1, 1.2, 1.3, ... , 2.0 in the first column, the value of
your function mylog for these numbers in the second column, and the
machine values of log for these numbers in the third column.
Check for the accuracy of your computation by comparing the values in
the second and third column. Observe that it takes much longer to
calculate log(2.0) than any other entry in the table. Can you tell
why?
#3 Modify the program for the second problem in the first assignment
so that the table of logarithms is written to a file named output.txt
instead of the standard output.

Mar 5 '07 #1
4 1682
sk***********@gmail.com writes:
Subject: Can anyone please help me with these? I did save
America, a few times...
Sorry, we don't do homework. Not even Brian Boitano's homework.
--
"This is a wonderful answer.
It's off-topic, it's incorrect, and it doesn't answer the question."
--Richard Heathfield
Mar 5 '07 #2
On Mar 4, 8:59 pm, skatemore9...@gmail.com wrote:
#1 in Calculus you learned that

log(1+x) = x - x^2/2 + x^3/3 - x^4/4 + ...

for x in the interval (-1,1] (here x^2 means "x squared", etc.).
Write a program which asks the user to type a number in the interval
[1,2] and then calculates the natural logarithm of that number using
this series with 6 decimal places accuracy (you can use the
alternating harmonic series program as a template).
#2 Modify the program from the first problem and define a function
caled mylog which gives the natural logarithm of a number in the
interval [1,2] using the above series with the six decimal places
accuracy. Use this function in a program which to prints a table which
has 1.0, 1.1, 1.2, 1.3, ... , 2.0 in the first column, the value of
your function mylog for these numbers in the second column, and the
machine values of log for these numbers in the third column.
Check for the accuracy of your computation by comparing the values in
the second and third column. Observe that it takes much longer to
calculate log(2.0) than any other entry in the table. Can you tell
why?
#3 Modify the program for the second problem in the first assignment
so that the table of logarithms is written to a file named output.txt
instead of the standard output.
At least have enough decency to try to disguise your homework!!!

Mar 5 '07 #3
At about the time of 3/4/2007 5:59 PM, sk***********@gmail.com stated
the following:
#1 in Calculus you learned that
log(1+x) = x - x^2/2 + x^3/3 - x^4/4 + ...

for x in the interval (-1,1] (here x^2 means "x squared", etc.).
Write a program which asks the user to type a number in the interval
[1,2] and then calculates the natural logarithm of that number using
this series with 6 decimal places accuracy (you can use the
alternating harmonic series program as a template).
#2 Modify the program from the first problem and define a function
caled mylog which gives the natural logarithm of a number in the
interval [1,2] using the above series with the six decimal places
accuracy. Use this function in a program which to prints a table which
has 1.0, 1.1, 1.2, 1.3, ... , 2.0 in the first column, the value of
your function mylog for these numbers in the second column, and the
machine values of log for these numbers in the third column.
Check for the accuracy of your computation by comparing the values in
the second and third column. Observe that it takes much longer to
calculate log(2.0) than any other entry in the table. Can you tell
why?
#3 Modify the program for the second problem in the first assignment
so that the table of logarithms is written to a file named output.txt
instead of the standard output.
Did you make an attempt? We'll help if you show that you made an
attempt by posting your code.

--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Mar 5 '07 #4
<sk***********@gmail.comwrote:
#1 in Calculus you learned that
log(1+x) = x - x^2/2 + x^3/3 - x^4/4 + ...

for x in the interval (-1,1] (here x^2 means "x squared", etc.).
Write a program which asks the user to type a number in the interval
[1,2] and then calculates the natural logarithm of that number using
this series with 6 decimal places accuracy (you can use the
alternating harmonic series program as a template).
Firstly, ignore exercises 2 and 3. They may just cloud your mind with a
fear factor. I would also ignore the parenthetical sentence above. It just
makes me wonder "What program? What is a template"? The equation is there,
use the damned equation. If you wrote some program in a prior assignment,
part of that may make sense to you. It's just obfuscating to me,

I would write three functions. Main deals with the user, getting sample
input and reporting the answers. A ln function would do the overall stuff
in the equation, including deciding when the precision was good enough.
Then I would write a function to compute an individual term for all terms
except the first. Note that each term is a nice little bundle and you can
determine the sign from within the "bundle" I would call the term function
from a for loop in the ln function. If the value returned by term is less
than some epsilon, say 1e-6, the precision is adequate and you can bail out
of the for loop.

I would put a detection mechanism at the start of the ln function to detect
out of range arguments.

Compile and test often. Sounds like it should be both fun and instructive
Mar 5 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

33 posts views Thread by Larry | last post: by
10 posts views Thread by =?Utf-8?B?am9uaWdy?= | last post: by
72 posts views Thread by dbahooker | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.