符号变量及其运算
绪:什么是符号计算?
1.字符型数据变量的创建
2.符号型数据变量的创建
3.符号计算的运算符与函数
4.寻找符号变量
5.符号精度计算
6.显示符号表达式
7.合并符号表达式
8.展开符号表达式
绪:什么是符号计算?
所谓符号计算是指在运算时,无须事先对变量赋值,而将所得到结果以标准的符号形式来表示。 例如,在符号变量运算过程中pi就用pi表示,而不是具体的近似数值在这里插入代码片3.14或3.1415926。使用符号变量进行运算能最大限度地减少运算过程中因舍入而造成的误差。符号变量也便于进行运算过程的演示。
1.字符型数据变量的创建
var = ‘expression
字符型变量是以矩阵的形式存在于Matlab的工作空间中的
示例
>> var = 'hello world'
var =
hello world
>> size(var)
ans =
1 11
>> y = '1 + sin(2*x)'
y =
1 + sin(2*x)
2.符号型数据变量的创建
符号对象中的符号常量、变量、函数和表达式,可以用sym和syms函数创建。使用class函数测试建立的操作对象为何种操作对象类型及是否为符号对象类型。
以下为Matlab自带的sym函数解释:
>> help sym
sym 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.
If the input is a function handle the result is the symbolic form
of the body of the function handle.
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','clear') restores x to a
formal variable with no additional properties (i.e., insures that x
is NEITHER real NOR positive).
See also: SYMS.
A = sym('A',[N1 N2 ... Nk]) creates an N1-by-N2-...-by-Nk array of
symbolic scalar variables. Elements of vectors have names of the form Ai and elements
of matrices and higher-dimensional arrays have names of the form
Ai1_..._ik where each ij ranges over 1:Nj.
The form can be controlled exactly by using '%d' in the first
input (eg 'A%d%d' will make names Ai1i2).
A = sym('A',N) creates an N-by-N matrix.
sym(A,ASSUMPTION) makes or clears assumptions on A as described in
the previous paragraph.
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 transformed from
double precision to exact numeric values N*2^e for integers N and e.
'r' stands for 'rational'