MATLAB基础

来源:互联网 发布:vscode debug webpack 编辑:程序博客网 时间:2024/06/05 10:50
>> 5^2ans =    25>> COS(pi)Undefined function 'COS' for input arguments of type 'double'.Did you mean:>> cos(pi)ans =    -1>> x=[1 2 3 4 5];>> y=[10 20 30 40 50];>> plot(x,y)>> isvarname timeans =  logical   1>> A=[3,1,-1;1,2,4;-1,4,5];>> B=[3.6,2.1,-1.4];>> X=A/BX =    0.7398    0.1138   -0.1138>> x=0:6x =     0     1     2     3     4     5     6>> x=0:0.01:6;>> y=[sin(1*x);sin(1*x^2);sin((1*x)^2)];Error using  ^ One argument must be a square matrix and the other must be ascalar. Use POWER (.^) for elementwise power.>>  y=[sin(1*x);sin(1*x.^2);sin((1*x).^2)];>> plot(x,y)>> (12+2*(7-4))/3^2ans =     2>> z1=3+4i;>> z2=1+2i;>> z3=2*e^(pi*i/6);Undefined function or variable 'e'.>> z3=2e^(pi*i/6); z3=2e^(pi*i/6);    ↑Error: Unexpected MATLAB operator.>> z3=2*exp(pi*i/6);>> z=(z1*z2)/z3;>> zz =   0.3349 + 5.5801i>> x=0:0.01:15;>> y=[sin(1*x);cos(1:x);1*exp(x),x^2];Error using  ^ One argument must be a square matrix and the other must be ascalar. Use POWER (.^) for elementwise power.>> y=[sin(1*x);cos(1:x);1*exp(x),x.^2];Error using vertcatDimensions of matrices being concatenated are not consistent.>> y=[sin(1*x);cos(1:x);1.*exp(x),x.^2];Error using vertcatDimensions of matrices being concatenated are not consistent.>> y=[sin(1*x);cos(1*x);1.*exp(x),x.^2];Error using vertcatDimensions of matrices being concatenated are not consistent.>> y=[sin(1*x);cos(1:x);1.*exp(x);x.^2];>> plot(x,y)>> y=[sin(1*x);cos(1*x);1*exp(x);x.^2];>> plot(x,y)>> plot(x,y)>> t=0:0.01:4*pi;>> y=[exp(-t/3)*sin(3*t);exp(-t/3)];Error using  * Inner matrix dimensions must agree.>> x=0:pi/10:2*pi;>> y=sin(2.*x)+cos(x);>> plot(x,y,'r-','LineWidth',1.5);xlabel('x'),ylable('y(x)';grid on legend('y=sin(2*x)+cos(x)'),1) plot(x,y,'r-','LineWidth',1.5);xlabel('x'),ylable('y(x)';grid on legend('y=sin(2*x)+cos(x)'),1)                                                         ↑Error: Unbalanced or unexpected parenthesis or bracket.>> )plot(x,y,'r-','LineWidth',1.5);xlabel('x'),ylable('y(x)');grid on legend('y=sin(2*x)+cos(x)'),1) )plot(x,y,'r-','LineWidth',1.5);xlabel('x'),ylable('y(x)');grid on legend('y=sin(2*x)+cos(x)'),1) ↑Error: Unbalanced or unexpected parenthesis or bracket.>> plot(x,y,'r-','LineWidth',1.5);xlabel('x'),ylable('y(x)');grid on legend('y=sin(2*x)+cos(x)'),1) plot(x,y,'r-','LineWidth',1.5);xlabel('x'),ylable('y(x)');grid on legend('y=sin(2*x)+cos(x)'),1)                                                                                                ↑Error: Unbalanced or unexpected parenthesis or bracket.>> plot(x,y,'r-','LineWidth',1.5);xlabel('x'),ylable('y(x)');grid on legend('y=sin(2*x)+cos(x)'),1); plot(x,y,'r-','LineWidth',1.5);xlabel('x'),ylable('y(x)');grid on legend('y=sin(2*x)+cos(x)'),1);                                                                                                ↑Error: Unbalanced or unexpected parenthesis or bracket.>>  plot(x,y,'r-','LineWidth',1.5);xlabel('x'),ylable('y(x)');grid on);Undefined function or variable 'ylable'.>> legend('y=sin(2*x)+cos(x)',1)Warning: There is no axes with which to associate a legend. > In legend (line 204) ans =   0×0 empty GraphicsPlaceholder array.>> legend('y=sin(2x)+cos(x)',1);Warning: There is no axes with which to associate a legend. > In legend (line 204) >> plot(x,y)>> xa=-2:0.2:2;>> ya=xa;>> [x,y]=meshgrid(xa,ya);>> %生成网格数据>> %计算纵轴数据>> z=x.*exp(-x.^2-y.^2);>> mesh(x,y,z)>> xa=-8:0.1:8;>> ya=-8:0.1:8ya =  Columns 1 through 7   -8.0000   -7.9000   -7.8000   -7.7000   -7.6000   -7.5000   -7.4000  Columns 8 through 14   -7.3000   -7.2000   -7.1000   -7.0000   -6.9000   -6.8000   -6.7000  Columns 15 through 21   -6.6000   -6.5000   -6.4000   -6.3000   -6.2000   -6.1000   -6.0000  Columns 22 through 28   -5.9000   -5.8000   -5.7000   -5.6000   -5.5000   -5.4000   -5.3000  Columns 29 through 35   -5.2000   -5.1000   -5.0000   -4.9000   -4.8000   -4.7000   -4.6000  Columns 36 through 42   -4.5000   -4.4000   -4.3000   -4.2000   -4.1000   -4.0000   -3.9000  Columns 43 through 49   -3.8000   -3.7000   -3.6000   -3.5000   -3.4000   -3.3000   -3.2000  Columns 50 through 56   -3.1000   -3.0000   -2.9000   -2.8000   -2.7000   -2.6000   -2.5000  Columns 57 through 63   -2.4000   -2.3000   -2.2000   -2.1000   -2.0000   -1.9000   -1.8000  Columns 64 through 70   -1.7000   -1.6000   -1.5000   -1.4000   -1.3000   -1.2000   -1.1000  Columns 71 through 77   -1.0000   -0.9000   -0.8000   -0.7000   -0.6000   -0.5000   -0.4000  Columns 78 through 84   -0.3000   -0.2000   -0.1000         0    0.1000    0.2000    0.3000  Columns 85 through 91    0.4000    0.5000    0.6000    0.7000    0.8000    0.9000    1.0000  Columns 92 through 98    1.1000    1.2000    1.3000    1.4000    1.5000    1.6000    1.7000  Columns 99 through 105    1.8000    1.9000    2.0000    2.1000    2.2000    2.3000    2.4000  Columns 106 through 112    2.5000    2.6000    2.7000    2.8000    2.9000    3.0000    3.1000  Columns 113 through 119    3.2000    3.3000    3.4000    3.5000    3.6000    3.7000    3.8000  Columns 120 through 126    3.9000    4.0000    4.1000    4.2000    4.3000    4.4000    4.5000  Columns 127 through 133    4.6000    4.7000    4.8000    4.9000    5.0000    5.1000    5.2000  Columns 134 through 140    5.3000    5.4000    5.5000    5.6000    5.7000    5.8000    5.9000  Columns 141 through 147    6.0000    6.1000    6.2000    6.3000    6.4000    6.5000    6.6000  Columns 148 through 154    6.7000    6.8000    6.9000    7.0000    7.1000    7.2000    7.3000  Columns 155 through 161    7.4000    7.5000    7.6000    7.7000    7.8000    7.9000    8.0000>> xa=-8:0.1:8;>> ya=-8:0.1:8;>> z=(sin((x^2+y^2)^(1/2)))/((x*2+y*2)^(1/2));>> mesh(x,y,z);Error using mesh (line 83)X, Y, Z, and C cannot be complex.>> [x,y]=meshgrid(xa,ya);>> z=(sin((x^2+y^2)^(1/2)))/((x*2+y*2)^(1/2));>>  mesh(x,y,z);Error using mesh (line 83)X, Y, Z, and C cannot be complex.>> z=(sin((x.^2+y.^2).^(1/2)))/((x*2+y*2).^(1/2));>> mesh(x,y,z);Error using mesh (line 83)X, Y, Z, and C cannot be complex.>> z=(sin((x.^2+y.^2).^(1/2)))/((x.*2+y.*2).^(1/2));>> mesh(x,y,z)Error using mesh (line 83)X, Y, Z, and C cannot be complex.>> xa=-8:0.1:8;>> ya=xa;>> [x,y]=meshgrid(xa,ya);>> z=(sin((x.^2+y.^2).^(1/2)))/((x.*2+y.*2).^(1/2));>> mesh(x,y,z);Error using mesh (line 83)X, Y, Z, and C cannot be complex.>> %mesh不能处理复数>> xa=-8:0.1:8;>> ya=xa;>> [x,y]=meshgrid(xa,ya);>> z=sin(sqrt(x*2+y*2))/(sqrt(x*2+y*2));>> mesh(x,y,z);Error using mesh (line 83)X, Y, Z, and C cannot be complex.>> xa=-8:0.1:8;>> ya=xa;>> [x,y]=meshgrid(xa,ya);>> z=(sin(sqrt(x^2+y^2)))/(sqrt(x^2+x^2));Warning: Matrix is singular to working precision. >> z=(sin(sqrt(x.^2+y.^2)))/(sqrt(x.^2+x.^2));Warning: Matrix is singular to working precision. >> %求矩阵的时候产生了奇异>> xa=-8:0.4:8;>> ya=xa;>> [x,y]=meshgrid(xa,ya);>> z=(sin(sqrt(x.^2+y.^2)))/(sqrt(x.^2+x.^2));Warning: Matrix is singular to working precision. >> z=(sin(sqrt(x.^2+y.^2)))./(sqrt(x.^2+x.^2));>> plot(x,y)>> mesh(x,y,z);>> %产生奇异就是因为不是z=a./b没有.>> A=[1 5 6;2 8 6;2 9 7];>> B=[4 8 3;5 2 1;7 6 9];>> A+Bans =     5    13     9     7    10     7     9    15    16>> A-B;>> A-Bans =    -3    -3     3    -3     6     5    -5     3    -2>> %如果语句后面不加;就不会出现结果>> A*Bans =    71    54    62    90    68    68   102    76    78>> A^2ans =    23    99    78    30   128   102    34   145   115>> AA =     1     5     6     2     8     6     2     9     7>> A^(-1)ans =    0.5000    4.7500   -4.5000   -0.5000   -1.2500    1.5000    0.5000    0.2500   -0.5000>> %点积>> dot(A,B)ans =    28   110    87>> %叉积>> cross(a,b)Undefined function or variable 'a'.Did you mean:>> cross(A,B)ans =     4    30    47     1    42   -33    -3   -54   -12>> %卷积>> conv(A,B)Error using conv (line 28)A and B must be vectors.>> AA =     1     5     6     2     8     6     2     9     7>> %转置>> x=A.'x =     1     2     2     5     8     9     6     6     7>> %画三维球体>> %elipsoid函数在三维立体空间画椭圆>> [x,y,x]=ellipsoid(8,9,10,2,2,2);>> surf(x,y,z);Error using surf (line 82)Data dimensions must agree.>> [x,y,z]=ellipsoid(8,9,10,2,2,2);>> surf(x,y,z);>> %直接画出了球体>> axis equal %保证各个维度长短一致>> axis([1 50 1 50 1 0])Error using matlab.graphics.axis.Axes/setValue must be a 1x2 vector of numeric type in which the second element islarger than the first and may be InfError in axis>LocSetLimits (line 279)        set(ax,...Error in axis (line 101)                LocSetLimits(ax(j),cur_arg,names);>> axis([1 50 1 50 1 0]);Error using matlab.graphics.axis.Axes/setValue must be a 1x2 vector of numeric type in which the second element islarger than the first and may be InfError in axis>LocSetLimits (line 279)        set(ax,...Error in axis (line 101)                LocSetLimits(ax(j),cur_arg,names);>> axis([1 50 1 50 1 0]);Error using matlab.graphics.axis.Axes/setValue must be a 1x2 vector of numeric type in which the second element islarger than the first and may be InfError in axis>LocSetLimits (line 279)        set(ax,...Error in axis (line 101)                LocSetLimits(ax(j),cur_arg,names);>> axis([1 50 1 50 1 0]);Error using matlab.graphics.axis.Axes/setValue must be a 1x2 vector of numeric type in which the second element islarger than the first and may be InfError in axis>LocSetLimits (line 279)        set(ax,...Error in axis (line 101)                LocSetLimits(ax(j),cur_arg,names);>> %画三维球体>> R=5;>> [x,y,z]=sphere(50);>> mesh(R*x,R*y,R*z)%上一步生成点 下一步画图>> >> 
原创粉丝点击