matlab学习日志——初级符号计算

%%
%符号对象和符号表达式
%符号对象的创建sym()syms
%先创建符号变量(包括常量)
clear
clc
a1=sym(2/3)
a2=sym(2/3,'d')
a3=sym(2/3,'r')
a4=sym('A')
a5=sym('abcdefg')
clear
clc
syms a1 a4 a5
2/3 ,'A','abcdefg'
%符号表达式的创建
%不能用=给sym变量赋值,那样它会变成对应一般类型变量
clc
clear
syms a b c d e x
f=a*x^4+b*x^3+c*x^2-d*x+e
g=sym('x^2+x^a==b')
h=[1 1+x a+x;c*e b/d x*d;2 d/e x^a]
h(2)
h(1,3)
h(1,:)
%可见符号矩阵(sym实例矩阵)的元素引用与普通矩阵无二
%%
%符号计算中的运算符,以矩阵运算为例
clear
clc
syms a b c d e f g h x y;
v1=[a b;c d];
v2=[e f;g h];
v1*v2
v1.*v2
v1/v2
v1./v2
v1+v2
v1-v2
v1.^x
v1^x
v1+x
v1*x
v1.'
log(a)
sin(b)
inv(v1)
det(v1)
rank(v1)
x=sym(2/3,'r')
vpa(x,6)
%%
%符号表达式操作
%符号表达式显示pretty()
clear
clc
syms x y a 
f=x^2+y^3-a/x^2;
pretty(f)
%符号表达式同类项合并collect()
g=(x-1)^3
collect(g)
%表达式展开expand()
expand(g)
%提取公因式
h=x^2+2*x;
horner(h)
%表达式分解
j=2*x^2-7*x*y-22*y^2-5*x+35*y-3;
factor(j)
%表达式化简
k=[(x^3-1)/(x-1);cos(x)+i*sin(x)]
simplify(k)
simplify(cos(x)+i*sin(x))
%%
%符号表达式的替换
%用符号变量或者符号表达式替换符号变量subs()
clear
clc
syms x y a b;
f=(2*x^2)+(x^2-6)/(x^2+a)
g=(y+x)^(y+x)
subs(f,x,2)
subs(f,y,1)
subs(f,a,'abcdefg')
%用符号变量去替换子表达式subexpr()
[Y1,SIM1]=subexpr(f,b)
[Y2,SIM2]=subexpr(g,a)
%%
%求复合函数compose()
clear
clc
syms x y;
f=sin(y);
g=x^2+1;
compose(f,g)
compose(g,f)
%求反函数finverse()
finverse(f,y)
finverse(g,x)
发布了17 篇原创文章 · 获赞 7 · 访问量 7104

猜你喜欢

转载自blog.csdn.net/hrwy2920566283/article/details/81358052