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:
vpa problem

Subject: vpa problem

From: naser

Date: 13 Jul, 2013 18:10:14

Message: 1 of 4

I insert a digit with vpa but it change my digit.
would you please hell me?

M=vpa(35.8662055159741179382109929234224820007262821451277998997729505792583139905076116515672679044047373935846813781752042552572372120168236917923706360824,150)

 
M =
 
35.8662055159741157694952562451362609863281250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

?
 
 

Subject: vpa problem

From: Nasser M. Abbasi

Date: 13 Jul, 2013 19:29:38

Message: 2 of 4

On 7/13/2013 1:10 PM, naser wrote:
> I insert a digit with vpa but it change my digit.
> would you please hell me?
>
> M=vpa(35.866205515974117938210992923422482000726282145127799899772950579258313990507611651567267904404
>7373935846813781752042552572372120168236917923706360824,150)
>
>
> M =
>
> 35.866205515974115769495256245136260986328125000000000000000000000000000000000000000000000000000
>0000000000000000000000000000000000000000000000000000000
>
> ?
>

On Matlab 2013a I get this btw (the zeros are not shown)

M =
35.866205515974115769495256245136260986328125
  

But if you step in vpa, you'll see your input became

K>> format long
   35.866205515974116

Then it became sym as
157741240036069/4398046511104

then

vpa(157741240036069/4398046511104,105)
35.866205515974115769495256245136260986328125


This is becuase you used double as input. Try to wrap it by sym, like this:

M=vpa('35.8662055159741179382109929234224820007262821451277998997729505792
583139905076116515672679044047373935846813781752042552572372120168236917923706360824',150)

I am not exctly sure what you are trying to do. There is no computation in what you are
doing.

--Nasser

Subject: vpa problem

From: Nasser M. Abbasi

Date: 13 Jul, 2013 19:45:51

Message: 3 of 4

On 7/13/2013 2:29 PM, Nasser M. Abbasi wrote:

> This is becuase you used double as input. Try to wrap it by sym, like this:

opps, meant try to wrap it by char.

>
> M=vpa('35.8662055159741179382109929234224820007262821451277998997729505792
> 583139905076116515672679044047373935846813781752042552572372120168236917923706360824',150)
>

ps. You can find logic of vpa from the vpa.m file by typing it.

Subject: vpa problem

From: Steven_Lord

Date: 15 Jul, 2013 15:23:34

Message: 4 of 4



"naser " <naser.sepehry@gmail.com> wrote in message
news:krs566$kqg$1@newscl01ah.mathworks.com...
> I insert a digit with vpa but it change my digit.
> would you please hell me?
>
> M=vpa(35.8662055159741179382109929234224820007262821451277998997729505792583139905076116515672679044047373935846813781752042552572372120168236917923706360824,150)

The input to VPA is interpreted as a double precision value before it gets
into VPA. Therefore by the time VPA can operate on it, you've already lost
precision. In order to avoid this, the input to VPA needs to be either a
string or a symbolic object -- and that symbolic object has to be
constructed in such a way that it doesn't suffer the same problem.

M = vpa(sym(2)^(1/3), 150)

Note that I converted 2 into a symbolic value THEN I computed its cube root
symbolically and printed 150 digits using VPA. Compare this which performs
the cube root in double precision THEN converts that value into a symbolic
expression.

M2 = vpa(sym(2^(1/3)), 150)

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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