第三讲 MATLAB的符号运算

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第三讲MATLAB的符号运算

——matlab 不仅具有数值运算功能,还开发了在matlab环境下实现符号计算的工具包Symbolic Math Toolbox

符号运算的功能

•符号表达式、符号矩阵的创建

•符号线性代数

•因式分解、展开和简化

•符号代数方程求解

•符号微积分

•符号微分方程

一、创建符号变量

1.什么是符号运算

•与数值运算的区别

※数值运算中必须先对变量赋值,然后才能参与运算。

※符号运算无须事先对独立变量赋值,运算结果以标准的符号形式表达。

•特点:

①运算对象可以是没赋值的符号变量

②可以获得任意精度的解

•Symbolic Math Toolbox——符号运算工具包通过调用Maple软件实现符号计算的。

•maple软件——主要功能是符号运算,它占据符号软件的主导地位。

2. Sym函数定义符号变量

(1)S=sym(arg)

Construct symbolic numbers, variables and objects.

S = SYM(A) constructs an object S, of class 'sym', from A.

If the input argument is a string, the result is a symbolic number or variable.

If the input argument is a numeric scalar or matrix,

the result is a symbolic representation of the given numeric values

x = sym('x') creates the symbolic variable with name 'x' and stores the result in x. x = sym('x','real') also assumes that x is real, so that conj(x) is equal to x.

alpha = sym('alpha') and

r = sym ( 'Rho‘ , 'real') are other examples. Similarly, k =sym('k','positive') makes k a positive (real) variable.

x = sym('x','unreal') makes x a purely formal variable with no additional properties (i.e., insures that x is NEITHER real NOR positive). See also: SYMS.

Statements like pi = sym('pi') and delta = sym('1/10') create symbolic numbers which avoid the floating point approximations inherent in the values of pi and 1/10. The pi created in this way temporarily replaces

the built-in numeric function with the same name.

S = sym(A,flag) converts a numeric scalar or matrix to symbolic form.

The technique for converting floating point numbers is specified by the optional second argument, which may be 'f', 'r', 'e' or 'd'. The default is 'r'.

'f' stands for 'floating point'. All values are represented in the form '1.F'*2^(e) or '-1.F'*2^(e) where F is a string of 13 hexadecimal digits and e is an integer. This captures the floating

point values exactly, but may not be convenient for subsequent manipulation.

For example, sym(1/10,'f') is '1.999999999999a'*2^(-4) because 1/10 cannot be represented exactly in floating point.

'r' stands for 'rational'. Floating point numbers obtained by evaluating expressions of the form p/q, p*pi/q, sqrt(p), 2^q and 10^q for modest sized integers p and q are converted to the corresponding symbolic form. This effectively compensates for the roundoff error involved in the original evaluation, but may not represent the floating point value precisely. If no simple rational approximation can be found, an expression of the form p*2^q with large integers p and q reproduces the floating point value exactly. For example, sym(4/3,'r') is '4/3', but sym(1+sqrt(5),'r') is 286977268806824*2^(-51)

'e' stands for 'estimate error'. The 'r' form is supplemented by a term involving the variable 'eps' which estimates the difference between the theoretical rational expression and its actual floating point value. For example, sym(3*pi/4) is 3*pi/4-103*eps/249.

'd' stands for 'decimal'. The number of digits is taken from the current setting of DIGITS used by VPA. Fewer than 16 digits looses some accuracy, while more than 16 digits may not be warranted.

For example, with digits(10), sym(4/3,'d') is 1.333333333, while with digits(20), sym(4/3,'d') is 1.3333333333333332593,

which does not end in a string of 3's, but is an accurate decimal representation of the floating point number nearest to 4/3.

3.syms 函数定义符号变量

Short-cut for constructing symbolic objects.

SYMS arg1 arg2 ...

is short-hand notation for

arg1 = sym('arg1');

arg2 = sym('arg2'); ...

SYMS arg1 arg2 ... real

is short-hand notation for

arg1 = sym('arg1','real');

arg2 = sym('arg2','real'); ...

SYMS arg1 arg2 ... positive

is short-hand notation for

arg1 = sym('arg1','positive');

arg2 = sym('arg2','positive'); ...

SYMS arg1 arg2 ... unreal

is short-hand notation for

arg1 = sym('arg1','unreal');

arg2 = sym('arg2','unreal'); ...

Each input argument must begin with a letter and must contain only

alphanumeric characters.

By itself, SYMS lists the symbolic objects in the workspace.

Examples:

syms x beta real

相关文档
最新文档