




已阅读5页,还剩32页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
P第一次实验答案 1 设要求以0.01秒为间隔,求出y的151个点,并求出其导数的值和曲线。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绘制极坐标系下曲线(a,b,n自定数据)clccleara=10;b=pi/2;n=5;theta=0:pi/100:2*pi;rho=a*cos(b+n*theta);polar(theta,rho)3. 列出求下列空间曲面交线的程序clcclearx=-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、编写一个学生成绩管理的程序,完成下列功能:(1) 构造一个学生结构,包括学生的姓名,课程名称(限M门),考试成绩和平均值等域; (2) 从键盘上,连续输入N个学生的情况,分别将这些学生的情况填入到相应的域,若域中没有值即为空或0,并分别计算其平均值写入到其平均值域。(3) 根据平均值排序(由高到低),并输出学生的姓名和平均值。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(please 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 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=1; iptr=j; endenddisp(成绩排序如下:)for i=1:n disp(strcat(名次: ,num2str(i), 名字 ,NameCell(1,i), 平均成绩: ,num2str(Array(i)end 4、使用句柄图像对象绘制曲线:y=2e-0.5xcos(x),同时对曲线进行标注和修饰。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,函数=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,.7,FaceColor,red)第三次试验答案1、做一个带按钮的界面,当按动“播放”按钮时调入声音文件并播放,显示声音波形,并建立一个用于关闭界面的按钮对象。(提示,找一个.wav文件,简单起见可以在windows目录下找一个文件,将其放在当前工作目录下或搜索路径上。具体用法请参照:y,f,b=wavread(*.wav); % 读入声音文件sound(y,f,b) % 由声卡播放声音plot(y) % 画出波形2、创建一个用于绘图参数选择的菜单对象,其中包含三个选项LineStyle、Marker和Color,每个选项下面又包含若干的子项分别可以进行选择图线的类型、标记点的类型和颜色 (每个子项不少于3个),当按下“绘图”按钮时,根据选项绘制正弦曲线(缺省时为蓝色无标记实线)。(注意使用全球变量)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_OpeningFcn, . 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 EDIT % - 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 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);global 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 future 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 defined 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 handles 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(hObject, 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 (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 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 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_Callback(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 Untitled_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 future 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 user 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 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=strcat(l,m,c);plot(x,y,s)2. 设和是两个10行10列的矩阵(数组),试说明命令A*B, A/B, AB, A.*(B.A), A./B, A.B和sin(A).*exp(B)的涵义。A,B的矩阵乘法,矩阵A乘以B的逆,矩阵B乘以A的逆,B的每个元素的对应A次幂乘以A对应的每个元素A的每个元素除以B对应的每个元素,B的每个元素除以A对应的每个元素,A的每个元素的正弦与B对应的每个元素的指数求积,3. 设A为数组,B为一个行数大于3的数组,请给出(1)删除A的第4、8、12三列的命令; (2)删除B的倒数第3行的命令;(3)求符号极限的命令集; (4)求的3阶导数的命令集;(5)计算定积分的命令,并给出计算结果(!)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 workspace.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 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(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 functionand call this function program to compute the value of in main program or command window, there, shows the factorial (阶乘) of . 提示:对x取整的函数有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 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() function and input() function, but cannot use mean() function, std() function, and var() function directly (可以使用循环语句和length()函数、input()函数等进行编程,但不能直接使用mean()、std()和var()等函数). (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(请输入x );i=1;s=0;while(x(i)=a) s=s+x(i); i=i+1; x(i)=input(请输入x ,输a结束);endxbar=s/(i-1)m=0;for j=1:i-1m=m+(x(i)-xbar)3;endske=m/(i-1)一、填空题1、MATLAB常用操作界面包括 命令窗口 、工作空间窗口、 命令历史窗口 、当前目录窗口 、内存数组编辑器、M文件编辑/调试器、帮助导航/浏览器、图形窗口等。2、MATLAB中Inf或inf表示 无穷大 、NaN或nan表示 不是一个数 、nargout表示 函数输出变量数目 。3、工作空间浏览器主要用于内存变量的 查阅 、 保持 和 编辑 。4、MATLAB实现将全下标转换为单下标的指令为 sub2ind 、据单下标换算出全下标的指令为 ind2sub 。5、MATLAB中clf用于 清除图形窗口 、clc用于 清除指令窗口中显示内容 、clear用于 清除MATLAB工作空间中保存的变量 。二、简答题(每题5分,共20分) 1、简述MATLAB历史指令窗的主要作用。答:历史指令窗记录着用户在MATLAB指令窗中所输入过的所有指令。历史记录包括:每次开启MATLAB的时间,每次开启MATLAB后在指令窗中运行过的所有指令。应用功能有单行或多行指令的复制和运行、生成M文件等。2、简述MATLAB函数的基本结构。答:典型M函数文件的结构:函数申明行、H1行、在线帮助文本区、编写和修改记录、函数体。3、简述绘制二维图形的一般步骤。绘制二维图形的一般步骤为:曲线数据准备、选定图形窗及子图位置、调用二维曲线绘图指令、设置轴的范围、坐标分格线、图形注释、图形的精细操作。三、阅读程序并回答问题(每题4分,共28分)1、写出下列指令运行结果。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、写出下列指令运行结果。A=reshape(1:16,2,8) reshape(A,4,4) s=1 3 6 8 9 11 14 16;A(s)=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、写出下列指令运行结果。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、下面的函数主要完成什么功能? function f=factor(n)if n=a&ch=z); ch(k)=ch(k)-(a-A); char(ch) subch =ABc12revch =9gF65e4d321cBAans =ABC123D4E56FG9ans = 46、写出下列指令运行结果。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(-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、用命令来创建GUI并绘制方程y=ax2 +bx+c图形,需要显示绘图结果的坐标系窗口,还能输入a、b、c的值和x的取值范围,同时用命令设置所以对象的属性。2、在同一图上分别用红色实线和绿色虚线绘制y1=sin(x)和y2=cos(x)在区间0,4*pi的曲线,并用星号*标出两条曲线的交点以及建立图例。(5分)x=0:0.01:4*pi;y1=sin(x);y2=cos(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、某商场对顾客所购买的商品实行打折销售,标准如下(商品价格用price来表示): price200 没有折扣 200price500 3%折扣 500price1000 5%折扣 1000price2500 8%折扣 2500price5000 10%折扣5000price 14%折扣输入所售商品的价格,求其实际销售价格。(5分)price=input(please input your price:);a=0;if price200 a=1;elseif price500 a=2;elseif price10
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025农产品销售合同模板
- 2025年传染病区隔离试题及答案
- 2025养殖场经营合同范本
- 2025年吉林省合同范本汇编
- 2025捐赠协议模板
- 2025标准供货合同模板
- 传染病防治监督技能竞赛试卷及答案
- 瓦屋面合同4篇
- 第 9 课 消失的树林教学设计-2025-2026学年小学信息技术滇人版三年级第1册-滇人版
- 放大电路的分析教学设计-2025-2026学年中职专业课-电子技术基础与技能-机电技术应用-装备制造大类
- 融资风险评估报告
- 画法几何及土木工程制图课件
- 第2课 树立科学的世界观《哲学与人生》(高教版2023基础模块)
- 录入与排版教学计划
- 2023免拆底模钢筋桁架楼承板图集
- 云计算技术基础应用教程(HCIA-Cloud)PPT完整全套教学课件
- 呼吸衰竭小讲课课件
- 成人学士学位英语1000个高频必考词汇汇总
- 全屋定制家居橱柜衣柜整装安装服务规范
- 沥青及沥青混合料试验作业指导书
- 义务教育阶段学生艺术素质测评指标体系小学音乐
评论
0/150
提交评论