资源描述:
《matlab上机实验答案》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、第一次上机内容:习题2:A=cos(pi/3)-(9-sqrt(2))^(1/3)习题11:x=0:2*pi/124:2*pi;y=cos(x)*(0.5+3*sin(x)/(1+x.*x));plot(x,y);习题13:x=-2:0.1:2;y=-2:0.1:2;[X,Y]=meshgrid(x,y);Z=X.*X.*exp(-X.^2-Y.^2);mesh(Z);习题15:N=2;t=0:0.1:2*pi;x=cos(t);y=sin(N*t+0);figure(1);subplot(2,2,1);plot(x,y);title('a=0');y=sin(N*t+pi/
2、3);subplot(2,2,2);plot(x,y);title('a=pi/3');y=sin(N*t+pi/2);subplot(2,2,3);plot(x,y);title('a=pi/2');y=sin(N*t+pi);subplot(2,2,4);plot(x,y);title('a=pi'); 3.选择一幅彩色图片,将其变作灰度图,再做上下颠倒、左右颠倒、逆时针90,顺时针旋转180度A=imread('1.jpg','jpg');A1=double(A);A1=[A1(:,:,1)+A1(:,:,2)+A1(:,:,3)]/3;imshow(uint8(A1)
3、);[h,w]=size(A1);B=A1;fori=1:h B(i,:)=A1(h+1-i,:);endimshow(uint8(B));C=A1;forj=1:w C(:,j)=A1(:,w+1-j);endimshow(uint8(C));D=eye(w,h);forj=1:w D(j,:)=A1(:,w+1-j);endimshow(uint8(D));E=A1;forj=1:w fori=1:h E(i,j)=A1(h+1-i,w+1-j); endendimshow(uint8(E));第二次上机内容1.鼠标
4、点击空白图面,实时显示鼠标点和轨迹figure(1);axis([-1,1,-1,1]);[x,y,b]=ginput(1);plot(x,y,'+r');string=sprintf('(%5.3f,%5.3f)',x,y);text(x,y,string);holdon;while(1) ifb==3 break; end x1=x; y1=y; [x,y,b]=ginput(1); plot(x,y,'+'); string=sprintf('(%5.3f,%5.3f)',x,y); text(x,y,string); plot([x1x],
5、[y1y],'+r-');end2.正弦的轨迹动态表示axis([0,4*pi,-1,1]);x=0;y=sin(x);holdon;x1=x;y1=y;forx=pi/24:pi/24:4*pi pause(0.1); y=sin(x); plot([x1x],[y1y]); x1=x; y1=y; end第三次上机内容:制作一界面,上有二个输入框、一个计算按钮、一个显示框、一个下拉选择框,做二数的可选择的四则运算。str1=get(handles.edit1,'string');number1=str2num(str1);str2=get(handles.edi
6、t2,'string');number2=str2num(str2);v=get(handles.popupmenu1,'value');switchvcase1m=number1+number2;case2m=number1-number2;case3m=number1*number2;case4m=number1/number2;end;set(handles.edit3,'string',m);第四次上机内容:1.P124第4、5、8、14题习题4:求代数方程3x^5+4x^4+7x^3+2x^2+9x+12=0的根。p=[3,4,7,2,9,12];r=roots(p
7、) 习题5:方程的根为x=[-3,-5,-8,-9],求对应的x多项式的系数。x=[-3,-5,-8,-9];pp=poly(x)习题8:a=[2,4,9;4,2,4;9,4,18],求其特征根和特征向量。A=[2,4,9;4,2,4;9,4,18];lambda=eig(A)[V,D]=eig(A)习题14:生成一个4*4的随机矩阵,并对其进行三角分解和正交分解。A=rand(4,4)[L,U]=lu(A)[Q,R]=qr(A)2.编写子函数可对任意两个多项式进行加减操作(自动补零)functionc