matlab编程与工程应用 课后答案-第2章

上传人:简****9 文档编号:110294952 上传时间:2019-10-29 格式:DOC 页数:7 大小:17.64KB
返回 下载 相关 举报
matlab编程与工程应用 课后答案-第2章_第1页
第1页 / 共7页
matlab编程与工程应用 课后答案-第2章_第2页
第2页 / 共7页
matlab编程与工程应用 课后答案-第2章_第3页
第3页 / 共7页
matlab编程与工程应用 课后答案-第2章_第4页
第4页 / 共7页
matlab编程与工程应用 课后答案-第2章_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《matlab编程与工程应用 课后答案-第2章》由会员分享,可在线阅读,更多相关《matlab编程与工程应用 课后答案-第2章(7页珍藏版)》请在金锄头文库上搜索。

1、1 %计算空心球体积r0 = 3;ri = 2;volume = 4*pi/3*(r03-ri3)2%计算过氧化氢分子量H = 15.9994;O = 1.0079;H2O2 = 2*H + 2*O3%计算字符创长度string = input(enter string: ,s);stringlength = length(string)%4 输入实数,fprintf输出这个变量,格式为两位小数num = input(enter a num: );fprintf(The num is %.2fn,num)6fprintf(不指定宽度: %fn,12345.6789)不指定宽度: 12345.6

2、78900fprintf(10个字符宽度,4个小数位: %10.4fn,12345.6789)10个字符宽度,4个小数位: 12345.6789fprintf(10个字符宽度,2个小数位: %10.2fn,12345.6789)10个字符宽度,2个小数位: 12345.68fprintf(6个字符宽度,4个小数位: %6.4fn,12345.6789)6个字符宽度,4个小数位: 12345.6789fprintf(2个字符宽度,4个小数位: %2.4fn,12345.6789)2个字符宽度,4个小数位: 12345.67897fprintf(不指定宽度:%int16n,12345)不指定宽度:

3、12345nt16fprintf(不指定宽度:%dn,12345)不指定宽度:12345fprintf(5个字符宽度:%5dn,12345)5个字符宽度:12345fprintf(8个字符宽度:%8dn,12345)8个字符宽度: 12345fprintf(3个字符宽度:%3dn,12345)3个字符宽度:123458x = 12.34;y = 4.56;fprintf(x is %.3fn,x)x is 12.340fprintf(x is %2.0fn,x)x is 12fprintf(y is %.1fn,y)y is 4.6fprintf(y is %-6.1f!n,y)y is 4.

4、6 !9%计算矩形面积x = input(enter length:);y = input(enter borad:);area = x*y;fprintf(area is %.2fn,area)10string = input(what is your name?,s);fprintf(WoW,your name is %sn,string)11string = input(enter your string:,s);fprintf(your string was:%sn,string) %输出单引号是应采用格式12v = input(enter the flow in m3/s:);fpr

5、intf(a flow rate of %.3f meters per secnis equivalent to %.3f feet per secn,v,v/0.028)13incomeyear = input(enter your income per year: );fprintf(the range of food expenditure per year %f%fnthe range of food expenditure per mounth %f%fn,incomeyear*0.08,incomeyear*0.1,incomeyear*0.08/12,incomeyear*0.1

6、/12)14wight = input(wight of plant: );area = input(area of wing: );fprintf(W/A: %f kg/m2n,wight/area)15x= 10;y =22;plot(x,y,g+)16x = -2:0.1:2;plot(x,exp(x)xlabel(x)ylabel(y)title(y=ex)17x = 1:5:100;y = sqrt(x);figure(1)plot(x,y)figure(2)bar(x,y)18略19x1 = linspace(0,pi,10);figure(1)plot(x1,sin(x1)x2

7、= linspace(0,pi,100);figure(2)plot(x2,sin(x2)20mat = 1000 2000 3000 5000 10000;288 281 269 256 223;x = mat(:,1);y = mat(:,2);plot(x,y)xlabel(high)ylabel(tempture)title(high-tempture)21mat1 = randi(50,100,3,6)save randfile.dat mat1 -ascii;mat2 = randi(50,100,2,6)save randfile.dat mat2 -ascii -append;

8、load randfile.dat;randfile22mat = rand(2,3)*4-1;save testtan.dat mat -ascii;load testtan.dat;mattan = tan(testtan)23mat = 89 42 49 55 72 63 68 77 82 76 67; 90 45 50 56 59 62 68 75 77 75 66; 91 44 43 60 60 60 65 69 74 70 70save hightemp.dat mat -ascii;load hightemp.dathightemp(:,1) = hightemp(:,1)+19

9、00;hightempsave y2ktemp.dat hightemp -ascii24%24 Calculates y as a function of xfunction y = fn(x)y = x3-4*x2+sin(x);25%25 Converts from MWh to GJfunction gj = mwh_to_gj(mwh) gj = 3.6*mwh;26%26 converta from inch/h to meter/sfunction meter_sec = converta(inch_hour) meter_sec = inch_hour*5280*0.3048/

10、3600;27function Tn = fn27(P,i,n) Tn = P*(1+i)*n;28略29function V = fn29(Pt,Ps) V = 1.016*sqrt(Pt-Ps);30function THR = fn30(A)THR = (220-A)*0.6;31function outdate = fn31(n)outdate = sqrt(2*pi*n)*(n/exp(1)n;32%32 脚本n = input(enter the number of units: );Cn = costn(n);fprintf(the cost for %d units will be $%.2fn,n,Cn)%32 mygcost函数function Cn = costn(n)Cn = 5*n2-44*n+11;33%33 脚本rain = input(enter the rain: );snow = fn33(rain);fprintf(the snow is %fn,snow)%33 调用函数function snow = fn33(rain)sno

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号