>> syms a t % 定义符号变量
>> g = a *cos(pi * t);>>int(sym(g))
ans =(a*sin(pi*t))/pi
>> g =sin(n * t);>>int(sym(g))% 默认t为变量
ans =-cos(n*t)/n
>>int(sym(g), n)% 选n为变量
ans =-cos(n*t)/t
>>
>> syms n
>> g ='sin(n * t)';% 字符向量
>>int(sym(g), n)
警告: Support of character vectors will be removed in a future release.
Character vectors can be used only for variable names and numbers.
Instead, to create symbolic
expressions first create symbolic variables using 'syms'.
To evaluate character vectors
and strings representing symbolic expressions, use 'str2sym'.% 字符向量的支持将在未来版本中删除
> In sym>convertExpression (line 1581)
In sym>convertChar (line 1486)
In sym>tomupad (line 1236)
In sym (line 215)
ans =-cos(n*t)/t
>> syms n
>> g =sin(n * t);% 修改之后即可
>>int(sym(g), n)
ans =-cos(n*t)/t
>> syms b x
>> f = b ^ x;>> F =int(sym(f))
F =
b^x/log(b)>>subs(F,{
b, x},{
2,4})
ans =16/log(2)% 通过调用 subs 命令,使用给定的值我们可以计算表达式的数值。
要在一个命令中用数代替符号变量,
我们要把被代替的符号列表和用来代替的数值列表都用花括号括起来
>> format short>>16/log(2)
ans =23.0831
>> syms x
>> f = x ^5*cos(9* x);>>int(sym(f))
ans =(40*cos(9*x))/177147+(40*x*sin(9*x))/