Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
digit

Subject: digit

From: Drew

Date: 22 Feb, 2012 15:35:13

Message: 1 of 3

i want to do a calculation on pi and need to figure out how to remove digits sequentially from 3.14159.... then 3.4159..... then 3.159.... then 3.59....and so on to a finite number of steps any help greatly appreciated

Subject: digit

From: Nasser M. Abbasi

Date: 22 Feb, 2012 16:07:35

Message: 2 of 3

On 2/22/2012 9:35 AM, Drew wrote:
> i want to do a calculation on pi and need to figure out how to
> remove digits sequentially from 3.14159.... then 3.4159..... then 3.159....
> then 3.59....and so on to a finite number of steps any help greatly appreciated

may be something along these lines:

pis=num2strexact(pi)
3.141592653589793115997963468544185161590576171875
for i=16:-1:2
     currentPi=str2num(pis(1:i))
end


    3.141592653589793
    3.141592653589790
    3.141592653589700
    3.141592653589000
    3.141592653580000
    3.141592653500000
    3.141592653000000
    3.141592650000000
    3.141592600000000
    3.141592000000000
    3.141590000000000
    3.141500000000000
    3.141000000000000
    3.140000000000000
    3.100000000000000
      3


--Nasser

Subject: digit

From: Roger Stafford

Date: 22 Feb, 2012 20:08:12

Message: 3 of 3

"Drew " <metuchen.premier@gmail.com> wrote in message <ji31vh$quh$1@newscl01ah.mathworks.com>...
> i want to do a calculation on pi and need to figure out how to remove digits sequentially from 3.14159.... then 3.4159..... then 3.159.... then 3.59....and so on to a finite number of steps any help greatly appreciated
- - - - - - - - - -
  Just to make sure there are no misunderstandings here, the 49-digit number Nassar produced with 'num2strexact' is an exact decimal representation of matlab's best double precision approximation to pi. However that best value is only accurate out to about sixteen decimal places for the real pi. It is the best matlab can do using only 53 bits.

  Here is pi out to about 100 places:

pi = 3.14159265358979323846264338327950288419716939937510 ...
        5820974944592307816406286208998628034825342117068

As you see, it begins to differ from the 'num2strexact' output at the 16th place.

  The mathematically exact pi is a transcendental number, which means that if it is expressed as a decimal fraction, that fraction never stops, nor are there ever any infinitely repeating cycles, such as in

 41/333 = .123123123123123 ..... ,

nor is it even true that it can ever be expressed as the solution to any polynomial equation with rational coefficients.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us