矩阵的多项式求值
p = [5 2 7];
polyvalm(p,[1 5;4 9])
求多项式x^5-3x^4+4x-7x2+2x-5的根
a=[1 -3 4 -7 2 -5];
r=roots(a)
s=compan(a)
r=eig(s)
r =
2.5154
0.4203 + 1.4083i
0.4203 - 1.4083i
-0.1780 + 0.9427i
-0.1780 - 0.9427i
s =
3 -4 7 -2 5
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
r =
2.5154
0.4203 + 1.4083i
0.4203 - 1.4083i
-0.1780 + 0.9427i
-0.1780 - 0.9427i
s为伴随矩阵(companion),r为s的特征值(eigenvalues)
输入系数矢量,创建多项式x^3-2*x^2+5*x+3。
poly2sym([1 -2 5 3])
ans =
x^3-2*x^2+5*x+3
两个多项式的相乘:
计算两多项式2x^4-5x^3+7x^2-3x+10和5x^3+3x^2-6x+3的乘法
a=[2 -5 7 -3 10];
b=[5 3 -6 3];
c=conv(a,b)
c =
10 -19 8 42 -16 69 -69 30
因式分解
syms x
f=factor(x^3-1)
f =
(x-1)*(x^2+x+1)
pretty(f)
2
(x - 1) (x + x + 1)
其中pretty的作用是使显示的结果美化
函数展开
>> syms x y
>> f=cos(x+y);
>> expand(f)
ans =
cos(x)*cos(y)-sin(x)*sin(y)
提取公因式
yms X t
f=(2*X^2*(X+3)-10)*t;
collect(f,t)
ans =
(2*X^2*(X+3)-10)*t
程序内容是对
(2*X^2*(X+3)-10)*t按X提取公因式
符号表达式的化简
[r,how]=simple((x+1)*(x-1))
r =
x^2-1
how =
simplify
其中how是简化的类型
多项式通分
clear
>> syms x y
>> [a,b]=numden((x-1)/y+(y+1)/x)
a =
x^2-x+y^2+y
b =
y*x
符号表达式的替换
用新变量替换表达式b中变量y。
>> syms a b
syms x y y1
>> subs(x+y,y1,y)
ans =
x+y1
求函数的极限
syms a x
>> v=(1+a/x)^x;
>> limit(v,x,inf)
ans =
exp(a)
求微分
syms x
diff(x^5,4)
ans =
120*x
求积分
>> syms x t
>> int(x^t,t,1,2)
ans =
x*(x-1)/log(x)
>> int(x^t,x,1,2)
ans =
(2*2^t-1)/(t+1)
连加
sysm x n
[r,how]=simple(symsum(x^2,1,n))
r =
1/6*n*(n+1)*(2*n+1)
how =
factor
taylor展开
syms x y
taylor(exp(x*y),0,4,x)
ans =
1+x*y+1/2*x^2*y^2+1/6*y^3*x^3
求方程组的解:
syms x y
>> [X,Y] = solve(x+y-1, x-y-2)
X =
3/2
Y =
-1/2
或者
[X,Y] = solve('x+y-1=0', 'x-y-2=0')
X =
3/2
Y =
-1/2
检测语句
clear
a=magic(3);%生成3行3列的矩阵
try
a_end=a(4,:)
catch
a_end=a(end,:)
end
a_end =
4 9 2
>> lasterr
ans =
Index exceeds matrix dimensions.
举报
举报
举报
更多回帖