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
1-Visitor
September 29, 2017

I am very sorry if I did not make myself clear. Not a native english speaker and I have only been studying mathematics mainly in my native language so some terms are new to me. I am uploading a Mathcad file in which my problem exists.

So what are we doing in class is everyone is getting a different function. We have to use maclaurin series and then calculate our given functions using other methods. Then we have to check the "error of calculation"/"the difference in result" from the inbuilt function calculator. I don't know how this method is called in english and I can't seem to find a translation.

I get the idea of what you are saying about not using 

while S1 /= S2

I added an example of the same job being done with sin(x) and it's using the same system as me and everything works splendid. I have tens of other examples using the same method for different functions and they all use

while S1 /= S2

I understand that it may not work for my function, but I would like to understand why that is. I hope the two examples in the file that I've added will make more sense of what I am trying to achieve.

Everthing works great with the second function, but with the one I need it stops working if I use

x>0.99

So if I would, lets say, put x=3 (which the answer is quite easily 0.5), the program can't calculate it.

If i'm still not making myself clear, please do tell. I really would like to get to the bottom of this.

21-Topaz II
September 29, 2017

Hi,

 

have fixed it so your function works see |S1-s2|<0.003 use any accuracy you like here.