Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Exercise_08_c #1

Closed
miladsade96 opened this issue Jun 6, 2020 · 7 comments
Closed

Implementation of Exercise_08_c #1

miladsade96 opened this issue Jun 6, 2020 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@miladsade96
Copy link
Owner

imgonline-com-ua-twotoone-tIdq3xAgq5O2B

@miladsade96 miladsade96 added enhancement New feature or request help wanted Extra attention is needed labels Jun 6, 2020
@LKedward
Copy link

LKedward commented Jun 6, 2020

I think m=2 and z=0.75 perhaps?

@miladsade96
Copy link
Owner Author

I think m=2 and z=0.75 perhaps?

How?

@LKedward
Copy link

LKedward commented Jun 6, 2020

Sorry, I should have explained that a bit more.

x = z*(2^m)

therefore

z = x/(2^m)

we can choose any m as long as -1 < z < 1.

Questions asks for x=3, for which m=2 and z=0.75 works.

Possible pseudo-code for program:

set ln2 = 0.6931472
ask user for value of x
ask user for value of m
calculate z = x/(2^m)
check that -1 < z < 1

calculate xi= (1-z)/(1+z)
calculate lnx = m*ln2 - 2*sum( (xi^(1:N))/(1:N) )

compare with exact value of ln(x)

Can try different values of m - I think smaller m will give a larger z which will give a smaller xi which will lead to fewer terms necessary for a certain precision.

Hope that helps a bit more.

edit: this repository is a really nice collection of Fortran snippets - great work!

@miladsade96
Copy link
Owner Author

Thank you very much @LKedward

@FortranFan
Copy link

@everlookneversee ,

Can you provide a reference to a derivation for the relationship you show in the original post?

A quick glance suggests the series is divergent for z <= 0, so a numerical approach is unclear for -1 <= z <= 0.

When z > 0, xi < 1, so one can compute the series numerically to determine lnx.

@LKedward
Copy link

LKedward commented Jun 8, 2020

@FortranFan, the exercises appear to be from: Bose, S., 2019. Numerical Methods Of Mathematics Implemented In Fortran. Singapore. Springer. See here on google.

The text does not provide a derivation for the relation; my summary conclusion is that it is an error since z <= 0 implies x <= 0 which would be problematic for then calculating ln(x).
As you point out, 0 < z <= 1 appear to be the correct bounds for z here.

@RonShepard
Copy link

One derivation of the relation in the original post follows from the identities

 y(z) = (1-z)/(1+z)

z(y) = (1-y)/(1+y)

From this, it follows that

ln(z) = ln(1-y) - ln(1+y)

Taylor expansion at y=0 on the right then gives the result shown in the original post where all of the even terms vanish. The radius of convergence of ln() on the right is -1<y<1. However, convergence is slow for large |y|, so the only useful values for computation are when y is small, which is when z is near +1. Thus in the computation where x is given, m should be chosen to make z<=1 as close to 1 as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants