sym
Create symbolic variables, expressions, functions, matrices
金宝app支持无效变量名称且未定义数字的字符矢量的支持。要创建符号表达式,请首先创建符号变量,然后在其上使用操作。例如,使用syms x; x + 1
代替sym('x + 1')
,,,,eXp((SYM(PI))
代替SYM('Exp(pi)')
,,,,一个ndsyms f(var1,...varN)
代替f(var1,...varN) = sym('f(var1,...varN)')
。
句法
Description
创建一个一个
= sym('<一个Href="//www.tatmou.com/au/help/symbolic/#bun735q-a" class="intrnllnk">一个
',,<一个Href="//www.tatmou.com/au/help/symbolic/#bun735q-n1nM" class="intrnllnk">[n1 ... nM]
)n1
-by-。。。
-by-nM
symbolic array filled with automatically generated elements. For example,a = sym('a',[1 3])
creates the row vectora =[a1 a2 a3]
。The generated elements一个1
,,,,一个2
,,,,一个nd一个3
do not appear in the MATLAB®workspace. For multidimensional arrays, these elements have the prefix一个
followed by the element’s index using_
作为定界符,例如一个1_3_2
。
sym(___,,,,<一个Href="//www.tatmou.com/au/help/symbolic/#bun735q-set" class="intrnllnk">
创建一个符号变量或数组,并设置一个假设,即变量或所有数组元素属于一个放
)放
。Here,放
可'real'
,,,,'positive'
,,,,'integer'
,,,,or'rational'
。You also can combine multiple assumptions by specifying a string array or cell array of character vectors. For example, assume a positive rational value by specifying放
作为["positive" "rational"]
or{'positive','rational'}
。
sym(___,'清除')
clears assumptions set on a symbolic variable or array. You can specify'清除'
一个fter the input arguments in any of the previous syntaxes, except combining'清除'
一个nd<一个Href="//www.tatmou.com/au/help/symbolic/#bun735q-set" class="intrnllnk">放
。You cannot set and clear an assumption in the same function call tosym
。
sym(<一个Href="//www.tatmou.com/au/help/symbolic/#bun735q-num" class="intrnllnk">
转换一个数字或数字矩阵num
)num
对于符号数或符号矩阵。
sym(<一个Href="//www.tatmou.com/au/help/symbolic/#bun735q-num" class="intrnllnk">
uses the technique specified bynum
,,,,<一个Href="//www.tatmou.com/au/help/symbolic/#bun735q-flag" class="intrnllnk">flag
)flag
用于将浮点数转换为符号数字。
sym(<一个Href="//www.tatmou.com/au/help/symbolic/#mw_b4228c40-a002-49a8-a6cc-1bec4af17ca8" class="intrnllnk">
converts the character vector or string specified bystrnum
)strnum
to an accurate symbolic number that avoids any approximation.
Examples
输入参数
Output Arguments
Tips
Statements like
pi = sym(pi)
一个nddelta = sym('1/10')
创建符号数字,以避免浮点近似值p一世
一个nd1/10
。Thep一世
以这种方式创建的符号编号在命名的工作区变量p一世
,,,,which temporarily replaces the built-in numeric function with the same name. Useclear pi
恢复浮点的表示p一世
。sym
一个lways treats一世
在字符矢量输入中作为标识符。输入虚构数字一世
,,,,use1一世
反而。清除x
does not clear the symbolic object of its assumptions, such as real, positive, or any assumptions set by作为sume
,,,,sym
,,,,orsyms
。要删除假设,请使用以下选项之一:作为sume(x,'clear')
删除所有影响的假设X
。clear all
clears all objects in the MATLAB workspace and resets the symbolic engine.作为sume
一个nd作为sumeAlso
provide more flexibility for setting assumptions on variable.
当您用符号编号替换数字向量或矩阵的一个或多个元素时,MATLAB将该数字转换为双精度编号。
a =eye((3); A(1,1) = sym(pi)
a =3。1416 0 0 0 1.0000 0 0 0 1.0000
You cannot replace elements of a numeric vector or matrix with a symbolic variable, expression, or function because these elements cannot be converted to double-precision numbers. For example,
a(1,1)= sym('a')
tHrows an error.When you use the syntax
a =sym('a',[n1 ... nM])
, 这sym
function assigns only the symbolic array一个
to the MATLAB workspace. To also assign the automatically generated elements of一个
, 使用<一个Href="//www.tatmou.com/au/help/symbolic/syms.html">syms
功能。例如,SYMS A [1 3]
creates the row vector一个= [a1 a2 a3]
一个nd the symbolic variables一个1
,,,,一个2
,,,,一个nd一个3
一世ntHeMATLAB workspace.
一个lternative Functionality
创建符号变量的替代方法
To create several symbolic variables in one function call, usesyms
。Usingsyms
还清除了命名变量的假设。