Variable-precision arithmetic (arbitrary-precision arithmetic) - MATLAB vpa (2024)

Variable-precision arithmetic (arbitrary-precision arithmetic)

collapse all in page

Syntax

xVpa = vpa(x)

xVpa = vpa(x,d)

Description

example

xVpa = vpa(x) uses variable-precision arithmetic (arbitrary-precision floating-point numbers) to evaluate each element of the symbolic input x to at least d significant digits, where d is the value of the digits function. The default value of digits is 32.

example

xVpa = vpa(x,d) uses at least d significant digits instead of the value of digits.

Examples

collapse all

Evaluate Symbolic Inputs with Variable-Precision Arithmetic

Open Live Script

Evaluate symbolic inputs with variable-precision floating-point arithmetic. By default, vpa calculates values to 32 significant digits.

p = sym(pi);pVpa = vpa(p)
pVpa =3.1415926535897932384626433832795
syms xa = sym(1/3);f = a*sin(2*p*x);fVpa = vpa(f)
fVpa =0.33333333333333333333333333333333sin(6.283185307179586476925286766559x)

Evaluate elements of vectors or matrices with variable-precision arithmetic.

V = [x/p a^3];VVpa = vpa(V)
VVpa =(0.31830988618379067153776752674503x0.037037037037037037037037037037037)
M = [sin(p) cos(p/5); exp(p*x) x/log(p)];MVpa = vpa(M)
MVpa =

(00.80901699437494742410229341718282e3.1415926535897932384626433832795x0.87356852683023186835397746476334x)

Change Precision Used by vpa

Open Live Script

By default, vpa evaluates inputs to 32 significant digits. You can change the number of significant digits by using the digits function.

Approximate the expression 100001/10001 with seven significant digits using digits. Save the old value of digits returned by digits(7). The vpa function returns only five significant digits, which can mean the remaining digits are zeros.

digitsOld = digits(7);y = sym(100001)/10001;yVpa = vpa(y)
yVpa =9.9991

Check if the remaining digits are zeros by using a higher precision value of 25. The result shows that the remaining digits are in fact zeros that are part of a repeating decimal.

digits(25)yVpa = vpa(y)
yVpa =9.999100089991000899910009

Alternatively, to override digits for a single vpa call, change the precision by specifying the second argument.

Find π to 100 significant digits by specifying the second argument.

pVpa =3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068

Restore the original precision value in digitsOld for further calculations.

digits(digitsOld)

Numerically Approximate Symbolic Results

Open Live Script

While symbolic results are exact, they might not be in a convenient form. You can use vpa to numerically approximate exact symbolic results.

Solve a high-degree polynomial for its roots using solve. The solve function cannot symbolically solve the high-degree polynomial and represents the roots using root.

syms xy = solve(x^4 - x + 1, x)
y =

(root(z4-z+1,z,1)root(z4-z+1,z,2)root(z4-z+1,z,3)root(z4-z+1,z,4))

Use vpa to numerically approximate the roots.

yVpa = vpa(y)
yVpa =

(0.72713608449119683997667565867496-0.43001428832971577641651985839602i0.72713608449119683997667565867496+0.43001428832971577641651985839602i-0.72713608449119683997667565867496-0.93409928946052943963903028710582i-0.72713608449119683997667565867496+0.93409928946052943963903028710582i)

vpa Uses Guard Digits to Maintain Precision

Open Live Script

The value of the digits function specifies the minimum number of significant digits used. Internally, vpa can use more digits than digits specifies. These additional digits are called guard digits because they guard against round-off errors in subsequent calculations.

Numerically approximate 1/3 using four significant digits.

a = vpa(1/3,4)
a =0.3333

Approximate the result a using 20 digits. The result shows that the toolbox internally used more than four digits when computing a. The last digits in the result are incorrect because of the round-off error.

aVpa = vpa(a,20)
aVpa =0.33333333333303016843

Avoid Hidden Round-Off Errors

Open Live Script

Hidden round-off errors can cause unexpected results.

Evaluate 1/10 with the default 32-digit precision and then with the 10-digit precision.

a = vpa(1/10,32)
a =0.1
b = vpa(1/10,10)
b =0.1

Superficially, a and b look equal. Check their equality by finding a - b.

roundoff = a - b
roundoff =0.000000000000000000086736173798840354720600815844403

The difference is not equal to zero because b was calculated with only 10 digits of precision and contains a larger round-off error than a. When you find a - b, vpa approximates b with 32 digits. Demonstrate this behavior.

roundoff = a - vpa(b,32)
roundoff =0.000000000000000000086736173798840354720600815844403

vpa Restores Precision of Common Double-Precision Inputs

Open Live Script

Unlike exact symbolic values, double-precision values inherently contain round-off errors. When you call vpa on a double-precision input, vpa cannot restore the lost precision, even though it returns more digits than the double-precision value. However, vpa can recognize and restore the precision of expressions of the form pq, pπq, (pq)12, 2q, and 10q, where p and q are modest-sized integers.

First, demonstrate that vpa cannot restore precision for a double-precision input. Call vpa on a double-precision result and the same symbolic result.

dp = log(3);s = log(sym(3));dpVpa = vpa(dp)
dpVpa =1.0986122886681095600636126619065
sVpa = vpa(s)
sVpa =1.0986122886681096913952452369225
d = sVpa - dpVpa
d =0.00000000000000013133163257501600766255995767652

As expected, the double-precision result differs from the exact result at the 16th decimal place.

Demonstrate that vpa restores precision for expressions of the form pq, pπq, (pq)12, 2q, and 10q, where p and q are modest-sized integers, by finding the difference between the vpa call on the double-precision result and on the exact symbolic result. The differences are 0.0 showing that vpa restores lost precision for the double-precision input.

d = vpa(1/3) - vpa(1/sym(3))
d =0.0
d = vpa(pi) - vpa(sym(pi))
d =0.0
d = vpa(1/sqrt(2)) - vpa(1/sqrt(sym(2)))
d =0.0
d = vpa(2^66) - vpa(2^sym(66))
d =0.0
d = vpa(10^25) - vpa(10^sym(25))
d =0.0

Evaluate Symbolic Matrix Variable with Variable-Precision Arithmetic

Since R2022b

Open Live Script

Create a symbolic expression S that represents sin([ππ2π2π3]X), where X is a 2-by-1 symbolic matrix variable.

syms X [2 1] matrixS = sin(hilb(2)*pi*X)
S =

sin(Σ1X)whereΣ1=(ππ2π2π3)

Evaluate the expression with variable-precision arithmetic.

SVpa = vpa(S)
SVpa =

(sin(3.1415926535897932384626433832795X1+1.5707963267948966192313216916398X2)sin(1.5707963267948966192313216916398X1+1.0471975511965977461542144610932X2))

Input Arguments

collapse all

xInput to evaluate
number | vector | matrix | multidimensional array | symbolic number | symbolic vector | symbolic matrix | symbolic multidimensional array | symbolic expression | symbolic function | symbolic character vector | symbolic matrix variable

Input to evaluate, specified as a number, vector, matrix, multidimensional array, or a symbolic number, vector, matrix, multidimensional array, expression, function, character vector, or matrix variable.

dNumber of significant digits
positive integer scalar

Number of significant digits, specified as a positive integer scalar. d must be greater than 1 and less than 229+1.

Output Arguments

collapse all

xVpa — Variable-precision output
symbolic number | symbolic vector | symbolic matrix | symbolic multidimensional array | symbolic expression | symbolic function

Variable-precision output, returned as a symbolic number, vector, matrix, multidimensional array, expression, or function.

  • For almost all input data types (such as sym, symmatrix, double, single, int64, and so on), vpa returns the output as data type sym.

  • If the input is a symbolic function of type symfun, then vpa returns the output as data type symfun. For example, syms f(x); f(x) = pi*x; g = vpa(f) returns the output g as type symfun.

  • If the input is an evaluated symbolic function of type sym, such as g = vpa(f(x)), then vpa returns the output as data type sym.

Tips

  • vpa does not convert fractionsin the exponent to floating point. For example, vpa(a^sym(2/5)) returns a^(2/5).

  • vpa uses more digits than thenumber of digits specified by digits. These extradigits guard against round-off errors in subsequent calculations andare called guard digits.

  • When you call vpa on a numericinput, such as 1/3, 2^(-5),or sin(pi/4), the numeric expression is evaluatedto a double-precision number that contains round-off errors. Then, vpa iscalled on that double-precision number. For accurate results, convertnumeric expressions to symbolic expressions with sym.For example, to approximate exp(1), use vpa(exp(sym(1))).

  • If the second argument d is notan integer, vpa rounds it to the nearest integerwith round.

  • vpa restores precision for numericinputs that match the forms p/q, pπ/q, (p/q)1/2, 2q,and 10q,where p and q are modest-sizedintegers.

  • Variable-precision arithmetic is different from IEEE® Floating-Point Standard 754 in these ways:

    • Inside computations, division by zero throws an error.

    • The exponent range is larger than in any predefined IEEE mode. vpa underflows below approximately 10^(-323228496).

    • Denormalized numbers are not implemented.

    • Zeros are not signed.

    • The number of binary digits in the mantissa of a result may differ between variable-precision arithmetic and IEEE predefined types.

    • There is only one NaN representation. No distinction is made between quiet and signaling NaN.

    • No floating-point number exceptions are available.

Version History

Introduced before R2006a

expand all

You can evaluate a symbolic matrix variable of type symmatrix with variable-precision arithmetic. The result is a symbolic expression with variable-precision numbers and scalar variables of type sym. For an example, see Evaluate Symbolic Matrix Variable with Variable-Precision Arithmetic.

Support for character vectors that do not define a number has been removed. Instead, first create symbolic numbers and variables using sym and syms, and then use operations on them. For example, use vpa((1 + sqrt(sym(5)))/2) instead of vpa('(1 + sqrt(5))/2').

See Also

digits | double | root | vpaintegral

Topics

  • Increase Precision of Numeric Calculations
  • Recognize and Avoid Round-Off Errors
  • Increase Speed by Reducing Precision
  • Choose Numeric or Symbolic Arithmetic
  • Change Output Format of Symbolic and Variable-Precision Arithmetic

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Variable-precision arithmetic (arbitrary-precision arithmetic) - MATLAB vpa (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Variable-precision arithmetic (arbitrary-precision arithmetic) - MATLAB vpa (2024)

FAQs

Variable-precision arithmetic (arbitrary-precision arithmetic) - MATLAB vpa? ›

Description. xVpa = vpa( x ) uses variable-precision arithmetic (arbitrary-precision floating-point numbers) to evaluate each element of the symbolic input x to at least d significant digits, where d is the value of the digits function. The default value of digits is 32.

What is the precision of VPA in MATLAB? ›

The default precision for vpa is 32 digits. Increase precision beyond 32 digits by using digits . Find pi using vpa , which uses the default 32 digits of precision. Confirm that the current precision is 32 by using digits .

What does vpa stand for in MATLAB? ›

Matlab variable precision arithmetic is used in calculations where large numbers are involved (as input or output), and the primary focus is on precision and not the speed of computation.

How many decimals are in MATLAB VPA? ›

By default, MATLAB® uses 16 digits of precision. For higher precision, use the vpa function in Symbolic Math Toolbox™. vpa provides variable precision which can be increased without limit. When you choose variable-precision arithmetic, by default, vpa uses 32 significant decimal digits of precision.

What is the VPA symbolic toolbox? ›

vpa (Symbolic Math Toolbox) Variable precision arithmetic. vpa(A) uses variable-precision arithmetic (VPA) to compute each element of A to d decimal digits of accuracy, where d is the current setting of digits . Each element of the result is a symbolic expression.

What is an example of a VPA? ›

So instead of sharing your bank account details, you can simply share your VPA or UPI ID with others to initiate transactions. For example, your VPA could be something like “yourname@bankname (rohit123@paytm)” or the most common one “yourphonenumber@bankname (9989889898@paytm)”.

What is the precision of Vpasolve in MATLAB? ›

By default, vpasolve returns solutions to a precision of 32 significant figures. Use digits to increase the precision to 64 significant figures.

What is vpa solve in MATLAB? ›

Description. S = vpasolve( eqn , var ) numerically solves the equation eqn for the variable var . If you do not specify var , vpasolve solves for the default variable determined by symvar . For example, vpasolve(x + 1 == 2, x) numerically solves the equation x + 1 = 2 for x.

What is the precision of MATLAB? ›

MATLAB® has data types for double-precision ( double ) and single-precision ( single ) floating-point numbers following IEEE® Standard 754. By default, MATLAB represents floating-point numbers in double precision.

What does VPA stand for? ›

What is VPA in UPI? The full form of VPA is Virtual Payment Address (VPA). VPA is a digital ID that lets you receive and send funds conveniently through UPI-enabled apps. VPA eliminates the need to enter details like bank account number, branch name, IFSC code separately while conducting a transaction.

How do you define decimals in MATLAB? ›

Select MATLAB > Command Window, and then choose a Numeric format option. The following table summarizes the numeric output format options. Short, fixed-decimal format with 4 digits after the decimal point.

How to use double-precision in MATLAB? ›

d = double( s ) converts the symbolic values s to double precision. Converting symbolic values to double precision is useful when a MATLAB® function does not accept symbolic values. For differences between symbolic and double-precision numbers, see Choose Numeric or Symbolic Arithmetic.

How do you limit decimals in MATLAB? ›

For display purposes, use sprintf to control the exact display of a number as a string. For example, to display exactly 2 decimal digits of pi (and no trailing zeros), use sprintf("%. 2f",pi) .

How does vpa work in MATLAB? ›

vpa Uses Guard Digits to Maintain Precision

The value of the digits function specifies the minimum number of significant digits used. Internally, vpa can use more digits than digits specifies. These additional digits are called guard digits because they guard against round-off errors in subsequent calculations.

What is the VPA code? ›

It is a unique address that you can use to make payments instantly. You can use it to send money via UPI apps or real-time modes of transactions. In fact, VPA numbers are used to create a digital bank account or a virtual bank account.

What is VPA in machine learning? ›

Virtual personal assistants (VPAs) are computer programme created to organically interact with humans to respond to questions, carry on discussions, and carry out different tasks. The two sorts of inputs that a VPA normally accepts are voice input (like Apple Siri) and text input (Google Assistant).

What is the precision of octave floating point? ›

All built-in floating point numeric data is currently stored as double precision numbers. On systems that use the IEEE floating point format, values in the range of approximately 2.2251e-308 to 1.7977e+308 can be stored, and the relative precision is approximately 2.2204e-16.

What is the precision of floating point scale? ›

The value that can be represented by a single precision floating point number is approximately 6 or 7 decimal digits of precision. A double precision, floating-point number is a 64-bit approximation of a real number.

What is the accuracy of floating point precision? ›

This is a binary format that occupies 32 bits (4 bytes) and its significand has a precision of 24 bits (about 7 decimal digits).

What is the precision of float type variable? ›

A variable of type float only has 7 digits of precision whereas a variable of type double has 15 digits of precision. If you need better accuracy, use double instead of float.

Top Articles
Deutsche Telekom wächst stetig weiter und hebt Jahresprognose für den Free Cashflow AL an
Deutschland - Deutsche Telekom Zwischenbericht H1 2024
This website is unavailable in your location. – WSB-TV Channel 2 - Atlanta
Toa Guide Osrs
Katie Pavlich Bikini Photos
Edina Omni Portal
Mcgeorge Academic Calendar
What happened to Lori Petty? What is she doing today? Wiki
DEA closing 2 offices in China even as the agency struggles to stem flow of fentanyl chemicals
Activities and Experiments to Explore Photosynthesis in the Classroom - Project Learning Tree
Dee Dee Blanchard Crime Scene Photos
Roblox Developers’ Journal
Tap Tap Run Coupon Codes
Moviesda Dubbed Tamil Movies
Directions To Lubbock
Palace Pizza Joplin
Does Publix Have Sephora Gift Cards
Voyeuragency
Keniakoop
Industry Talk: Im Gespräch mit den Machern von Magicseaweed
Costco Gas Foster City
Wal-Mart 140 Supercenter Products
1-833-955-4522
Ecampus Scps Login
Pawn Shop Moline Il
Masterbuilt Gravity Fan Not Working
Kiddie Jungle Parma
What Happened To Father Anthony Mary Ewtn
Exploring TrippleThePotatoes: A Popular Game - Unblocked Hub
Uhaul Park Merced
Chris Provost Daughter Addie
Space Marine 2 Error Code 4: Connection Lost [Solved]
Hannibal Mo Craigslist Pets
Tokyo Spa Memphis Reviews
Hindilinks4U Bollywood Action Movies
Trivago Myrtle Beach Hotels
Insideaveritt/Myportal
Check From Po Box 1111 Charlotte Nc 28201
Discover Wisconsin Season 16
Citibank Branch Locations In North Carolina
Penny Paws San Antonio Photos
Ehc Workspace Login
Sea Guini Dress Code
9294027542
Verizon Forum Gac Family
Muni Metro Schedule
Phunextra
F9 2385
99 Fishing Guide
2121 Gateway Point
Worlds Hardest Game Tyrone
E. 81 St. Deli Menu
Latest Posts
Article information

Author: Carlyn Walter

Last Updated:

Views: 5885

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Carlyn Walter

Birthday: 1996-01-03

Address: Suite 452 40815 Denyse Extensions, Sengermouth, OR 42374

Phone: +8501809515404

Job: Manufacturing Technician

Hobby: Table tennis, Archery, Vacation, Metal detecting, Yo-yoing, Crocheting, Creative writing

Introduction: My name is Carlyn Walter, I am a lively, glamorous, healthy, clean, powerful, calm, combative person who loves writing and wants to share my knowledge and understanding with you.