Skip to main content
1-Visitor
September 29, 2017
Solved

Calculations of function (1+x)^(-1/2)

  • September 29, 2017
  • 5 replies
  • 5990 views

Hello there,

I have a function that I'm trying to calculate using various methods (in Mathcad).

f(x) = 1/(1+x)^2

I've attached a photo of my code.

The problem is, that for every x from -0.9 to 0.9 the calculations are great, but if i choose x>1 - it gets stuck on an infinite loop (sometimes it even says that it encountered a floating point error). If i try to do a graph of s[0] it also only shows results till x=0.99. 

What am I doing wrong?

Thanks in advance.

Best answer by MJG

I'm not familiar with the maclaurin series, so I don't know what you're doing incorrectly.  However, take a look at the first several iterations of your While loop:

Capture.PNG

 

You can see that S1 and S2 will not be equivalent no mater how many loops you do.

In fact, you can see that "a" grows continuously further from 0.  For this loop to end, you need "a" to tend toward zero.

5 replies

24-Ruby IV
September 29, 2017

1. Send please the sheet!

2. You can use functions trace and pause for a debugging the program in Mathcad 15

16-Pearl
September 29, 2017

1/ (1+ -1) ^2 is division by zero.  

21-Topaz II
September 29, 2017

Please, you should be clearer. What should the program calculate? What is the algorithm used?

nunscapiscnient.jpg

21-Topaz II
September 29, 2017

Hi

Your email has different equation than in picture, please clarify

 

Capture.JPG

1-Visitor
September 29, 2017

I don't understand what you're doing in the while loop, but it seems unlikely that S1 and S2 would ever be exactly the same.  Consider a few options:

  • Tools -> Worksheet Options -> Calculation -> uncheck "Use exact equality for comparisons and truncation."
  • Change
    While S1≠S2
    to
    While abs(S2-S1) < {some acceptable level of tolerance}
  • Would it make sense to change it to this?
    While S1<S2
24-Ruby III
September 29, 2017

Hi,

 

@MJG is right. You cannot use condition S1 is not equal to S2 in while loop, when S1, S2 are real numbers. This condition is always TRUE, because of real number representation.