http://www.mathworks.com/matlabcentral/newsreader/view_thread/279763
MATLAB Central Newsreader  vpa help with matrices
Feed for thread: vpa help with matrices
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Sun, 18 Apr 2010 16:06:05 +0000
vpa help with matrices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/279763#737167
ben payne
I have a Fortran 90 program in which I perform many matrix multiplications. I would like to find a product with a userdefined precision. To do this, I am using vpa(). I cannot use sym() due to memory constraints of the program. The problem I have is in how to use vpa() correctly. For example, suppose I want to perform the following multiplication, accurate to 100 decimal places:<br>
<br>
x=[sqrt(2) sqrt(3); sqrt(5) sqrt(6)] <br>
y=[sqrt(7); sqrt(8)]<br>
z=[sqrt(14)+sqrt(24); sqrt(35)+sqrt(48)]<br>
a=x*yz<br>
<br>
Without vpa() used in determining x,y,z, then I get<br>
<br>
>> vpa(a,100)<br>
ans =<br>
0.0000000000000017763568394002504646778106689453125<br>
0<br>
<br>
I want to be able to specify the precision of the answer for a, but the following does not do what I want:<br>
<br>
x=vpa([sqrt(2) sqrt(3); sqrt(5) sqrt(6)],100)<br>
y=vpa([sqrt(7); sqrt(8)],100) <br>
z=vpa([sqrt(14)+sqrt(24); sqrt(35)+sqrt(48)],100)<br>
a=vpa(x*yz,100) <br>
<br>
Nor does this work:<br>
<br>
a=vpa(vpa(x,100)*vpa(y,100)vpa(z,100),100)<br>
<br>
Please let me know if further clarification is needed.<br>
<br>
Thanks in advance.

Sun, 18 Apr 2010 17:13:05 +0000
Re: vpa help with matrices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/279763#737174
Roger Stafford
"ben payne" <ben.is.located@gmail.com> wrote in message <hqfald$g20$1@fred.mathworks.com>...<br>
> I have a Fortran 90 program in which I perform many matrix multiplications. I would like to find a product with a userdefined precision. To do this, I am using vpa(). I cannot use sym() due to memory constraints of the program. The problem I have is in how to use vpa() correctly. For example, suppose I want to perform the following multiplication, accurate to 100 decimal places:<br>
> .......<br>
<br>
The 'vpa' function merely converts a symbolic expression into a decimal string with the accuracy of the 'digits' or 'vpa' setting. When you write<br>
<br>
vpa(sqrt(2),100) ,<br>
<br>
unless '2' is of 'sym' form, all you get is the sixteenplace accuracy of double precision floating point for the square root but then converted to the 100 decimals in the vpa setting. That does you no good. You cannot avoid the use of 'sym' if you want more accuracy than that of the ordinary double precision floating point.<br>
<br>
Roger Stafford

Sun, 18 Apr 2010 17:42:04 +0000
Re: vpa help with matrices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/279763#737188
ben payne
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hqfej0$fj4$1@fred.mathworks.com>...<br>
> "ben payne" <ben.is.located@gmail.com> wrote in message <hqfald$g20$1@fred.mathworks.com>...<br>
> > I have a Fortran 90 program in which I perform many matrix multiplications. I would like to find a product with a userdefined precision. To do this, I am using vpa(). I cannot use sym() due to memory constraints of the program. The problem I have is in how to use vpa() correctly. For example, suppose I want to perform the following multiplication, accurate to 100 decimal places:<br>
> > .......<br>
> <br>
> The 'vpa' function merely converts a symbolic expression into a decimal string with the accuracy of the 'digits' or 'vpa' setting. When you write<br>
> <br>
> vpa(sqrt(2),100) ,<br>
> <br>
> unless '2' is of 'sym' form, all you get is the sixteenplace accuracy of double precision floating point for the square root but then converted to the 100 decimals in the vpa setting. That does you no good. You cannot avoid the use of 'sym' if you want more accuracy than that of the ordinary double precision floating point.<br>
> <br>
> Roger Stafford<br>
<br>
Hello. I am somewhat confused as to how useful vpa is if it only displays output from symbolic computation. For example, if I want to perform a numeric calculation to better than double or quad precision, it sounds like matlab is unable to do that?<br>
<br>
I am asking basically the same question as on<br>
<a href="http://www.mathworks.com/support/solutions/en/data/11AGHW/index.html?product=SM&solution=11AGHW">http://www.mathworks.com/support/solutions/en/data/11AGHW/index.html?product=SM&solution=11AGHW</a><br>
but they don't answer my question there. Namely, if I have two variables known to 100 decimal places, can I perform operations with those variables and retain precision?<br>
<br>
Unlike thread 151496, I don't need the fastest library. The original program is written in Fortran 90, and I have used quadruple precision for that. However, quadruple precision is insufficient.<br>
<br>
Do I need to be using something like the following?<br>
<a href="http://www.mathworks.com/matlabcentral/fileexchange/6446">http://www.mathworks.com/matlabcentral/fileexchange/6446</a><br>
I assumed matlab would be able to perform vpa arithmetic.

Sun, 18 Apr 2010 18:32:07 +0000
Re: vpa help with matrices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/279763#737192
Roger Stafford
"ben payne" <ben.is.located@gmail.com> wrote in message <hqfg9c$bii$1@fred.mathworks.com>...<br>
> Hello. I am somewhat confused as to how useful vpa is if it only displays output from symbolic computation. For example, if I want to perform a numeric calculation to better than double or quad precision, it sounds like matlab is unable to do that?<br>
> <br>
> I am asking basically the same question as on<br>
> <a href="http://www.mathworks.com/support/solutions/en/data/11AGHW/index.html?product=SM&solution=11AGHW">http://www.mathworks.com/support/solutions/en/data/11AGHW/index.html?product=SM&solution=11AGHW</a><br>
> but they don't answer my question there. Namely, if I have two variables known to 100 decimal places, can I perform operations with those variables and retain precision?<br>
> <br>
> Unlike thread 151496, I don't need the fastest library. The original program is written in Fortran 90, and I have used quadruple precision for that. However, quadruple precision is insufficient.<br>
> <br>
> Do I need to be using something like the following?<br>
> <a href="http://www.mathworks.com/matlabcentral/fileexchange/6446">http://www.mathworks.com/matlabcentral/fileexchange/6446</a><br>
> I assumed matlab would be able to perform vpa arithmetic.<br>
<br>
On my system if I type<br>
<br>
x = vpa('sqrt(2)',100)<br>
<br>
I get the square root of two out to a hundred decimal places of accuracy, but if I merely type<br>
<br>
y = vpa(sqrt(2),100)<br>
<br>
I get a hundred decimal places but it is accurate only out to the sixteenth place.<br>
<br>
The difference is that I have convinced 'vpa' to regard the first expression as being of type 'sym', but the second is only regarded as of type 'double'. There is a world of difference between the two entities.<br>
<br>
To obtain 100place accuracy in general computations you will need a system that is capable of handling type 'sym'. When you say, "I have two variables known to 100 decimal places" you cannot be talking about a variable represented as a 64bit double precision floating point number. It can't be done with such a limited object. It has to be in another form with far greater capacity, a form which the symbolic toolbox can use, which is to say a type 'sym'. As you are probably aware, matlab's symbolic toolbox accomplishes this with strings of characters or strings of decimal digits of variable lengths depending on the required accuracy.<br>
<br>
Roger Stafford

Sun, 18 Apr 2010 19:05:10 +0000
Re: vpa help with matrices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/279763#737204
ben payne
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hqfj77$p87$1@fred.mathworks.com>...<br>
> "ben payne" <ben.is.located@gmail.com> wrote in message <hqfg9c$bii$1@fred.mathworks.com>...<br>
> > Hello. I am somewhat confused as to how useful vpa is if it only displays output from symbolic computation. For example, if I want to perform a numeric calculation to better than double or quad precision, it sounds like matlab is unable to do that?<br>
> > <br>
> > I am asking basically the same question as on<br>
> > <a href="http://www.mathworks.com/support/solutions/en/data/11AGHW/index.html?product=SM&solution=11AGHW">http://www.mathworks.com/support/solutions/en/data/11AGHW/index.html?product=SM&solution=11AGHW</a><br>
> > but they don't answer my question there. Namely, if I have two variables known to 100 decimal places, can I perform operations with those variables and retain precision?<br>
> > <br>
> > Unlike thread 151496, I don't need the fastest library. The original program is written in Fortran 90, and I have used quadruple precision for that. However, quadruple precision is insufficient.<br>
> > <br>
> > Do I need to be using something like the following?<br>
> > <a href="http://www.mathworks.com/matlabcentral/fileexchange/6446">http://www.mathworks.com/matlabcentral/fileexchange/6446</a><br>
> > I assumed matlab would be able to perform vpa arithmetic.<br>
> <br>
> On my system if I type<br>
> <br>
> x = vpa('sqrt(2)',100)<br>
> <br>
> I get the square root of two out to a hundred decimal places of accuracy, but if I merely type<br>
> <br>
> y = vpa(sqrt(2),100)<br>
> <br>
> I get a hundred decimal places but it is accurate only out to the sixteenth place.<br>
> <br>
> The difference is that I have convinced 'vpa' to regard the first expression as being of type 'sym', but the second is only regarded as of type 'double'. There is a world of difference between the two entities.<br>
> <br>
> To obtain 100place accuracy in general computations you will need a system that is capable of handling type 'sym'. When you say, "I have two variables known to 100 decimal places" you cannot be talking about a variable represented as a 64bit double precision floating point number. It can't be done with such a limited object. It has to be in another form with far greater capacity, a form which the symbolic toolbox can use, which is to say a type 'sym'. As you are probably aware, matlab's symbolic toolbox accomplishes this with strings of characters or strings of decimal digits of variable lengths depending on the required accuracy.<br>
> <br>
> Roger Stafford<br>
<br>
Thanks for your help Roger. I will implement the program in Mathematica<br>
<a href="http://reference.wolfram.com/mathematica/tutorial/ArbitraryPrecisionNumbers.html">http://reference.wolfram.com/mathematica/tutorial/ArbitraryPrecisionNumbers.html</a>

Mon, 19 Apr 2010 15:50:23 +0000
Re: vpa help with matrices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/279763#737442
Steven Lord
<br>
"ben payne" <ben.is.located@gmail.com> wrote in message <br>
news:hqfg9c$bii$1@fred.mathworks.com...<br>
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in <br>
> message <hqfej0$fj4$1@fred.mathworks.com>...<br>
>> "ben payne" <ben.is.located@gmail.com> wrote in message <br>
>> <hqfald$g20$1@fred.mathworks.com>...<br>
>> > I have a Fortran 90 program in which I perform many matrix <br>
>> > multiplications. I would like to find a product with a userdefined <br>
>> > precision. To do this, I am using vpa(). I cannot use sym() due to <br>
>> > memory constraints of the program. The problem I have is in how to use <br>
>> > vpa() correctly. For example, suppose I want to perform the following <br>
>> > multiplication, accurate to 100 decimal places:<br>
>> > .......<br>
>><br>
>> The 'vpa' function merely converts a symbolic expression into a decimal <br>
>> string with the accuracy of the 'digits' or 'vpa' setting. When you <br>
>> write<br>
>><br>
>> vpa(sqrt(2),100) ,<br>
>><br>
>> unless '2' is of 'sym' form, all you get is the sixteenplace accuracy of <br>
>> double precision floating point for the square root but then converted to <br>
>> the 100 decimals in the vpa setting. That does you no good. You cannot <br>
>> avoid the use of 'sym' if you want more accuracy than that of the <br>
>> ordinary double precision floating point.<br>
>><br>
>> Roger Stafford<br>
><br>
> Hello. I am somewhat confused as to how useful vpa is if it only displays <br>
> output from symbolic computation. For example, if I want to perform a <br>
> numeric calculation to better than double or quad precision, it sounds <br>
> like matlab is unable to do that?<br>
<br>
To perform a calculation to greater than double precision, use the <br>
arbitraryprecision arithmetic in Symbolic Math Toolbox.<br>
<br>
two = sym(2);<br>
squareRootOfTwo = sqrt(two)<br>
vpa(squareRootOfTwo, 100) % Display it to 100 decimal places.<br>
<br>
> I am asking basically the same question as on<br>
> <a href="http://www.mathworks.com/support/solutions/en/data/11AGHW/index.html?product=SM&solution=11AGHW">http://www.mathworks.com/support/solutions/en/data/11AGHW/index.html?product=SM&solution=11AGHW</a><br>
> but they don't answer my question there. Namely, if I have two variables <br>
> known to 100 decimal places, can I perform operations with those variables <br>
> and retain precision?<br>
<br>
So you type the following into MATLAB:<br>
<br>
x = 1.234567890123456789012345678901234567890123456789012345678901234567890<br>
<br>
If you do that, MATLAB will evaluate that expression _in double precision_ <br>
and store the result in the _double precision_ variable x.<br>
<br>
> Unlike thread 151496, I don't need the fastest library. The original <br>
> program is written in Fortran 90, and I have used quadruple precision for <br>
> that. However, quadruple precision is insufficient.<br>
><br>
> Do I need to be using something like the following?<br>
> <a href="http://www.mathworks.com/matlabcentral/fileexchange/6446">http://www.mathworks.com/matlabcentral/fileexchange/6446</a><br>
> I assumed matlab would be able to perform vpa arithmetic.<br>
<br>
See above.<br>
<br>
 <br>
Steve Lord<br>
slord@mathworks.com<br>
comp.softsys.matlab (CSSM) FAQ: <a href="http://matlabwiki.mathworks.com/MATLAB_FAQ">http://matlabwiki.mathworks.com/MATLAB_FAQ</a>

Tue, 20 Apr 2010 02:10:44 +0000
Re: vpa help with matrices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/279763#737572
benbarrowes
On Apr 18, 3:05 pm, "ben payne" <ben.is.loca...@gmail.com> wrote:<br>
> "Roger Stafford" <ellieandrogerxy...@mindspring.com.invalid> wrote in message <hqfj77$p8...@fred.mathworks.com>...<br>
> > "ben payne" <ben.is.loca...@gmail.com> wrote in message <hqfg9c$bi...@fred.mathworks.com>...<br>
> > > Hello. I am somewhat confused as to how useful vpa is if it only displays output from symbolic computation. For example, if I want to perform a numeric calculation to better than double or quad precision, it sounds like matlab is unable to do that?<br>
><br>
> > > I am asking basically the same question as on<br>
> > ><a href="http://www.mathworks.com/support/solutions/en/data/11AGHW/index.html">http://www.mathworks.com/support/solutions/en/data/11AGHW/index.html</a>...<br>
> > > but they don't answer my question there. Namely, if I have two variables known to 100 decimal places, can I perform operations with those variables and retain precision?<br>
><br>
> > > Unlike thread 151496, I don't need the fastest library. The original program is written in Fortran 90, and I have used quadruple precision for that. However, quadruple precision is insufficient.<br>
><br>
> > > Do I need to be using something like the following?<br>
> > ><a href="http://www.mathworks.com/matlabcentral/fileexchange/6446">http://www.mathworks.com/matlabcentral/fileexchange/6446</a><br>
> > > I assumed matlab would be able to perform vpa arithmetic.<br>
><br>
> > On my system if I type<br>
><br>
> > x = vpa('sqrt(2)',100)<br>
><br>
> > I get the square root of two out to a hundred decimal places of accuracy, but if I merely type<br>
><br>
> > y = vpa(sqrt(2),100)<br>
><br>
> > I get a hundred decimal places but it is accurate only out to the sixteenth place.<br>
><br>
> > The difference is that I have convinced 'vpa' to regard the first expression as being of type 'sym', but the second is only regarded as of type 'double'. There is a world of difference between the two entities.<br>
><br>
> > To obtain 100place accuracy in general computations you will need a system that is capable of handling type 'sym'. When you say, "I have two variables known to 100 decimal places" you cannot be talking about a variable represented as a 64bit double precision floating point number. It can't be done with such a limited object. It has to be in another form with far greater capacity, a form which the symbolic toolbox can use, which is to say a type 'sym'. As you are probably aware, matlab's symbolic toolbox accomplishes this with strings of characters or strings of decimal digits of variable lengths depending on the required accuracy.<br>
><br>
> > Roger Stafford<br>
><br>
> Thanks for your help Roger. I will implement the program in Mathematica<a href="http://reference.wolfram.com/mathematica/tutorial/ArbitraryPrecisionN">http://reference.wolfram.com/mathematica/tutorial/ArbitraryPrecisionN</a>...<br>
<br>
You can also use the free multiple precision toolbox in matlab:<br>
<a href="http://www.mathworks.com/matlabcentral/fileexchange/6446multipleprecisiontoolboxformatlab">http://www.mathworks.com/matlabcentral/fileexchange/6446multipleprecisiontoolboxformatlab</a><br>
<br>
Ben Barrowes