一、矩阵
1、定义和简单使用(一般的编程语言,数组下标都是从0开始的,但是MATLAB是从1开始的)
>> a=[ ;
;
] a = >> b=[ ; ; ];
>> c=[;;];
>> a+b ans = >> a*b ans = >> a*c ans =
2、常用矩阵运算和函数
A':矩阵转置;
A+B,A-B,A*b:矩阵加减;
inv(A):矩阵求逆;
rank(A):矩阵的秩;
B/A:等价于B*inv(a);
A.*B:点乘,即对应元素相乘;
A(i,:),A(:,j):第i行,第j列;
zeros(n):n阶零矩阵;
eye(n):单位矩阵;
[X,D]=eig(A):X,特征向量,D,特征值
A([i,j],:)=A([j,i],:0):第i行和第j行交换位置;
二、极限(limit),求导(diff),积分(int)
>> F=sym('(1+a/x)^x');
>> limit(F,'x',inf,'left') ans = exp(a) >> syms x;
>> y=log((x+)/(-x)); >> diff(y,x) ans = ((/(x - ) - (x + )/(x - )^)*(x - ))/(x + ) >> diff(y,x,) ans = (*(/(x - ) - (x + )/(x - )^)*(x - ))/(x + )^ - (*(/(x - )^ - (*(x + ))/(x - )^))/(x + ) - (*(/(x - ) - (x + )/(x - )^))/(x + )^ + (*(/(x - )^ - (*(x + ))/(x - )^)*(x - ))/(x + )^ + ((/(x - )^ - (*(x + ))/(x - )^)*(x - ))/(x + ) >> y=x^+y^-sqrt(x)/;
>> int(y)
Warning: Explicit integral could not be found. ans = int(log(-(x + )/(x - ))^, x) - x^(/)/ + x^/ >> pretty(ans) -
/
| / x + \ x x
| log| - ----- | dx - -- + --
/ \ x - /
三、绘图
常用的绘图函数有fplot,plot,plot3,mesh,还有一个辅助函数meshgrid。fplot是根据一个已知的函数表达式画图,plot是画一个二维图,已知x,y的坐标,plot3是画三维图,mesh是画有颜色的三维网状(将空间中每三个点连成一个三角片)图。
fplot('x^3+2*x^2+exp(x)',[-,]);
subplot(,,);
fplot('x^3+2*x^2+exp(x)',[-,]);
title('fplot');
x=-:0.1:;
y=x.^+*x.^+exp(x);
subplot(,,);
plot(x,y);
title('plot');
t=:0.1:;
x=t.^;
y=cos(t);
z=sin(*t);
subplot(,,);
plot3(x,y,z);
title('plot3');
subplot(,,);
x=-:0.1:;
y=-:0.1:;
[x,y]=meshgrid(x,y);
z=sqrt(x.^+y.^);
mesh(x,y,z);
title('mesh');
运行(F5)结果如图所示: