Matlab vpa | Quick Glance on Matlab vpa with Examples (2024)

Updated March 6, 2023

Matlab vpa | Quick Glance on Matlab vpa with Examples (1)

Introduction to Matlab vpa

The following article provides an outline for Matlab vpa. 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. The high precision for these long numbers is achieved by algorithms that group these numbers into smaller parts for calculation.

ADVERTIsem*nT Popular Course in this categoryMATLAB - Specialization | 5 Course Series | 3 Mock Tests

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

For example, the mathematical ‘pi’ has more than 31 Trillion digits, but we usually use 3.14 as its value. However, some of our calculations might require more digits to be involved, and this is where vpa (variable precision arithmetic) comes in handy.

Syntax:

vpa (a)

vpa (a, n)

Explanation:

  • The vpa (a) is used to compute the elements of the input ‘a’ till ‘n’ significant digits.
  • By default, the value of significant digits is 32 for the vpa function.

Examples of Matlab vpa

Given below examples shows how to use vpa in Matlab:

Example #1

In this example, we will use vpa to perform a non-terminating division. First, we will compute the result using the normal division in Matlab, and then we will use vpa to understand the utility of vpa clearly.

For this example, we will divide 2 by 3, which will give us a non-terminating output.

Code without using vpa:

A1 = double (2) / double (3)
[Using ‘double’ as the data type to ensure that the decimal part is displayed in the output]

A1
[Displaying the output (without vpa)]

Input:

Matlab vpa | Quick Glance on Matlab vpa with Examples (2)

Output:

Matlab vpa | Quick Glance on Matlab vpa with Examples (3)

Code using vpa:

syms x
[Initializing symbolic input]

InputNumber = sym (2 / 3);
[Declaring the input]

A2 = vpa (InputNumber)
[Displaying the output using vpa]

Input:

Matlab vpa | Quick Glance on Matlab vpa with Examples (4)

Output:

Matlab vpa | Quick Glance on Matlab vpa with Examples (5)

If we compare the 2 outputs above, we will notice that the first one has 4 significant digits, whereas the second one has 32, and thus the second one, which uses vpa, provides more precision.

Example #2

Next, we will use vpa to compute the value of a mathematical expression.

For this example, we will add two non-terminating numbers and will see the difference in precision while using vpa. Here the output will also be a non-terminating number.

Code without using vpa:

Input1 = double (2 / 3)
[Declaring the first input, using ‘double’ as the data type to ensure that the decimal part is displayed in the output]

Input2 = double (pi)
[Declaring the second input]

Input1 + Input2
[Adding the 2 inputs (without using vpa)]

Input:

Matlab vpa | Quick Glance on Matlab vpa with Examples (6)

Output:

Matlab vpa | Quick Glance on Matlab vpa with Examples (7)

Code using vpa:

syms x
[Initializing symbolic input]

Input1 = sym (2 / 3)
[Declaring the first input]

Input2 = sym (pi)
[Declaring the second input]

vpa(Input1) + vpa(Input2)
[Adding the 2 inputs using vpa]

Input:

Matlab vpa | Quick Glance on Matlab vpa with Examples (8)

Output:

Matlab vpa | Quick Glance on Matlab vpa with Examples (9)

As we can see in the two output above, we have obtained 5 significant digits without using the vpa, whereas 32 significant digits while using the vpa, resulting in more precision.

Example #3

Next, we will use vpa to compute the value of a mathematical expression involving square root.

For this example, we will add 2 numbers with non-terminating and non-repeating square roots and will see the difference in precision while using vpa. Here also, the output will be a non-terminating number.

Code without using vpa:

Input1 = sqrt (2)
[Declaring the first input variable and using the sqrt function to compute the square root]

Input2 = sqrt (5)
[Declaring the second input variable and using the sqrt function to compute the square root]

Input1 + Input2
[Adding the 2 inputs (without using vpa)]

Input:

Matlab vpa | Quick Glance on Matlab vpa with Examples (10)

Output:

Matlab vpa | Quick Glance on Matlab vpa with Examples (11)

Code using vpa:

syms x
[Initializing symbolic input]

Input1 = sqrt (2)
[Declaring the first input variable]

Input2 = sqrt (5)
[Declaring the second input variable]

vpa(Input1) + vpa(Input2)
[Adding the 2 inputs using vpa]

Input:

Matlab vpa | Quick Glance on Matlab vpa with Examples (12)

Output:

Matlab vpa | Quick Glance on Matlab vpa with Examples (13)

As we can see in the two outputs obtained above, we have obtained 5 significant digits without using the vpa, whereas 32 significant digits while using the vpa, resulting in more precision.

In the above 3 examples, we got 32 significant digits as the output; however, we can get more or less than 32 digits if required. For this, we will pass the required number of digits as the second argument to the vpa function.

Example #4

In this example, we will learn how to get more than 32 digits, say 50, in the output.

Code:

syms x
[Initializing symbolic input]

A = vpa(sqrt(3), 50)
[Declaring the first input, and using vpa to get 50 significant digits]

B = vpa(3*pi, 50)
[Declaring the second input]

vpa(A + B, 50)
[Adding the 2 inputs using vpa and again passing 50 as the second argument to get 50 significant digits]

Input:

Matlab vpa | Quick Glance on Matlab vpa with Examples (14)

Output:

Matlab vpa | Quick Glance on Matlab vpa with Examples (15)

As we can see in the output, we now have 50 significant digits as expected by us.

Conclusion

The vpa is used in Matlab to increase precision in the output. We can control the number of significant digits in the output using the input argument; by default, this number is 32. Using vpa can affect the performance of a program, as the focus is on precision.

Recommended Articles

This is a guide to Matlab vpa. Here we discuss the introduction and the examples of Matlab vpa for a better understanding. You may also have a look at the following articles to learn more –

  1. What is Matlab?
  2. Matlab limit
  3. Plot graph Matlab
  4. Absolute Value Matlab

ADVERTIsem*nT

SPSS - Specialization | 14 Course Series | 5 Mock Tests 42 of HD Videos 14 Courses Verifiable Certificate of Completion Lifetime Access4.5

ADVERTIsem*nT

MICROSOFT AZURE - Specialization | 15 Course Series | 12 Mock Tests 73 of HD Videos 15 Courses Verifiable Certificate of Completion Lifetime Access4.5

ADVERTIsem*nT

HADOOP - Specialization | 32 Course Series | 4 Mock Tests 170 of HD Videos 32 Courses Verifiable Certificate of Completion Lifetime Access4.5

ADVERTIsem*nT

INFORMATICA - Specialization | 7 Course Series 69 of HD Videos 7 Courses Verifiable Certificate of Completion Lifetime Access4.5
Primary Sidebar

");jQuery('.cal-tbl table').unwrap("

");jQuery("#mobilenav").parent("p").css("margin","0");jQuery("#mobilenav .fa-bars").click(function() {jQuery('.navbar-tog-open-close').toggleClass("leftshift",7000);jQuery("#fix-bar").addClass("showfix-bar");/*jQuery(".content-sidebar-wrap").toggleClass("content-sidebar-wrap-bg");jQuery(".inline-pp-banner").toggleClass("inline-pp-banner-bg");jQuery(".entry-content img").toggleClass("img-op");*/jQuery("#fix-bar").toggle();jQuery(this).toggleClass('fa fa-close fa fa-bars');});jQuery("#mobilenav .fa-close").click(function() {jQuery('.navbar-tog-open-close').toggleClass("leftshift",7000);jQuery("#fix-bar").removeClass("showfix-bar");jQuery("#fix-bar").toggle();jQuery(this).toggleClass('fa fa-bars fa fa-close');/*jQuery(".content-sidebar-wrap").toggleClass("content-sidebar-wrap-bg");jQuery(".inline-pp-banner").toggleClass("inline-pp-banner-bg");jQuery(".entry-content img").toggleClass("img-op");*/});});

Matlab vpa | Quick Glance on Matlab vpa with Examples (2024)

References

Top Articles
Chard, Lentil & Potato Slow Cooker Soup Recipe
Homemade Natural Lip Balm Recipe - Takes Only 5 MINUTES to Make!
Pau.blaz
Smoothie Operator Ruff Ruffman
Tripadvisor London Forum
Markz Blog
Www.citizen-Times.com Obituaries
Discover the Hidden Gems of Greenbush MI: A Charming Lakeside Retreat - 200smichigan.com (UPDATE 👍)
Terry Gebhardt Obituary
Elgin Il Building Department
The Meaning Behind The Song: Waymore's Blues by Waylon Jennings - Beat Crave
Rocky Bfb Asset
عکس کون زنان ایرانی
Laura Houston Wbap
Ice Dodo Unblocked 76
Sugar And Spice Playboy Magazine
Edenmodelsva
Kira Kener 2022
Idaho Falls Temple Prayer Roll
Female Same Size Vore Thread
Hendricks County Mugshots Busted Newspaper
Auto-Mataru
Bfri Forum
Forum Train Europe FTE on LinkedIn: #freight #traffic #timetablingeurope #fted
Oh The Pawsibilities Salon & Stay Plano
2013 Freightliner Cascadia Fuse Box Diagram
25+ Twitter Header Templates & Design Tips - Venngage
Pella Culver's Flavor Of The Day
Walgreens Pharmacy On Jennings Station Road
No Cable Schedule
Culver's Flavor Of The Day Taylor Dr
Horoscope Daily Yahoo
Brublackvip
Match The Criminal To The Weapon
Shapovalov Flashscore
Alabama Adventure Coupons
Remembering the names of those who died on 9/11
Clothes Mentor Overland Park Photos
Oprichter Haagse rapgroep SFB doodgeschoten, wie was hij?
Dimmitt Range Rover
Rg353M Vs Rg351Mp
236 As A Fraction
Sarah Snook Weight Gain
Alibaba Expands Membership Perks for 88VIP
Best Of Clinton Inc Used Cars
Hourly Pay At Dick's Sporting Goods
Understanding DeFi The Roles, Tools, Risks, and Rewards of -- Alexandra Damsker -- 2024 -- O'Reilly Media -- 9781098120764 -- 79accdb00af9d0f41d97f44fa7970ff1 -- Annas Archive - Biblioteconomia
Eureka Mt Craigslist
Walmart Makes Its Fashion Week Debut
Level A Sarasota
18 Awesome Things to do in Fort Walton Beach Florida 2024 - The Wanderlust Within
Wiley Rein Vault
Latest Posts
Article information

Author: Barbera Armstrong

Last Updated:

Views: 5906

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Barbera Armstrong

Birthday: 1992-09-12

Address: Suite 993 99852 Daugherty Causeway, Ritchiehaven, VT 49630

Phone: +5026838435397

Job: National Engineer

Hobby: Listening to music, Board games, Photography, Ice skating, LARPing, Kite flying, Rugby

Introduction: My name is Barbera Armstrong, I am a lovely, delightful, cooperative, funny, enchanting, vivacious, tender person who loves writing and wants to share my knowledge and understanding with you.