This website uses cookies. By using this site, you consent to the use of cookies. For more information, please take a look at our Privacy Policy.
Home > Wiki encyclopedia > SYM

SYM

The sym function is used to create symbol numbers, symbol variables, and symbol objects. The type of symbol object is sym, which can be verified by class(S), where S is a symbol object.

Function introduction

Function function: In MATLAB, the advantage of the symbol variable is that the operation obtained using the symbol variable is only an analytical solution. For example, in the operation of the symbol variable π is expressed by π, rather than the specific approximate value 3.14 or 3.14159. Using symbolic variables for operations can minimize errors caused by rounding during operations. Symbol variables are also convenient for the demonstration of the operation process.

Syntax format:

S = sym(A) converts non-symbol objects (eg, numbers, expressions, variables, etc.) A into symbol objects and stores them in symbol variables S.

x = sym('x')

Create a symbol variable x whose name is'x'. Example: alpha = sym('alpha')

x = sym('x','real')

It is assumed here that x is a real number, so the conjugate conj(x) of x is equal to x. Example: r = sym('Rho','real')

k = sym('k','positive')

This creates a positive (real) sign variable.

x = sym('x','clear')

Create a purely formal symbol variable x without additional attributes (for example, create a symbol variable x, but do not specify whether it is positive or it is a real number). For compatibility with older MATLAB versions, x = sym('x','unreal') has the same function as x = sym('x','clear').

S = sym(A, flag)

Convert a numeric scalar or matrix into a symbolic object. The value of the flag parameter here can be:'r','d','e', or'f', which specifies the rules when converting floating-point numbers:

'f': means "floating-point". In this way, all values are expressed in the form of N*2^e or -N*2^e. Both N and e are integers, and N is not less than 0. For example, sym(1/10,'f') is converted to 3602879701896397/36028797018963968.

'r': stands for "rational" (rational number form). Here, all floating-point numbers are represented and formed into forms such as p/q (fractional form), p*pi/q, 2^q, 10^q, sqrt(p), etc. (p and q are both symbolic rational numbers) . This method of representation reduces errors caused by rounding in expressions. But sometimes this method does not accurately represent a value. If the most approximate rational number cannot be found to represent a floating-point number, the number will be expressed in the form of p*2^q (where p and q are both large integers) in order to accurately represent its value . For example, sym(4/3,'r') will produce the symbol quantity '4/3', but sym(1+sqrt(5),'r') will be expressed as 7286977268806824*2^(-51).

'e': means "estimate error". This form adds an error value represented by a symbolic expression containing eps on the basis of'r'. This error value represents the error between the theoretical value of a rational number and the actual value expressed in the form of floating-point numbers. For example, sym(3*pi/4,'e') will be expressed as 3*pi/4*(1+3143276*eps/65).

'd': means "decimal" (decimal). We know that in real life we are used to decimal, but the computer uses binary, a simple decimal floating point number 3.14 can not be accurately expressed in binary. Therefore, a better way to reduce errors is to introduce a decimal in the computer to represent a number. In this case, the numbers are taken from the set of numbers generated after calling the vpa function. Although 16-bit sometimes does not accurately represent a floating-point number, in most cases, we may not want to use more than 16-bit numbers to represent a floating-point number. For example, by calling digits(10), the floating-point numbers we get are all composed of 10 digits, and sym(4/3,'d') will produce the symbolic number 1.333333333. Although we can use 20 digits to represent a floating-point number after calling digits(20), so that sym(4/3,'d') is 1.3333333333333332593, but we see that only the first 16 digits are accurate, and the following digits The value has produced an error, so in most cases it is not necessary to represent a floating-point number with a number exceeding 16 bits.

Related functions: syms, eps, vpa, digits, findsym, symvar

Program example

>> PI = sym(pi);

>> R = sym(5);

>> areas = PI * R ^ 2

areas = 25*pi

>> class(areas)

ans =sym

>> sym(1/3)

ans =1/3

>> sym(sqrt(5))

ans =5^(1/2)

>> sym(sqrt(5) + 1)

ans =910872158600853/281474976710656

>> sym(1)/sym(3) + sym(1)

ans =4/3

>> y = sin(sym('x'))

y = sin(x)

>> diff(y)

ans = cos(x)

>> diff(y,2)

ans =-sin(x)

>> z = sym('x') ^ 2 + sin(sym('y'))

z = x^2 + sin(y)

>> diff(z,'x')

ans =2*x

>> diff(z,'y')

ans =cos(y)

Other Wikis

ASSOCIATED PRODUCTS

  • XCV200-6FG456C

    XCV200-6FG456C

    FPGA Virtex Family 236.666K Gates 5292 Cells 333MHz 0.22um Technology 2.5V 456-Pin FBGA

  • XC4028XL-2HQ208C

    XC4028XL-2HQ208C

    FPGA XC4000X Family 28K Gates 2432 Cells 0.35um Technology 3.3V 208-Pin HSPQFP EP

  • XC5VFX130T-2FF1738C

    XC5VFX130T-2FF1738C

    FPGA Virtex-5 FXT Family 65nm Technology 1V 1738-Pin FCBGA

  • XC5VFX130T-3FF1738C

    XC5VFX130T-3FF1738C

    FPGA Virtex-5 FXT Family 65nm Technology 1V 1738-Pin FCBGA

  • XC5VFX200T-1FFG1738C

    XC5VFX200T-1FFG1738C

    FPGA Virtex-5 FXT Family 65nm Technology 1V 1738-Pin FCBGA

FPGA Tutorial Lattice FPGA
Need Help?

Support

If you have any questions about the product and related issues, Please contact us.