一个关于Matlab编程的问题 s=sym('x')与s=sym(x)有什么区别

来源:百度知道 编辑:UC知道 时间:2024/06/01 06:00:05
RT 最好能讲的明白一点
同时还有一个问题
那位大哥能帮我解释一下这段代码
>> clear
>> f='3*x-7'

f =

3*x-7

>> g='9*x+8'

g =

9*x+8

>> f+g

ans =

108 84 240 88 111

>> f*g
??? Error using ==> mtimes
Inner matrix dimensions must agree.

>> f.*g

ans =

2907 1764 14400 1935 3080

>> clear
>> f='3*x-7'

f =

3*x-7

>> g='2*a-9'

g =

2*a-9

>> f+g

ans =

101 84 217 90 112

>> m='4+x^3-7'

m =

4+x^3-7

>> f+m
??? Error using ==> plus
Matrix dimensions must agree.
谢谢了 回答的好加分的

举个例子:
x=13432;
s1=sym(x)
s2=sym('x')
s1 =
13432
s2 =
x
于是可以知道,sym(x)表示的是,以x所对应的值为符号的参量,
sym('x')直接是以x为符号。
??? Error using ==> mtimes
Inner matrix dimensions must agree.
??? Error using ==> plus
Matrix dimensions must agree
告诉你只有维数相同的矩阵才能相乘,错误发生在f,g对应的向量是1*5的,要么只能对应相乘f.*g,不能是f*g;而m是一个1*7的向量;不能对应于f相加。
注意这种f+g结果是数组。

没学过Matlab,不过一般来说,引号引起来的是按字符串来处理,不加引号为变量