MATLAB考试复习点及例题(2)

2019-08-31 17:33

矩阵元素的修改

>> A=[1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16] A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 >> A(1,1) ans = 1 >> A(2,3) ans = 7

>> A(1,1)=0;A(2,2)=A(1,2)+A(2,1);A(4,4)=cos(0); >> A A = 0 2 3 4 5 7 7 8 9 10 11 12 13 14 15 1

矩阵的函数

a.矩阵的基本变换函数

>> A=[3,3,5;2,4,6;7,8,9] %创建方阵 A A =

3 3 5 2 4 6 7 8 9

>> inv(A) %矩阵的逆(A必须为非奇异方阵) ans =

0.5000 -0.5417 0.0833 -1.0000 0.3333 0.3333 0.5000 0.1250 -0.2500 >> A‘ %矩阵的转置 ans =

3 2 7 3 4 8 5 6 9

求值:

>> a=[1,2,3,4] a =

1 2 3 4 >> b=[1,1;1,1] b =

1 1 1 1

>> polyvalm(a,4) % x=4时多项式的值 ans =

112 %与polyval(a,4)结果相同 >> polyval(a,b) %数组运算 ans =

10 10 10 10

>> polyvalm(a,b) %矩阵运算 ans =

15 11 11 15

多项式拟合:

>> x=0:pi/20:pi/2; >> y=sin(x);

>> [p,s]=polyfit(x,y,5); >> x1=0:pi/30:pi*2; >> y1=sin(x1);

>>y2=p(1)*x1.^5+p(2)*x1.^4+p(3)*x1.^3+p(4)*x1.^2+p(5)*x1+p(6); >> plot(x1,y1,'b-',x1,y2,'r*')

>> legend('Original curve','Fitted curve') >> axis([0,7,-1.2,4])

用命令 plot(y)绘曲线,其中 y=[5 3 4 9 0 2 3]。

y=[5 3 4 9 0 2 3];

plot(y)

用命令 plot(x,y)绘制函数 y=cos(x)在两个周期内的图形。

x=0:0.01:2*pi;

y=cos(x);

plot(x,y)

在同一图形窗口中用命令 plot(x,y)绘出正弦余弦函数的图形。

x=0:0.01:2*pi;

y=[sin(x);cos(x)];

plot(x,y)

用命令plot(Y)绘制矩阵 Y=[5 4 3 8 9 10;3 4 4 5 8 2 ;8 12 13 21 18 25 ;9 8 8

9 6 7]的图形。

Y=[5 4 3 8 9 10;3 4 4 5 8 2 ;8 12 13 21 18 25 ;9 8 8 9 6 7];

对数坐标曲线命令

绘制二维对数坐标曲线的命令semilogx、semilogy 和 loglog,其用法和函数 plot 相同。

函数 semilogx 横坐标为对数坐标;函数 semilogy 纵坐标为对数坐标; 函数loglog 横、纵坐标均为对数坐标。 绘制正弦函数的对数坐标曲线。 t=0.1:0.1:3*pi; y=sin(t); figure(1)

semilogx(t,y)

grid on %为图形窗口添加网格 figure(2) semilogy(t,y) figure(3)

y?在同一图形窗口中用不同的绘图函数绘制同一函数曲线

的双 y 轴图形。x=0:0.1:6; y=sqrt(x); plotyy(x,y,x,y,’semilogy’,’plot’)

x

用 subplot 函数把两种不同的图形综合在一个图形窗口中。

subplot(2,2,1) t=0.1:0.1:2*pi; y=sin(t); semilogx(t,y) grid on

subplot(2,2,2) t=0:0.1:4*pi; y=sin(t); plot(t,y)

subplot(2,2,3) x=1:0.01:5; y=exp(x);

plotyy(x,y,x,y,’semilogx’,’plot’) subplot(2,2,4) x=1:0.1:10; y=sqrt(x); plot(x,y,’:rd’)

坐标系的调整

实现坐标系的调整的命令是 axis 函数。

调用格式为: axis([xmin,xmax,ymin,ymax,zmin,zmax])

坐标的最小值( xmin,ymin,zmin)必须小于相应的最大值( xmax,ymax,zmax),否则 会出错。

自动坐标系与用 axis 函数调整后的坐标系的比较。 subplot(2,1,1) t=0:0.1:4*pi; y=sin(t); plot(t,y) subplot(2,1,2) t=0:0.1:4*pi; y=sin(t); plot(t,y)

axis([0,max(t),min(y),max(y)])

x、y、z 是向量时,plot3 命令的使用 t=0:0.1:8*pi;

plot3(sin(t),cos(t),t)

title(’绘制螺旋线’) %用命令 title 对图形主题进行标注 xlabel(’sin(t)’,’FontWeight’,’bold’,’FontAngle’,’italic’) ylabel(’cos(t)’,’FontWeight’,’bold’,’FontAngle’,’italic’) zlabel(’t’,’FontWeight’,’bold’,’FontAngle’,’italic’) %命令 zlabel 用来指定 z 轴的数据名称 grid on

x、y、z 都是矩阵时,plot3 命令的使用 [X,Y]=meshgrid(-pi:0.1:pi); Z=sin(X)+cos(Y); plot3(X,Y,Z)


MATLAB考试复习点及例题(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:新闻学导论 习题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: