matlab概要.docVIP

  • 157
  • 0
  • 约3.69千字
  • 约 11页
  • 2016-11-23 发布于湖北
  • 举报
matlab概要

MATLAB 课后习题 班级: 姓名: 学号: 第二章 2.3产生一均匀分布在(-5,5)之间的随机阵(50×2),要求精确到小数点后一位。 解: a=5-round(100*rand(50,2))/10 第三章 3.3.5将图形窗口分成两个窗格,并分别绘制出以下函数在[-3,3]区间上的曲线: Y1=2*x+5 Y2=x^2-3*x+1 利用axis调整轴刻度,使它们具有相同的放缩尺寸。 解: x=-3:.1:3; y1=2*x+5; y2=x.^2-3*x+1; subplot(2,1,1); plot(x,y1),grid on axis([-3 3 -1 19]); subplot(2,1,2); plot(x,y2),grid on axis([-3 3 -1 19]); 3.7有一位研究生,一年中平均每月的费用为生活费190元、资料费33元、电话费45元、购买衣服42元以及其它费用45元,请以饼图表示出他每月的消费比例,并分离出表示资料费用的切片。请给图中每一块加以标注。 解: x=[190 33 45 42 45]; explode=[0 1 0 0 0]; figure(1) colormap hsv labels={生活费,资料费,电话费,购买衣服费,其他费用}; pie(x,explode,labels) 第四章 4.1编写M函数实现:求一个数是否为素数,再编写一主程序(脚本文件),要求通过键盘输入一个整数,然后判断其是否为素数。 解: 4.5.利用menu函数输入选择参数ch。当ch=1时,产生[-10,10]之间均匀分布的随机数;当ch=2时,产生[-5,5]之间均匀分布的随机数;当ch=3时,产生[-1,1]之间均匀分布的随机数;当ch=4时,产生均值为0,方差为1的正态分布随机数。要求使用switch函数。 解:f=menu(ch,1,2,3,4); a=[]; switch f case 1,a=10-rand(2)*20 case 2,a=5-rand(2)*10 case 3,a=1-rand(2)*2 case 4,a=randn(2); otherwise disp(error!) end 4.7 编写程序设计良好的用户界面,完成输入全班学生某学期6门课程(任意指定)的成绩,并按学分2、3、2、4、2.5、1分别进行加权平均,计算出每个学生的加权平均。 解:% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) a = get(handles.edit1,String); b = get(handles.edit2,String); c = get(handles.edit3,String); d = get(handles.edit4,String); e = get(handles.edit5,String); f = get(handles.edit6,String); total = 2*str2double(a)/14.5 +3*str2double(b)/14.5+2*str2double(c)/14.5+4*str2double(d)/14.5+2.5*str2double(e)/14.5+str2double(f)/14.5 ; h = num2str(total); set(handles. edit7,String,h); guidata(hObject, handles); 第五章 5.7已知一组测量值 t 1 2 3 4 5 6 7 8 9 10 y 15.0 39.5 66.0 85.5 89.0 67.5 12.0 -86.4 -236.9 -448.4 分别采用二阶和三阶多项式进行拟合,给出拟合结果曲线。 解:x=[1 2 3 4 5 6 7 8 9 10]; y=[15.0 39.5 66.0 85.5 89.0 67.5 12.0 -86.4 -236.9 -448.4]; x2=1:.1:10; y2=polyval(p,x2); subplot(2,1,1); p=polyfit(x,y,2); figure(1) plot(x,y,o,x2,y2) grid

文档评论(0)

1亿VIP精品文档

相关文档