>> a=[1 2 3]a =1 2 3>> b=a'b =123>> fliplr(a)ans =3 2 1>> flipud(a)ans =1 2 3>> rot90(a)ans =321>> a=magic(3)a =8 1 63 5 74 9 2>> help diagdiag - Get diagonal elements or create diagonal matrixThis MA TLAB function returns a square diagonal matrix with the elements of vector v on the main (k=0) diagonal.D = diag(v)D = diag(v,k)x = diag(A)x = diag(A,k)diag 的参考页另请参阅blkdiag, isdiag, istril, istriu, spdiags, tril, triu名为diag 的其他函数fixedpoint/diag, robust/diag, symbolic/diag>> diag(a)ans =852>> b=diag(a)b =852>> diag(b)ans =8 0 00 5 00 0 2>> %建立矩阵>> a=1:9a =1 2 3 4 5 6 7 8 9 >> reshape(a,3,3)ans =1 4 72 5 83 6 9>> b=reshape(a,3,3)b =1 4 72 5 83 6 9>> c=reshape(b,9,1)c =123456789>> tral(a)未定义与'double' 类型的输入参数相对应的函数'tral'。
是不是想输入:>> tril(a)ans =1 0 0 0 0 0 0 0 0 >> inv(b)警告: 矩阵为奇异工作精度。
ans =Inf Inf InfInf Inf InfInf Inf Inf>> c=rand(3)c =0.8147 0.9134 0.27850.9058 0.6324 0.54690.1270 0.0975 0.9575 >> inv(c)ans =-1.9958 3.0630 -1.16902.8839 -2.6919 0.6987-0.0291 -0.1320 1.1282>> %求矩阵的逆>> a=[1 2; 3 4}a=[1 2; 3 4}|错误: 圆括号或方括号不对称或异常。
>> a=[1 2; 3 4]a =1 23 4>> a=[1 2 3;4 5 6;7 8 9]a =1 2 34 5 67 8 9>> a.*a.*|错误: 表达式或语句不完整或不正确。
>> a.*aans =1 4 916 25 3649 64 81>> b=[1 2; 3 4]b =1 23 4>> a*b错误使用*内部矩阵维度必须一致。
>> b=[1 2 5; 3 4 6]b =1 2 53 4 6>> b=[1 2; 5 3;4 6]b =1 25 34 6>> a*bans =23 2653 5983 92>> a.*b错误使用 .*矩阵维度必须一致。
>> b=a>5b =0 0 00 0 11 1 1>> %逻辑运算符>> b=ab =1 2 34 5 67 8 9 >> a&bans =1 1 11 1 11 1 1 >> ~aans =0 0 00 0 00 0 0 >> b=a>5b =0 0 00 0 11 1 1>> a&bans =0 0 00 0 11 1 1>> a|bans =1 1 11 1 11 1 1>> ~bans =1 1 11 1 00 0 0>> t=1:1:10t =1 2 3 4 5 6 7 8 9 10>> y=sin(t)y =0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794 0.6570 0.9894 0.4121 -0.5440>> plot(t,y)>> t=0:0.1:2*pi;>> x1=sin(t);>> plot(t,x1)>> y=asin(x1)y =Columns 1 through 120 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000 1.1000Columns 13 through 241.2000 1.3000 1.4000 1.5000 1.5416 1.4416 1.3416 1.2416 1.1416 1.0416 0.9416 0.8416Columns 25 through 360.7416 0.6416 0.5416 0.4416 0.3416 0.2416 0.1416 0.0416 -0.0584 -0.1584 -0.2584 -0.3584Columns 37 through 48-0.4584 -0.5584 -0.6584 -0.7584 -0.8584 -0.9584 -1.0584 -1.1584 -1.2584 -1.3584 -1.4584 -1.5584Columns 49 through 60-1.4832 -1.3832 -1.2832 -1.1832 -1.0832 -0.9832 -0.8832 -0.7832 -0.6832 -0.5832 -0.4832 -0.3832Columns 61 through 63-0.2832 -0.1832 -0.0832>> figure;plot(t,y)>> t=0:0.1:2*pi;>> t=-pi:0.1:pi;>> x1=sin(t);>> plot(t,x1)>> y=asin(x1);>> figure;plot(t,y)>> t=-pi/2:0.1:pi/2;>> x1=sin(t);plot(t,x1)y=asin(x1);figure;plot(t,y)>> t=-pi:0.1:pi;>> exp(1)ans =2.7183>> exp(j*pi/4)ans =0.7071 + 0.7071i >> power(2,3)ans =8>> power(3,2)ans =9>> pow2(a)ans =2 4 816 32 64128 256 512 >> nextpow2(15) ans =4>> nextpow2(31)ans =5>> nextpow2(314444) ans =19>> nextpow2(31445) ans =15>> nextpow2(314445) ans =19>> nextpow2(314645) ans =19>> power(2,19)ans =524288>> x=314444x =314444>> power(2,19)-x ans =209844>> log2(10)ans =3.3219>> log10(10)ans =1>> 10*log10(2010*log10(20|错误: 表达式或语句不正确--可能(、{ 或[ 不对称。
>> 10*log10(2)ans =3.0103>> 20*log10(5^0.5)ans =6.9897>> 20*log10(1/2^0.5)ans =-3.0103>> %5^0.5 ; sqrt(5) ; sqrtm(5)>>>> a=[1 2 3 4 ]a =1 2 3 4>> roots(a)ans =-1.6506 + 0.0000i-0.1747 + 1.5469i-0.1747 - 1.5469i>> %X^3+2*x^2+3*x^1+4=0>> real(roots_a)未定义函数或变量'roots_a'。
是不是想输入:>> real(roots)错误使用roots (line 22)输入参数的数目不足。
>> r=roots(a)r =-1.6506 + 0.0000i-0.1747 + 1.5469i-0.1747 - 1.5469i>> real(r)ans =-1.6506-0.1747-0.1747>> ads(r)未定义与'double' 类型的输入参数相对应的函数'ads'。
>> abs(r)ans =1.65061.55671.5567>> t=0:0.1:7;>> x=2*atan(tan(t));>> plot(t,y)未定义函数或变量'y'。
>> plot(t,x)>> hold on>> phase=unwrap(x)phase =Columns 1 through 120 0.2000 0.4000 0.6000 0.8000 1.0000 1.2000 1.40001.6000 1.80002.0000 2.2000Columns 13 through 242.4000 2.6000 2.80003.0000 3.2000 3.4000 3.6000 3.80004.0000 4.2000 4.4000 4.6000Columns 25 through 364.80005.0000 5.2000 5.4000 5.6000 5.80006.0000 6.2000 6.4000 6.6000 6.80007.0000Columns 37 through 487.2000 7.4000 7.6000 7.8000 8.0000 8.2000 8.4000 8.60008.8000 9.0000 9.2000 9.4000Columns 49 through 609.6000 9.8000 10.0000 10.2000 10.4000 10.6000 10.8000 11.0000 11.2000 11.4000 11.6000 11.8000Columns 61 through 7112.0000 12.2000 12.4000 12.6000 12.8000 13.0000 13.2000 13.400013.6000 13.8000 14.0000>> plot(t,phase,"'r')plot(t,phase,"'r')|错误: 输入字符不是MATLAB 语句或表达式中的有效字符。