Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- calculation of pi

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
07:10 AM

07-07-2016
07:10 AM

Hello everyone! I have some problem in cycle that I made in mathcd 15. I wrote short code to calculate pi number but only 14 numbers after point I can only see in my array and dont know what to do. Can anyone can help to solve this problem? @

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
10:04 AM

07-07-2016
10:04 AM

First: The loop with j as upper limit seems to be a bit useless. At least its not necessary to calculate pi 100 times with increasing precision. Calculate it once with max precision and then do your num2str thing.

The reason for the error is, that you are limited to numerical precison in a program, too.

So no matter how large you choose N1 to be, you will only get a result for pi with approx. 14 or 15 digits.

This result is then converted to a string with just 16 or 17 entries.

The error is when you demand to take element with indes number j+1 and j+1 is bigger than the last index in the array (max 16).

To get more decimals of pi you have a couple of choces:

Use a different algorithm which allows you to calculate specific decimals without calculating the decimals before it (spigot algorithm).

Implement your own long number arithmetic.

or use Mathcads symbolics to do the job:

Regards

Werner

19 REPLIES 19

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
09:47 AM

07-07-2016
09:47 AM

Re: calculation of pi

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
09:49 AM

07-07-2016
09:49 AM

Re: calculation of pi

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
09:56 AM

07-07-2016
09:56 AM

Re: calculation of pi

Sorry, but thats nonsense!

You stop the calculation the first time the loop is executed and return an approximated value (the value you would get originally with N1=10) which is completely independend of N1.

What you suggest is exactly the same as

Sure not, what the OP had in mind!

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
10:04 AM

07-07-2016
10:04 AM

First: The loop with j as upper limit seems to be a bit useless. At least its not necessary to calculate pi 100 times with increasing precision. Calculate it once with max precision and then do your num2str thing.

The reason for the error is, that you are limited to numerical precison in a program, too.

So no matter how large you choose N1 to be, you will only get a result for pi with approx. 14 or 15 digits.

This result is then converted to a string with just 16 or 17 entries.

The error is when you demand to take element with indes number j+1 and j+1 is bigger than the last index in the array (max 16).

To get more decimals of pi you have a couple of choces:

Use a different algorithm which allows you to calculate specific decimals without calculating the decimals before it (spigot algorithm).

Implement your own long number arithmetic.

or use Mathcads symbolics to do the job:

Regards

Werner

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
10:10 AM

07-07-2016
10:10 AM

Re: calculation of pi

Thank you, I will try!

But one thing I need every digit in array not in one float number.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
11:19 AM

07-07-2016
11:19 AM

Re: calculation of pi

Can you "cheat" by copy/pasting the symbolic result into a new string variable?

You could then easily isolate each digit by using the "substr" function.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
11:23 AM

07-07-2016
11:23 AM

Re: calculation of pi

Yes, I thought about it but if 1000 digits it is not working

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
04:08 PM

07-07-2016
04:08 PM

Re: calculation of pi

I didn't realize how many digits you wanted. As Werner noted below, the limit for the Mathcad symbolics is 250 significant digits.

If you don't consider this method "cheating," then perhaps you could just copy/paste from an online source?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
10:45 AM

07-07-2016
10:45 AM

Re: calculation of pi

Okay, took some looking:

The num2str function has a limit--it creates a string of only a certain length. (note num2str(pi) stops at ...79 while pi goes on ...793)

So regardless of how big N1 is, the substr function will fail when it tries to go past the last character in string c.

One fix:

This solves that problem, but it doesn't get you past the basic numerical precision issue.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
11:51 AM

07-07-2016
11:51 AM

Re: calculation of pi

Thank you!

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
10:47 AM

07-07-2016
10:47 AM

Re: calculation of pi

The main problem is that you are trying to calculate using the numeric calculation engine. Its accuracy is very limited (17 decimal places , showing 15/16).

if you want more accuracy , the only way as I understand is to use the symbolic calculation engine.

Example shows N1-10, this can continue up to approx. N1=80 after that the symbolic engine fails to generate a result.

This is also possible:

I'm not sure how far you can take this ,1000 places appears to be OK.

But as soon as you convert it to a numeric result, the 17 places limit will apply again.

If you want to create a digit by digit array, the numer and denom function will be useful.

The first steps in a manual version are attached, whether it is possible to automate this , I don't know.

Regards

Andy

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
11:20 AM

07-07-2016
11:20 AM

Re: calculation of pi

Thank you, I will try to automate this!

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
11:55 AM

07-07-2016
11:55 AM

Re: calculation of pi

> I'm not sure how far you can take this ,1000 places appears to be OK.

250 significant digits are the upper limit

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
12:13 PM

07-07-2016
12:13 PM

Re: calculation of pi

Well, may be I use spigot algorithm to generate array

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
04:16 PM

07-07-2016
04:16 PM

Re: calculation of pi

If 249 decimals are enough, copying the result of the symbolic evaluation (with float,250) in a string and then convert it in an array of digits would be easier.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
04:17 PM

07-07-2016
04:17 PM

Re: calculation of pi

Well, may be I use spigot algorithm to generate array

I am not sure about that algorithm. It can be that it needs big number arithmetic, too.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
04:28 PM

07-07-2016
04:28 PM

Re: calculation of pi

Thank you, I will try with 250 decimals may be it is enough to my little experiment

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2016
07:59 PM

07-07-2016
07:59 PM

Re: calculation of pi

Following is a numerical procedure to get decimals for Pi. But Mathcad, as numerical tool, can get more than 47. If you want more digits, guess must to take them from other software, and read digits from a file. Attached, also first million of pi digits as plain text.

Best regards.

Alvaro.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-08-2016
01:14 AM

07-08-2016
01:14 AM

Re: calculation of pi

Thank you so much!!!! 1 million is enough!