Thread Subject: done in by a dim Sym

Subject: done in by a dim Sym

From: ross

Date: 27 May, 2008 13:25:47

Message: 1 of 4

Never bothered with symbolic math before, but now I want to use it for high
precision calculations.
The following didn't work as I expected:

digits = 50;
pi50 = sym('3.1415926535897932384626433832795028841971693993751');
e50 = sym('2.7182818284590452353602874713526624977572470936999');
piovere = vpa(pi50/e50, 50)

% expected output (reflecting the set value of digits = 50)
piovere =
1.1557273497909217179100931833126962991208510231644

% actual output (is equivalent to digits = 32, which is the default)
piovere =
1.1557273497909217179100931833127

Apparently I misunderstand how to use DIGITS with SYM.
Would someone please explain why the output doesn't reflect the DIGITS settings?

Thanks
Ross

Subject: done in by a dim Sym

From: us

Date: 27 May, 2008 13:41:02

Message: 2 of 4

ross:
<SNIP symbolic conundrum...

> digits = 50;
> pi50 = sym...
> e50 = sym...
> piovere = vpa(pi50/e50, 50)
> % expected output (reflecting the set value of digits =
50)
> piovere =
> 1.1557273497909217179100931833126962991208510231644
> % actual output (is equivalent to digits = 32, which is
the default)
> piovere =
> 1.1557273497909217179100931833127

...because:

     vpa(pi50/e50,50)
% uses a sym result (pi50/e50) with DIGITS-precision...
% and the subsequent request of 50 digits
% cannot be satisfied...

% hence
     digits(100); % -or- >=50
     r=vpa(sym(pi50/e50),50)
% r = 1.1557273497909217179100931833126962991208510231644

us

Subject: done in by a dim Sym

From: us

Date: 27 May, 2008 13:52:01

Message: 3 of 4

"us ":
<SNIP down to superfluous syntax...

> r=vpa(sym(pi50/e50),50)

should read

     digits(100); % -or- >=50
     r=vpa(pi50/e50,50)
% r = 1.1557273497909217179100931833126962991208510231644

us

Subject: done in by a dim Sym

From: ross

Date: 27 May, 2008 14:06:26

Message: 4 of 4

"us " <us@neurol.unizh.ch> wrote:

> digits(100); % -or- >=50

I've just realised that the condition above is not necessary.
It works fine with digits(50):
that fault was that I had written digits = 50
instead of digits(50).

ross

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
digits us 27 May, 2008 09:45:09
code us 27 May, 2008 09:45:09
sym us 27 May, 2008 09:45:09
vpa us 27 May, 2008 09:45:09
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com