matlab符号函数的建立826.docx
《matlab符号函数的建立826.docx》由会员分享,可在线阅读,更多相关《matlab符号函数的建立826.docx(13页珍藏版)》请在冰豆网上搜索。
matlab符号函数的建立826
符号函数的建立:
y=sym('sin(x)+cos(x)');
x=sym('x');
y=sin(x)+cos(x)
结果:
y=
cos(x)+sin(x)
y=
cos(x)+sin(x)
符号矩阵:
程序:
将数值矩阵转化为符号矩阵
b=[2/3sqrt
(2);5.2log(3)];
c=sym(b)
结果:
y=
cos(x)+sin(x)
y=
cos(x)+sin(x)
a=
[x+1,sin(x)]
[5,exp(x)]
a=
[x+1,sin(x),5,exp(x)]
a=
[x+1,sin(x)]
[5,exp(x)]
c=
[2/3,2^(1/2)]
[26/5,2473854946935173/2251799813685248]
符号矩阵中的元素的引用和修改:
符号函数的建立:
y=sym('sin(x)+cos(x)');
x=sym('x');
y=sin(x)+cos(x)
结果:
y=
cos(x)+sin(x)
y=
cos(x)+sin(x)
符号矩阵:
程序:
将数值矩阵转化为符号矩阵
b=[2/3sqrt
(2);5.2log(3)];
c=sym(b)
结果:
y=
cos(x)+sin(x)
y=cos(x)+sin(x)
符号表达式中符号变量的查找:
程序:
clc
clearall
f1=sym('a*x^2+B*x+c');
g1=findsym(f1)
g2=findsym(f1,1)
g3=findsym(f1,2)
g4=findsym(f1,3)
结果:
g1=
B,a,c,x
g2=
x
g3=
x,c
g4=
x,c,a
求多项式在某一点的值;;;;
把多项式表示成符号函数,利用sub函数求其在某一点的值
程序:
clc
clearall
f=sym('s*u')
f1=subs(f,'u',2)
f2=subs(f,'u','u+2')
结果:
f=s*u
f1=2*s
f2=
s*(u+2)
程序2
clc
clearall
f=sym('2*u')
symsxy
f3=subs(f,'u',x+y)
subs(f3,[x,y],[1,2])
结果:
f=2*u
f3=2*x+2*y
ans=
6
符号数值精度控制
任意代数精度设置;;;
六大常见符号运算:
符号函数公式是:
syms而不是sym
1,因式分解:
程序:
clc
clearall
symsx;
f=x^6+1
f1=factor(f)
结果:
f=
x^6+1
f1=
(x^2+1)*(x^4-x^2+1)
11---Factor可用于正整数的因式分解
程序11-----
s=factor(100)
factor(sym('1234567890'))%大整数的因式分解要转化为符号常量
结果:
s=
2255
ans=
2*3^2*5*3607*3803
2---函数展开
三角函数的展开:
程序:
clc
clearall
symsxy;
f=sin(x+y);
f1=expand(f)
结果:
f1=
cos(x)*sin(y)+cos(y)*sin(x)
3-----合并同类项————collect
程序:
clc
clearall
symsxy;
f=x^2*y+y*x-x^2+2*x;
f1=collect(f)
f2=collect(f,y)
结果:
f1=
(y-1)*x^2+(y+2)*x
f2=
(x^2+x)*y+2*x-x^2
4+——函数简化——simple函数,使其转化为最简单的形式
程序:
clc
clearall
symsx
g1=2*cos(x)^2-sin(x)^2;
[Howy1]=simple(g1)
g2=(x+1)*x*(x-1);
[Howy2]=simple(g2)
g3=x^3+3*x^2+3*x+1;
[Howy3]=simple(g3)
g4=cos(3*acos(x));
[Howy4]=simple(g4)
结果:
How=
2-3*sin(x)^2
y1=
simplify
How=
x^3-x
y2=
simplify(100)
How=
(x+1)^3
y3=
simplify
How=
4*x^3-3*x
y4=simplify(100)
函数多次简化;
程序:
clc
clearall
symsx;
f=(1/x^3+6/x^2+12/x+8)^(1/3);
y1=simplify(f)
g1=simple(y1)
g2=simple(g1)
结果:
y1=
((2*x+1)^3/x^3)^(1/3)
g1=
((2*x+1)^3/x^3)^(1/3)
g2=
((2*x+1)^3/x^3)^(1/3)
>>
5——分式通分
函数简化:
程序:
clc
clearall
symsxy;
f=x/y+y/x;
[nd]=numden(f)
结果:
n=
x^2+y^2
d=
x*y
可以对数进行同分:
程序
clc
clearall
[nd]=numden(sym(112/1024))
factor(sym(10000))
结果:
n=
7
d=
64
ans=
2^4*5^4
6——计算极限
程序:
clc
clearall
symsxhn;
l=limit((log(x+h)-log(x))/h,h,0)
l11=limit((log(x+h)-log(x))/h,h,0,'right')%表达式的右极限
l12=limit((log(x+h)-log(x))/h,h,0,'left')%表达式的左极限
结果:
l=
1/x
l11=
1/x
l12=
1/x
趋于无穷的极限——
程序
clc
clearall
symsxn;
limit((1-x/n)^n,n,inf)
结果:
ans=
1/exp(x)
求积分:
程序:
clc
clearall
symsx
f=(x^2+1)/(x^2-2*x+2)^2;
f1=int(f,x)
g=exp(-x^2);
g1=int(g,0,inf)
结果:
f1=
(3*atan(x-1))/2+(x/2-3/2)/(x^2-2*x+2)
g1=
pi^(1/2)/2
求和:
程序:
clc
clearall
symsn;
f=1/n^2;
f1=symsum(f,n,1,inf)
f2=symsum(f,n,1,100)
结果
f1=
pi^2/6
f2=
158********330378*********28517553859702383498543709859889432834803818131090369901/972186144434381030589657976672623144161975583995746241782720354705517986165248000
程序2计算函数的级数——
clc
clearall
symsxn;
f=x/n^2;
f1=symsum(f,n,1,inf)
结果;
f1=
(pi^2*x)/6
>>