1、MATLAB实验报告1 1实 验 报 告课程名称MATLAB语言及应用实验机房院系专业班级学号姓名机器号实验日期任课教师实验学时2实验成绩一实验名称:MATLAB程序阅读、调试、运行。 二实验目的和要求1、阅读程序,并给程序中的语句添加注释。2、调试、运行程序,并给出运行结果。三实验内容(一)给下列程序添加注释、调试运行,并给出运行结果。1、 x=1 2 3; 4 5 6; 7 8 9 y=0: 0.1 :1 w=eye(3) u=rand(3) u1=rand(2, 3) q=randn(3) q1=randn(2, 3) s=magic(3) ss=zeros(3) uu=ones(3)
2、2、A = 1 2 3 4; 5 6 7 8; 9 10 11 12;A(2,3) = 5B = A(2,1:3)A = A BA(:, 2) = A = A; 4 3 2 1A(1 4, :) = B = reshape(A, 4, 2)3、一元二次方程ax2 +bx+c=0的根。程序如下:a=input(a=?);b=input(b=?);c=input(c=?);d=b*b-4*a*c;x=(-b+sqrt(d)/(2*a),(-b-sqrt(d)/(2*a);disp(x1=,num2str(x(1),x2=,num2str(x(2)4、输入一个字符,若为大写字母,则输出其对应的小写字
3、母;若为小写字母,则输出其对应的大写字母;若为数字字符则输出其对应的数值,若为其他字符则原样输出。c=input(请输入一个字符,s);if c=A & c=a& c=0& c=9 disp(abs(c)-abs(0);else disp(c);end5、某商场对顾客所购买的商品实行打折销售,标准如下(商品价格用price来表示):price200 没有折扣 200price500 3%折扣 500price1000 5%折扣 1000price2500 8%折扣 2500price 0) sum mean=sum/cntend7、求100,200之间第一个能被21整除的整数。程序如下:for
4、 n=100:200if rem(n,21)=0 continueendbreakendN388、若一个数等于它的各个真因子之和,则称该数为完数,如6=1+2+3,所以6是完数。求1,500之间的全部完数。程序如下:for m=1:500s=0;for k=1:m/2if rem(m,k)=0s=s+k;endendif m=sdisp(m);endend(二)给下列图形程序添加注释、调试运行,并给出运行结果:1、 t=0:pi/100:2*pi;y=sin(t);subplot(1,2,1); plot(t,y)y2=sin(t-0.25);y3=sin(t-0.5);subplot(1,2
5、,2); plot(t,y,t,y2,t,y3); grid on2、 t = 0 : pi/20 : 2*pi; x, y = meshgrid ( t );subplot ( 2, 2, 1 )plot ( sin ( t ), cos ( t ) )axis equalsubplot ( 2, 2, 2 )z = sin ( x ) + cos ( y );plot ( t, z )axis ( 0 2*pi -2 2 )subplot ( 2, 2, 3 )z = sin ( x ).*cos ( y );plot ( t, z )axis ( 0 2*pi -1 1 )subplot
6、 ( 2, 2, 4 )z=(sin(x).2)-(cos(y).2);plot ( t, z )axis ( 0 2*pi -1 1 )3、 x1= (1:100)/100*pi*2;x2=(1:100)-20)/100*pi*2;y1=sin(1:100)/100*pi*2);y2=cos(1:100)/100*pi*2);x3=x1;x2;y3=y1;y2;subplot(2,2,1); plot(x1,y1, r*)subplot(2,2,2); plot(x2,y2, bo),grid onsubplot(2,2,3); plot(x3,y3)subplot(2,2,4); plot
7、(x1,y3*0.5), grid minor4、 X,Y=meshgrid(-8:5:8); R=sqrt(X.2+Y.2)+eps; Z=sin(R)./R;C=gradient(Z); subplot(131);surf(Z) subplot(132); surf(X,Y,Z);axis(-8 8 -8 8 -0.5 1) subplot(133); surf(X,Y,Z,C); axis(-8 8 -8 8 -0.5 1)5、 x = 0 : 0.2 : 12;y1 = Bessel ( 1, x );y2 = Bessel ( 2, x );y3 = Bessel ( 3, x );
8、figure ( 1 )subplot ( 2, 2, 1 )h = plot ( x, y1, x, y2, x, y3 );set ( h, LineWidth, 2, LineStyle, - ; : , -. )set ( h, Color , R; G ; B )axis ( 0 12 0.5 1 )grid onxlabel ( Time )ylabel ( Amplitude )legend ( h, First, Second , Third )title ( Bessel Functions) y, ix = min ( y1 );text ( x ( ix ), y, First Min rightarrow, HorizontalAlignment, right)四运行结果 五实验中存在问题及解决办法六实验结果五实验中存在问题及解决办法六实验结果五实验中存在问题及解决办法六实验结果五实验中存在问题及解决办法六实验结果
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2