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

S

skatemore9690

#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.
 
S

swengineer001

#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!!!
 
D

Daniel Rudy

At about the time of 3/4/2007 5:59 PM, (e-mail address removed) 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
 
O

osmium

#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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top