>> title('\\ity\\rm=e^{-\\itat}','FontSize',12) >> legend('a=0.1','a=0.2','a=0.5')
22,建立一个简单模型,用信号发生器产生一个幅度为2V、频率为0.5Hz的正 弦波,并叠加一个0.1V的噪声信号,将叠加后的信号显示在示波器上并传送到工作空间。
23,编制一个解数论问题的函数文件:取任意整数,若是偶数,则用2除,否则乘3加1,重复此过程,直到整数变为1。 答:function c=collatz(n) % collatz
% Classic “3n+1” Ploblem from number theory
c=n;
while n>1
if rem(n,2)==0 n=n/2; else
n=3*n+1; end c=[c n]; end 24,
?4矩阵a??7???3254?6??4?9??,计算a的行列式和逆矩阵。
答:求行列式:
>> a=[4,2,-6;7,5,4;3,4,9];
>> det(a) ans =
-64
求逆矩阵:
>> a=[4,2,-6;7,5,4;3,4,9]; >> inv(a) ans =
-0.4531 0.6562 -0.5937 0.7969 -0.8437 0.9062 -0.2031 0.1562 -0.0937 25, 用符号函数法求解方程at2+b*t+c=0。
答:>>r=solve(?a*t^2+b*t+c=0?,t) r=
1/2/a*(-b+(b^2-4*a*c)^(1/2)) 1/2/a*(-b-(b^2-4*a*c)^(1/2))
二、选答题(在下列题中选答5题):
1. 有一组测量数据如下表所示,数据具有y=x2的变化趋势,用最小二乘法求 解y。
答 :>> x=[1 1.5 2 2.5 3 3.5 4 4.5 5]'
>> y=[-1.4 2.7 3 5.9 8.4 12.2 16.6 18.8 26.2]' >> e=[ones(size(x)) x.^2] >> c=e\\y
>> x1=[1:0.1:5]';
>> y1=[ones(size(x1)),x1.^2]*c; >> plot(x,y,'ro',x1,y1,'k')
2.
?af???ax?ex2log(x)??x?sin(x)?1, 用符号微分求df/dx。
答: >> syms a x;
>> f=[a, x^2, 1/x; exp(a*x), log(x), sin(x)]; >> df=diff(f) df =
[ 0, 2*x, -1/x^2] [ a*exp(a*x), 1/x, cos(x)] 3.
z?xe?x?y22,当x和y的取值范围均为-2到2时,用建立子窗口的方法在同
一个图形窗口中绘制出三维线图、网线图、表面图和带渲染效果的表面图。 答:x=-2:0.1:2;
y=x;
z=x.*exp(-x.^2 - y.^2); figure(1)
subplot(2,2,1); plot3(x,y,z); %三维线图、 [x,y]=meshgrid(x,y); z=x*exp(-x^2 - y^2);
subplot(2,2,2); mesh(x,y,z);%网线图 subplot(2,2,3); surf(x,y,z); %表面图 subplot(2,2,4);
surf(x,y,z,'FaceColor','green','EdgeColor','none'); %表面图 camlight left; lighting phong alpha(.5)
4.用subplot语句在一个图形窗口上开多个大小不等的子窗口进行绘图并添加注
释,见图。图形具体内容及各图所占位置可自选。
答: >> subplot('position',[0.1,0.15,0.3,0.65])
>> hist(randn(1,1000),20); >> xlabel('直方图')
>> subplot('position',[0.45,0.52,0.25,0.28]) >> [xp,yp,zp]=peaks;
>> contour(xp,yp,zp,15,'k') >> hold on
>> pcolor(xp,yp,zp) >> shading interp >> hold off >> axis off
>> text(-1.2,-4,'伪彩色图')
>> subplot('position',[0.72,0.5,0.25,0.3]) >> sphere(25);
>> axis equal,axis([-0.75,0.75,-0.75,0.75,-0.75,0.75]) >> light('Position',[1 3 2]); >> light('Position',[-3 -1 3]); >> material shiny >> axis off
>> text(-0.8,-0.7,-1,'三维图')
>> subplot('position',[0.45,0.15,0.5,0.25]) >> t=0:pi/15:pi;
>> y=sin(4*t).*sin(t)/2;
>> plot(t,y,'-bs','LineWidth',2,... %设置线型
'MarkerEdgeColor','k',... %设置标记点边缘颜色 'MarkerFaceColor','y',... %设置标记点填充颜色 'MarkerSize',5)
>> axis([0,3.14,-0.5,0.5])
>> xlabel('带标记点的线图')