資源描述:
《matlab上機實驗答案》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、第一次上機內(nèi)容:習(xí)題2:A=cos(pi/3)-(9-sqrt(2))^(1/3)習(xí)題11:x=0:2*pi/124:2*pi;y=cos(x)*(0.5+3*sin(x)/(1+x.*x));plot(x,y);習(xí)題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);習(xí)題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,順時針旋轉(zhuǎn)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));第二次上機內(nèi)容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.正弦的軌跡動態(tài)表示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第三次上機內(nèi)容:制作一界面,上有二個輸入框、一個計算按鈕、一個顯示框、一個下拉選擇框,做二數(shù)的可選擇的四則運算。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);第四次上機內(nèi)容:1.P124第4、5、8、14題習(xí)題4:求代數(shù)方程3x^5+4x^4+7x^3+2x^2+9x+12=0的根。p=[3,4,7,2,9,12];r=roots(p
7、)?習(xí)題5:方程的根為x=[-3,-5,-8,-9],求對應(yīng)的x多項式的系數(shù)。x=[-3,-5,-8,-9];pp=poly(x)習(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)習(xí)題14:生成一個4*4的隨機矩陣,并對其進行三角分解和正交分解。A=rand(4,4)[L,U]=lu(A)[Q,R]=qr(A)2.編寫子函數(shù)可對任意兩個多項式進行加減操作(自動補零)functionc