matlab上機(jī)習(xí)題詳解_試題答案_第1頁
matlab上機(jī)習(xí)題詳解_試題答案_第2頁
matlab上機(jī)習(xí)題詳解_試題答案_第3頁
matlab上機(jī)習(xí)題詳解_試題答案_第4頁
matlab上機(jī)習(xí)題詳解_試題答案_第5頁
已閱讀5頁,還剩32頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、P第一次實(shí)驗(yàn)答案 1 設(shè)要求以0.01秒為間隔,求出y的151個(gè)點(diǎn),并求出其導(dǎo)數(shù)的值和曲線。clcclearx=0:0.01:1.5;y=sqrt(3)/2*exp(-4*x).*sin(4*sqrt(3)*x+pi/3)y1=diff(y)subplot(2,1,1)plot(x,y)subplot(2,1,2)plot(x(1:150),y1)2繪制極坐標(biāo)系下曲線(a,b,n自定數(shù)據(jù))clccleara=10;b=pi/2;n=5;theta=0:pi/100:2*pi;rho=a*cos(b+n*theta);polar(theta,rho)3. 列出求下列空間曲面交線的程序clccle

2、arx=-5:0.5:5;X,Y=meshgrid(x);z1=X.2-2*Y.2;z2=X.*2-Y.*3;xlabel(x)ylabel(y)zlabel(z)surf(X,Y,z1)hold onsurf(X,Y,z2)k=find(abs(z1-z2)2 error(輸入量太多。);else S=N*R*R*sin(2*pi/N)/2; L=2*N*R*sin(pi/N); plot(x,y,str) endaxis equal squarebox on3、編寫一個(gè)學(xué)生成績管理的程序,完成下列功能:(1) 構(gòu)造一個(gè)學(xué)生結(jié)構(gòu),包括學(xué)生的姓名,課程名稱(限M門),考試成績和平均值等域; (

3、2) 從鍵盤上,連續(xù)輸入N個(gè)學(xué)生的情況,分別將這些學(xué)生的情況填入到相應(yīng)的域,若域中沒有值即為空或0,并分別計(jì)算其平均值寫入到其平均值域。(3) 根據(jù)平均值排序(由高到低),并輸出學(xué)生的姓名和平均值。clcclearn=input(please input students number:);for x=1:n number(x)=struct(name,Curriculum1,Curriculum2,Curriculum3,Average,);endfor i=1:n number(i).name=input(name:,s); number(i).Curriculum1=input(plea

4、se input the scoresnCurriculum1:); number(i).Curriculum2=input(Curriculum2:); number(i).Curriculum3=input(Curriculum3:); number(i).Average=(number(i).Curriculum1+number(i).Curriculum2+number(i).Curriculum3)/3; disp(the average is:) disp(num2str(number(i).Average)end NameCell=cell(1,n);Array=1,n;for

5、i=1:n NameCell(1,i)=number(i).name; Array(i)=number(i).Average;endfor j=1:(n-1) iptr = j; for i=(j+1):n if Array(i)Array(iptr) %比較相鄰前后大小 iptr=i; end end if j=iptr %若后面比前面大,互換 Name=NameCell(1,i); NameCell(1,i)=NameCell(1,j); NameCell(1,j)=Name; average=Array(i); Array(i)=Array(j); Array(j)=average; j

6、=1; iptr=j; endenddisp(成績排序如下:)for i=1:n disp(strcat(名次: ,num2str(i), 名字 ,NameCell(1,i), 平均成績: ,num2str(Array(i)end 4、使用句柄圖像對(duì)象繪制曲線:y=2e-0.5xcos(x),同時(shí)對(duì)曲線進(jìn)行標(biāo)注和修飾。x=-12:0.02:12y=2*exp(-0.5)*x).*cos(pi*x)h_f=figure(Position,200 300 300 300,menubar,none)h_a1=axes(position,0.1,0.1,.8,.8)h_t=title(h_a1,函數(shù)=

7、2*exp(-0.5)*x).*cos(pi*x)h_1=line(x,y)set(gca,xtick,(-6)*pi (-4)*pi (-2)*pi 0 (2)*pi (4)*pi (6)*pi)set(gca,xticklabel,(-6)*pi, (-4)*pi, (-2)*pi, 0, (2)*pi, (4)*pi,(6)pi)set(gca,xgrid,on,ygrid,on)set(h_1,linewidth,2)set(get(h_t,parent),color,y)h_anm1=annotation(gcf,rectangle,0.1 0.5 .8 0.4,FaceAlpha,

8、.7,FaceColor,red)第三次試驗(yàn)答案1、做一個(gè)帶按鈕的界面,當(dāng)按動(dòng)“播放”按鈕時(shí)調(diào)入聲音文件并播放,顯示聲音波形,并建立一個(gè)用于關(guān)閉界面的按鈕對(duì)象。(提示,找一個(gè).wav文件,簡單起見可以在windows目錄下找一個(gè)文件,將其放在當(dāng)前工作目錄下或搜索路徑上。具體用法請(qǐng)參照:y,f,b=wavread(*.wav); % 讀入聲音文件sound(y,f,b) % 由聲卡播放聲音plot(y) % 畫出波形2、創(chuàng)建一個(gè)用于繪圖參數(shù)選擇的菜單對(duì)象,其中包含三個(gè)選項(xiàng)LineStyle、Marker和Color,每個(gè)選項(xiàng)下面又包含若干的子項(xiàng)分別可以進(jìn)行選擇圖線的類型、標(biāo)記點(diǎn)的類型和顏色 (每

9、個(gè)子項(xiàng)不少于3個(gè)),當(dāng)按下“繪圖”按鈕時(shí),根據(jù)選項(xiàng)繪制正弦曲線(缺省時(shí)為藍(lán)色無標(biāo)記實(shí)線)。(注意使用全球變量)function varargout = shiyan32(varargin)% SHIYAN32 MATLAB code for shiyan32.fig% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, shiyan32_OpeningFc

10、n, . gui_OutputFcn, shiyan32_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);end if nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT E

11、DIT % - Executes just before shiyan32 is made visible.function shiyan32_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and

12、user data (see GUIDATA)% varargin command line arguments to shiyan32 (see VARARGIN) % Choose default command line output for shiyan32handles.output = hObject; % Update handles structureguidata(hObject, handles); % UIWAIT makes shiyan32 wait for user response (see UIRESUME)% uiwait(handles.figure1);g

13、lobal cc=bglobal ll=-global mm= % - Outputs from this function are returned to the command line.function varargout = shiyan32_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a fu

14、ture version of MATLAB% handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structurevarargout1 = handles.output; % -function Untitled_1_Callback(hObject, eventdata, handles)% hObject handle to Untitled_1 (see GCBO)% eventdata reserved - to be de

15、fined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global l % -function Untitled_8_Callback(hObject, eventdata, handles)% hObject handle to Untitled_8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with hand

16、les and user data (see GUIDATA)global m % -function color_Callback(hObject, eventdata, handles)% hObject handle to color (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global c % -function Untitled_14_Callback(h

17、Object, eventdata, handles)% hObject handle to Untitled_14 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global cc=r % -function Untitled_15_Callback(hObject, eventdata, handles)% hObject handle to Untitled_15

18、(see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global cc=b % -function Untitled_16_Callback(hObject, eventdata, handles)% hObject handle to Untitled_16 (see GCBO)% eventdata reserved - to be defined in a future

19、version of MATLAB% handles structure with handles and user data (see GUIDATA)global cc=g % -function Untitled_17_Callback(hObject, eventdata, handles)% hObject handle to Untitled_17 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user

20、data (see GUIDATA) global cc=y% -function Untitled_10_Callback(hObject, eventdata, handles)% hObject handle to Untitled_10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global mm=o % -function Untitled_11_Callb

21、ack(hObject, eventdata, handles)% hObject handle to Untitled_11 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global mm=* % -function Untitled_13_Callback(hObject, eventdata, handles)% hObject handle to Untitle

22、d_13 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) global mm=d % -function Untitled_4_Callback(hObject, eventdata, handles)% hObject handle to Untitled_4 (see GCBO)% eventdata reserved - to be defined in a fut

23、ure version of MATLAB% handles structure with handles and user data (see GUIDATA)global ll=- % -function Untitled_5_Callback(hObject, eventdata, handles)% hObject handle to Untitled_5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and use

24、r data (see GUIDATA)global ll=- % -function Untitled_7_Callback(hObject, eventdata, handles)% hObject handle to Untitled_7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global ll=-. % - Executes on button press

25、 in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global s global l global m global cx=0:0.1:2*pi;y=sin(x);s

26、=strcat(l,m,c);plot(x,y,s)2. 設(shè)和是兩個(gè)10行10列的矩陣(數(shù)組),試說明命令A(yù)*B, A/B, AB, A.*(B.A), A./B, A.B和sin(A).*exp(B)的涵義。A,B的矩陣乘法,矩陣A乘以B的逆,矩陣B乘以A的逆,B的每個(gè)元素的對(duì)應(yīng)A次冪乘以A對(duì)應(yīng)的每個(gè)元素A的每個(gè)元素除以B對(duì)應(yīng)的每個(gè)元素,B的每個(gè)元素除以A對(duì)應(yīng)的每個(gè)元素,A的每個(gè)元素的正弦與B對(duì)應(yīng)的每個(gè)元素的指數(shù)求積,3. 設(shè)A為數(shù)組,B為一個(gè)行數(shù)大于3的數(shù)組,請(qǐng)給出(1)刪除A的第4、8、12三列的命令; (2)刪除B的倒數(shù)第3行的命令;(3)求符號(hào)極限的命令集; (4)求的3階導(dǎo)數(shù)的命令

27、集;(5)計(jì)算定積分的命令,并給出計(jì)算結(jié)果(!)A(:,4 8 12)=(2)B(end-2)=(3)syms m n xlimit(tan(m*x)/(n*x)(4)syms x yy=atan(x+3)/(x-2)-log(1+exp(-2)*x)diff(y,3)(5)syms xint(abs(x)+sin(x)*x2,-1,1)得分 三基本編程題(每小題10分,共30分)1. Write a program to compute the following expressions;Here, we suppose the variable x has existed in the w

28、orkspace.for i=1:10 for j=1:10xbar(i)=xbar(i)+x(i,j); end xbar(i)=xbar(i)/10;endfor i=1:10 for j=1:10 t1=0;t2=0;t3=0; for k=1:3 t1=t1+(x(i,k)-xbar(i)*(x(j,k)-xbar(j); t2=t2+(x(i,k)-xbar(i)2; t3=t3+(x(j,k)-xbar(j)2; end r2(i,j)=t1/sqrt(t2*t3); endendr2 2. (1) Using plot() function to plot the curves

29、of and in the range of , let their color are red and green respectively, and add the grid to the figure. (2) Using fplot() function and ezplot() function to plot above-mentioned (上述的) curves respectively.(1)x=-2*pi:pi/100:2*pi;y=(sin(2*x)+cos(3*x).*exp(-2*x);z=sin(x)/x;plot(x,y,r,x,z,g)(2)fplot(sin(

30、2*x)+cos(3*x).*exp(-2*x), sin(x)/x,-2*pi 2*pi) 3. Plot the 3D mesh figure and 3D surface figure of the functionin the range of and , respectively.x=-4:1/100:4;y=-4:1/100:4;z=9(1-x)2*exp(-x2/2-(y+1)2)mesh(x,y,z);surf(x,y,z);得分 四綜合編程題(每小題11分,共22分) 1. Write a function program to compute the following f

31、unctionand call this function program to compute the value of in main program or command window, there, shows the factorial (階乘) of . 提示:對(duì)x取整的函數(shù)有fix(x), floor(x), round(x) 和ceil(x) .fuction y=f1(x) %f1.mif x-fix(x)= =0y=prod(1:abs(2*x);elsey=4*sin(2*x)+x1.8;y=f1(-4)+f1(3)-f1(14.37)2.Write a program

32、to compute the sample mean,and the sample skewness (偏度) .for the following three case:(1) n and exist in Workspace of Matlab. It is no any limit;(2) n and are unknown variables. Please input x by keyboard one by one, and give a mark of end the data input. Examinees can use loop statement and length(

33、) function and input() function, but cannot use mean() function, std() function, and var() function directly (可以使用循環(huán)語句和length()函數(shù)、input()函數(shù)等進(jìn)行編程,但不能直接使用mean()、std()和var()等函數(shù)). (1)s=0;for i=1:ns=s+x(i);endxbar=s/nm=0;for i=1:nm=m+(x(i)-xbar)3;endske=m/n(2)x(1)=input(請(qǐng)輸入x );i=1;s=0;while(x(i)=a) s=s+x

34、(i); i=i+1; x(i)=input(請(qǐng)輸入x ,輸a結(jié)束);endxbar=s/(i-1)m=0;for j=1:i-1m=m+(x(i)-xbar)3;endske=m/(i-1)一、填空題1、MATLAB常用操作界面包括 命令窗口 、工作空間窗口、 命令歷史窗口 、當(dāng)前目錄窗口 、內(nèi)存數(shù)組編輯器、M文件編輯/調(diào)試器、幫助導(dǎo)航/瀏覽器、圖形窗口等。2、MATLAB中Inf或inf表示 無窮大 、NaN或nan表示 不是一個(gè)數(shù) 、nargout表示 函數(shù)輸出變量數(shù)目 。3、工作空間瀏覽器主要用于內(nèi)存變量的 查閱 、 保持 和 編輯 。4、MATLAB實(shí)現(xiàn)將全下標(biāo)轉(zhuǎn)換為單下標(biāo)的指令為

35、sub2ind 、據(jù)單下標(biāo)換算出全下標(biāo)的指令為 ind2sub 。5、MATLAB中clf用于 清除圖形窗口 、clc用于 清除指令窗口中顯示內(nèi)容 、clear用于 清除MATLAB工作空間中保存的變量 。二、簡答題(每題5分,共20分) 1、簡述MATLAB歷史指令窗的主要作用。答:歷史指令窗記錄著用戶在MATLAB指令窗中所輸入過的所有指令。歷史記錄包括:每次開啟MATLAB的時(shí)間,每次開啟MATLAB后在指令窗中運(yùn)行過的所有指令。應(yīng)用功能有單行或多行指令的復(fù)制和運(yùn)行、生成M文件等。2、簡述MATLAB函數(shù)的基本結(jié)構(gòu)。答:典型M函數(shù)文件的結(jié)構(gòu):函數(shù)申明行、H1行、在線幫助文本區(qū)、編寫和修改

36、記錄、函數(shù)體。3、簡述繪制二維圖形的一般步驟。繪制二維圖形的一般步驟為:曲線數(shù)據(jù)準(zhǔn)備、選定圖形窗及子圖位置、調(diào)用二維曲線繪圖指令、設(shè)置軸的范圍、坐標(biāo)分格線、圖形注釋、圖形的精細(xì)操作。三、閱讀程序并回答問題(每題4分,共28分)1、寫出下列指令運(yùn)行結(jié)果。A=zeros(2,4); A(:)=1:8; s=2 3 5;A(s)Sa=10 20 30A(s)=Saans = 2 3 5Sa = 10 20 30A = 1 20 30 7 10 4 6 8 2、寫出下列指令運(yùn)行結(jié)果。A=reshape(1:16,2,8) reshape(A,4,4) s=1 3 6 8 9 11 14 16;A(s)

37、=0A = 1 3 5 7 9 11 13 15 2 4 6 8 10 12 14 16ans = 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16A = 0 0 5 7 0 0 13 15 2 4 0 0 10 12 0 03、寫出下列指令運(yùn)行結(jié)果。A=1,2;3,4; B=-1,-2;2,1;S=3;A.*Bans = -1 -4 6 4A*Bans = 3 0 5 -2S.*Aans = 3 6 9 12S*Bans =-3 -6 6 34、下面的函數(shù)主要完成什么功能? function f=factor(n)if n=a&ch=z); ch(k)=ch(k)

38、-(a-A); char(ch) subch =ABc12revch =9gF65e4d321cBAans =ABC123D4E56FG9ans = 46、寫出下列指令運(yùn)行結(jié)果。A(1,1)=this is cell;A1,2=1 2 3;4 5 6;A2,1=1+2*i;A2,2=A1,21+(A1,21(1,1)+A1,21(2,2);celldisp(A)A1,1 = this is cellA2,1 = 1.0000 + 2.0000iA1,21 = 1 2 3 4 5 6A2,2 = 7 8 9 10 11 127、下面的程序完成功能是什么?t=0:pi/50:4*pi;y0=exp

39、(-t/3);y=exp(-t/3).*sin(3*t);plot(t,y,-r,t,y0,:b,t,-y0,:b)xlabel(bfit t);ylabel(bfit y);grid on;繪制圖形如下:四、編程題(32分)1、用命令來創(chuàng)建GUI并繪制方程y=ax2 +bx+c圖形,需要顯示繪圖結(jié)果的坐標(biāo)系窗口,還能輸入a、b、c的值和x的取值范圍,同時(shí)用命令設(shè)置所以對(duì)象的屬性。2、在同一圖上分別用紅色實(shí)線和綠色虛線繪制y1=sin(x)和y2=cos(x)在區(qū)間0,4*pi的曲線,并用星號(hào)*標(biāo)出兩條曲線的交點(diǎn)以及建立圖例。(5分)x=0:0.01:4*pi;y1=sin(x);y2=cos

40、(x);z=find(abs(y1-y2)0.007);plot(x,y1,r.-,Linewidth,2,Markersize,1);axis(-1.5,15,-1.5,1.5);hold on plot (x,y2,g.:,Linewidth,2,Markersize,1);n=size(z);plot(x(z),y1(z),k*,Markersize,15);3、某商場(chǎng)對(duì)顧客所購買的商品實(shí)行打折銷售,標(biāo)準(zhǔn)如下(商品價(jià)格用price來表示): price200 沒有折扣 200price500 3%折扣 500price1000 5%折扣 1000price2500 8%折扣 2500price5000 10%折扣5000price 14%折扣輸入所售商品的價(jià)格,求其實(shí)際銷售價(jià)格。(5分)price=input(please input your price:);a=0;if price200 a=1;elseif price500 a=2;elseif price1000 a=3;elseif pric

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論