Convert symbolic values to MATLAB double precision (2024)

Convert symbolic values to MATLAB double precision

collapse all in page

Syntax

d = double(s)

Description

example

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.

Examples

collapse all

Convert Symbolic Number to Double Precision

Open Live Script

Convert symbolic numbers to double precision by using double. Symbolic numbers are exact, while double-precision numbers have round-off errors.

Convert π and 13 from symbolic form to double precision.

symN = sym([pi 1/3])
symN =

(π13)

doubleN = double(symN)
doubleN = 1×2 3.1416 0.3333

For information on round-off errors, see Recognize and Avoid Round-Off Errors.

Convert Variable Precision to Double Precision

Open Live Script

Variable-precision numbers created by vpa are symbolic values. When a MATLAB function does not accept symbolic values, convert variable precision to double precision by using double.

Convert π and 13 from variable-precision form to double precision.

vpaN =(3.14159265358979323846264338327950.33333333333333333333333333333333)
doubleN = double(vpaN)
doubleN = 1×2 3.1416 0.3333

Convert Symbolic Matrix to Double-Precision Matrix

Open Live Script

Convert the symbolic numbers in matrix symM to double-precision numbers by using double.

a = sym(sqrt(2));b = sym(2/3);symM = [a b; a*b b/a]
symM =

(22322323)

doubleM = double(symM)
doubleM = 2×2 1.4142 0.6667 0.9428 0.4714

High-Precision Conversion

Open Live Script

When converting symbolic expressions that suffer from internal cancellation or round-off errors, increase the working precision by using digits before converting the number.

Convert a numerically unstable expression Y with double. Then, increase precision to 100 digits by using digits and convert Y again. This high-precision conversion is accurate, while the low-precision conversion is not.

Y = ((exp(sym(200)) + 1)/(exp(sym(200)) - 1)) - 1;lowPrecisionY = double(Y)
lowPrecisionY = 0
digitsOld = digits(100);highPrecisionY = double(Y) 
highPrecisionY = 2.7678e-87

Restore the old precision used by digits for further calculations.

digits(digitsOld)

Convert Symbolic Results to Double Precision

Open Live Script

Solve the trigonometric equation sin(2x)+cos(x)=0 by using solve. Set the ReturnConditions option to true to return the complete solution, parameters used in the solution, and conditions on those parameters.

syms xeqn = sin(2*x) + cos(x) == 0;[solx,params,conds] = solve(eqn,x,ReturnConditions=true)
solx =

(π2+πk2πk-π67π6+2πk)

params =k
conds =

(kZkZkZ)

The solver does not create the variable k for the parameters in the MATLAB® workspace. Create this variable. Find the solutions for k=2 by using subs.

syms ksols_k2 = subs(solx,k,2)
sols_k2 =

(5π223π631π6)

The solutions are exact symbolic numbers. Convert these numbers to double-precision numbers.

doublesols_k2 = double(sols_k2)
doublesols_k2 = 3×1 7.8540 12.0428 16.2316

Convert Symbolic Matrix Variable of Numbers to Double Precision

Open Live Script

Create a symbolic expression S that represents A2-2A+I2, where A is a 2-by-2 symbolic matrix variable.

syms A 2 matrixS = A*A - 2*A + eye(2)
S =I2-2A+A2

Substitute A with symbolic numbers [cos(π5)sin(π4)-10].

Aval = [cos(sym(pi)/5) sin(pi/4); -1 0];symS = subs(S,A,Aval)
symS =

-2Σ1+Σ12+I2whereΣ1=(54+1422-10)

Convert the result to a double-precision matrix.

doubleS = double(symS)
doubleS = 2×2 -0.6706 -0.8422 1.1910 0.2929

Input Arguments

collapse all

sSymbolic input
symbolic number | array of symbolic numbers | symbolic matrix variable of numbers

Symbolic input, specified as a symbolic number, array of symbolic numbers, or symbolic matrix variable of numbers. If the input contains only numeric values (does not contain symbolic numbers), then the MATLAB double function is called.

Data Types: sym | symmatrix

Version History

Introduced before R2006a

expand all

See Also

sym | vpa | subs

Topics

  • Choose Numeric or Symbolic Arithmetic
  • Increase Precision of Numeric Calculations
  • Recognize and Avoid Round-Off Errors
  • Increase Speed by Reducing Precision
  • 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.

Convert symbolic values to MATLAB double precision (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

Convert symbolic values to MATLAB double precision (2024)

References

Top Articles
IP Address Lookup - IP Location Lookup For Any IP Address
Sunyou Tracking | 4Trackit
It's Official: Sabrina Carpenter's Bangs Are Taking Over TikTok
Craigslist Free En Dallas Tx
Top Scorers Transfermarkt
Lighthouse Diner Taylorsville Menu
Wmu Course Offerings
Myhr North Memorial
Hotels Near 500 W Sunshine St Springfield Mo 65807
Teamexpress Login
Jesse Mckinzie Auctioneer
41 annonces BMW Z3 occasion - ParuVendu.fr
What's New on Hulu in October 2023
Magic Mike's Last Dance Showtimes Near Marcus Cedar Creek Cinema
Sotyktu Pronounce
The Binding of Isaac
Void Touched Curio
Interactive Maps: States where guns are sold online most
Condogames Xyz Discord
Mail.zsthost Change Password
Idaho Harvest Statistics
111 Cubic Inch To Cc
A Cup of Cozy – Podcast
14 Top-Rated Attractions & Things to Do in Medford, OR
Malluvilla In Malayalam Movies Download
Villano Antillano Desnuda
What Is a Yurt Tent?
Bend Missed Connections
Play It Again Sports Forsyth Photos
Myaci Benefits Albertsons
Sam's Club Gas Price Hilliard
Pipa Mountain Hot Pot渝味晓宇重庆老火锅 Menu
United E Gift Card
Fastpitch Softball Pitching Tips for Beginners Part 1 | STACK
Netherforged Lavaproof Boots
Appraisalport Com Dashboard /# Orders
Maybe Meant To Be Chapter 43
Myql Loan Login
Compare Plans and Pricing - MEGA
Trap Candy Strain Leafly
Timberwolves Point Guard History
Google Flights Orlando
Top 25 E-Commerce Companies Using FedEx
F9 2385
Weather Underground Cedar Rapids
California Craigslist Cars For Sale By Owner
Youravon Com Mi Cuenta
Hdmovie2 Sbs
Craigslist Marshfield Mo
Where Is Darla-Jean Stanton Now
Optimal Perks Rs3
Craigslist.raleigh
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 5599

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.