数值计算的通用函数
符号计算基础
创建符号对象
sym
符号变量名=sym('符号字符串')
例一:符号运算解方程
clear;clc;
a=sym('a');b=sym('b');x=sym('x');y=sym('y');
[x,y]=solve(a*x-b*y-1,a*x+b*y-4);%这里要把等式右边都换成零
x
y

syms
syms 符号变量名1 符号变量名2 …… 符号变量名n
使用方法和sym函数类似
但是现在已经过时了,被替换成了str2sym
运算符和运算
常用运算
提取分子和分母
%提取分子和分母
clear;clc;
syms x y;
f=x/2*y+2*y/x;
[n,d]=numden(f)

变量替换
%变量替换
clear;clc;
syms x x1 x2 x3;
y=1+2*x+3^x;
subs(y,'x','x1+2*x2+3*x3')
这样会报错,MATLAB虽好用,但有时候报错莫名其妙的。所以选参考书一定要选最新的,不然很多函数都被抛弃了。
报错内容:
Error using sym>convertChar (line 1448)
Character vectors and strings in the first argument can only specify a variable or number. To evaluate
character vectors and strings representing symbolic expressions, use ‘str2sym’.
Error in sym>tomupad (line 1214)
S = convertChar(x);
Error in sym (line 211)
S.s = tomupad(x);
需要这样改:
%变量替换
clear;clc;
syms x x1 x2 x3;
y=sym(1+2*x+3^x);
subs(y,'x',sym(x1+2*x2+3*x3))
也就是不能用字符串符号计算,需要使用符号计算函数才行。

因式分解和展开
| 函数 | 说明 |
|---|---|
| factor(s) |

最低0.47元/天 解锁文章
7766

被折叠的 条评论
为什么被折叠?



