1、matlab上机习题详解试题答案matlab上机习题详解_试题答案clcclear P第一次实验答案 x=-2*pi:0.1: 2*pi; 3,y=cos(x).*(0.5+sin(x)*3./(1+x.2); ,4tsin43y,et,, 1( 设 plot(x,y,b*-); 23,title(绘图); xlabel(x坐标); 要求以0.01秒为间隔,求出y的151个点,ylabel(y坐标); 并求出其导数的值和曲线。 legend(原函数) clc gtext(y=cos(x)(0.5+3*sin(x)/(1+x2) clear x=0:0.01:1.5; y=sqrt(3)/2*e
2、xp(-4*x).*sin(4*sqrt(3)*x+pi/35、求下列联立方程的解 ) 3x,4y,7z,12w,4y1=diff(y) subplot(2,1,1) 5x,7y,4z,2w,3 plot(x,y) x,8z,5w,9subplot(2,1,2) plot(x(1:150),y1) ,6x,5y,2z,10w,8clc clear 2绘制极坐标系下曲线(a,b,n自定数据) a=3,4,-7,-12;5,-7,4,2;1,0,8,-5;-6,5,-2,10 ; ,,acosb,n, b=4,-3,9,-8; clc c=b/a; clear x=c(1,1) a=10; y=c
3、(1,2) b=pi/2; z=c(1,3) n=5; w=c(1,4) theta=0:pi/100:2*pi; rho=a*cos(b+n*theta); 6. 假设一曲线数据点为 polar(theta,rho) x = 0:2:4*pi; y = sin(x).*exp(-x/5); 3. 列出求下列空间曲面交线的程序 试将x 的间距调成 0.1,采用不同插值方法进行 22z,2x,3yz,x,2y2插值,并通过子图的形式将不同插值结果和原始数1 据点绘制在同一图形窗口。 clc clear clc x=-5:0.5:5; clear X,Y=meshgrid(x); x=0:2:4*
4、pi; z1=X.2-2*Y.2; y=sin(x).*exp(-x./5); z2=X.*2-Y.*3; x1=0:0.1:4*pi; xlabel(x) y01=interp1(x,y,x1,spline); ylabel(y) y02=interp1(x,y,x1,cubic); zlabel(z) y03=interp1(x,y,x1,nearest); surf(X,Y,z1) y04=interp1(x,y,x1); hold on subplot(3,2,1); surf(X,Y,z2) plot(x,y,o-); k=find(abs(z1-z2)2 a=input(输入密码:
5、) error(输入量太多。); while a=20120520 else disp(密码错误,请重新输入:) S=N*R*R*sin(2*pi/N)/2; clear L=2*N*R*sin(pi/N); a=input(输入密码:) plot(x,y,str) end end if a=20120520 axis equal square disp(密码输入正确!) box on end 3、编写一个学生成绩管理的程序,完成下列2、编写一个函数实现以下功能: 功能: a. 若没有实参输入变量,则用蓝色实线画出(1) 构造一个学生结构,包括学生的姓名,课半径为1的圆; 程名称(限M门),考
6、试成绩和平均值等域; 若有两个实参输入变量N,R,则用蓝色实b.(2) 从键盘上,连续输入N个学生的情况,分线画出外接半径为R的正N多边形; 别将这些学生的情况填入到相应的域,若域中d. 若有两个实参输出变量,则分别输出正多没有值即为空或0,并分别计算其平均值写入边形的面积S和周长L。 到其平均值域。 g. 如果输入变量多于三个或输出变量多于两(3) 根据平均值排序(由高到低),并输出学个则给出错误提示信息。 生的姓名和平均值。 (提示:外接半径为R的正N多边形参数 clc 式:t=0:2*pi/N:2*pi;x=R*sin(t);y=R*cos(t)当Nclear n=input(pleas
7、e input students number:); for x=1:n ?100时,可看作是半径为R的圆) number(x)=struct(name,Curriculum1, ,Curriculum2,Curriculum3,Averagefunction S,L=shiyan22(N,R,str) ,); end for i=1:n switch nargin number(i).name=input(name:,s); case 0 number(i).Curriculum1=input(please N=100;R=1;str=-b; input the scoresnCurricu
8、lum1:); case 1 R=1;str=-b; number(i).Curriculum2=input(Curriculum2:); case 2 set(h_1,linewidth,2) number(i).Curriculum3=input(Curriculum3:)set(get(h_t,parent),color,y) ; h_anm1=annotation(gcf,rectangle,0.1 0.5 .8 number(i).Average=(number(i).Curriculum1+nu0.4,FaceAlpha,.7,FaceColor,red) mber(i).Curr
9、iculum2+number(i).Curriculum3)/3; disp(the average is:) disp(num2str(number(i).Average) 第三次试验答案 end NameCell=cell(1,n); 1、做一个带按钮的界面,当按动“播放”按Array=1,n; for i=1:n 钮时调入声音文件并播放,显示声音波形,并 NameCell(1,i)=number(i).name; Array(i)=number(i).Average; 建立一个用于关闭界面的按钮对象。(提示,end for j=1:(n-1) iptr = j; 找一个.wav文件,简单
10、起见可以在windowsfor i=(j+1):n if Array(i)Array(iptr) %比较相邻前后目录下找一个文件,将其放在当前工作目录下大小? iptr=i; 或搜索路径上。具体用法请参照: end end y,f,b=wavread(*.wav); % 读入声音文 if j=iptr %若后面比前面大,互换 件 Name=NameCell(1,i); NameCell(1,i)=NameCell(1,j); sound(y,f,b) % 由声卡播放 NameCell(1,j)=Name; average=Array(i); 声音 Array(i)=Array(j); Arra
11、y(j)=average; plot(y) % 画出波形 j=1; iptr=j; end end disp(成绩排序如下:) for i=1:n disp(strcat(名次: ,num2str(i), 名字 2、创建一个用于绘图参数选择的菜单对象,,NameCell(1,i), 平均成绩: ,num2str(Array(i) 其中包含三个选项LineStyle、Marker和Color,end 每个选项下面又包含若干的子项分别可以进-0.5x4、使用句柄图像对象绘制曲线:y=2ecos(行选择图线的类型、标记点的类型和颜色 (每x),同时对曲线进行标注和修饰。 个子项不少于3个),当按下“
12、绘图”按钮时,根据选项绘制正弦曲线(缺省时为蓝色无标记x=-12:0.02:12 y=2*exp(-0.5)*x).*cos(pi*x) 实线)。(注意使用全球变量) h_f=figure(Position,200 300 300 300,menubar,none) function varargout = shiyan32(varargin) h_a1=axes(position,0.1,0.1,.8,.8) % SHIYAN32 MATLAB code for shiyan32.fig h_t=title(h_a1,函数 =2*exp(-0.5)*x).*cos(pi*x) % Begin
13、 initialization code - DO NOT EDIT h_1=line(x,y) gui_Singleton = 1; set(gca,xtick,(-6)*pi (-4)*pi (-2)*pi 0 gui_State = struct(gui_Name, (2)*pi (4)*pi (6)*pi) mfilename, . set(gca,xticklabel,(-6)*pi, (-4)*pi, gui_Singleton, (-2)*pi, 0, (2)*pi, (4)*pi,(6)pi) gui_Singleton, . set(gca,xgrid,on,ygrid,on
14、) gui_OpeningFcn, shiyan32_OpeningFcn, . % Get default command line output from handles gui_OutputFcn, structure shiyan32_OutputFcn, . varargout1 = handles.output; gui_LayoutFcn, , . gui_Callback, ); if nargin & ischar(varargin1) % gui_State.gui_Callback = -str2func(varargin1); - end function Untitl
15、ed_1_Callback(hObject, eventdata, handles) if nargout % hObject handle to Untitled_1 (see GCBO) varargout1:nargout = % eventdata reserved - to be defined in a gui_mainfcn(gui_State, varargin:); future version of MATLAB else % handles structure with handles and user gui_mainfcn(gui_State, varargin:);
16、 data (see GUIDATA) end global l % End initialization code - DO NOT EDIT % % - Executes just before shiyan32 is made -visible. - function shiyan32_OpeningFcn(hObject, function Untitled_8_Callback(hObject, eventdata, handles, varargin) eventdata, handles) % This function has no output args, see % hOb
17、ject handle to Untitled_8 (see GCBO) OutputFcn. % eventdata reserved - to be defined in a % hObject handle to figure future version of MATLAB % eventdata reserved - to be defined in a % handles structure with handles and user future version of MATLAB data (see GUIDATA) % handles structure with handl
18、es and user data (see GUIDATA) global m % varargin command line arguments to % shiyan32 (see VARARGIN) - - % Choose default command line output for function color_Callback(hObject, eventdata, shiyan32 handles) handles.output = hObject; % hObject handle to color (see GCBO) % eventdata reserved - to b
19、e defined in a % Update handles structure future version of MATLAB guidata(hObject, handles); % handles structure with handles and user data (see GUIDATA) % UIWAIT makes shiyan32 wait for user response global c (see UIRESUME) % % uiwait(handles.figure1); - global c function Untitled_14_Callback(hObj
20、ect, c=b eventdata, handles) % hObject handle to Untitled_14 (see GCBO) global l % eventdata reserved - to be defined in a l=- future version of MATLAB % handles structure with handles and user global m data (see GUIDATA) m= global c % - Outputs from this function are returned c=r to the command lin
21、e. function varargout = % shiyan32_OutputFcn(hObject, eventdata, -handles) - % varargout cell array for returning output function Untitled_15_Callback(hObject, args (see VARARGOUT); eventdata, handles) % hObject handle to figure % hObject handle to Untitled_15 (see GCBO) % eventdata reserved - to be
22、 defined in a % eventdata reserved - to be defined in a future version of MATLAB future version of MATLAB % handles structure with handles and user % handles structure with handles and user data (see GUIDATA) data (see GUIDATA) % handles structure with handles and user global c data (see GUIDATA) c=
23、b % global m - m=d function Untitled_16_Callback(hObject, % eventdata, handles) -% hObject handle to Untitled_16 (see GCBO) - % eventdata reserved - to be defined in a function Untitled_4_Callback(hObject, future version of MATLAB eventdata, handles) % handles structure with handles and user % hObje
24、ct handle to Untitled_4 (see GCBO) data (see GUIDATA) % eventdata reserved - to be defined in a future version of MATLAB global c % handles structure with handles and user c=g data (see GUIDATA) % global l - l=- function Untitled_17_Callback(hObject, % eventdata, handles) -% hObject handle to Untitl
25、ed_17 (see GCBO) - % eventdata reserved - to be defined in a function Untitled_5_Callback(hObject, future version of MATLAB eventdata, handles) % handles structure with handles and user % hObject handle to Untitled_5 (see GCBO) data (see GUIDATA) % eventdata reserved - to be defined in a future vers
26、ion of MATLAB global c % handles structure with handles and user c=y data (see GUIDATA) % global l - l=- function Untitled_10_Callback(hObject, % eventdata, handles) -% hObject handle to Untitled_10 (see GCBO) - % eventdata reserved - to be defined in a function Untitled_7_Callback(hObject, future v
27、ersion of MATLAB eventdata, handles) % handles structure with handles and user % hObject handle to Untitled_7 (see GCBO) data (see GUIDATA) % eventdata reserved - to be defined in a future version of MATLAB global m % handles structure with handles and user m=o data (see GUIDATA) % global l - l=-. function Untitled_11_Callback
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1