Skip to main content
1-Visitor
Solved

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

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.

MJGAnswer
1-Visitor

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.

19 replies

24-Ruby IV

1. Send please the sheet!

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

Translate
16-Pearl

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

Translate
-MFra-
21-Topaz II

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

nunscapiscnient.jpg

Translate
terryhendicott
21-Topaz II

Hi

Your email has different equation than in picture, please clarify

 

Capture.JPG

Translate
1-Visitor

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
Translate
24-Ruby III

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.

Translate