




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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.678900fprintf(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)不指定宽度: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.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:);fprintf(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/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 = 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;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)+1900;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/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)snow = rain*6.5;34%34 脚本s = input(enter long_side: );V = fn34(s);fprintf(volume is %.2fn,V)%34 函数function V = fn34(s)V = sqrt(2)*s3/12;35%35 pickone(x) returns a random element from vector xfunction outdate = pickone(x)outdate = randi(x(1) x(end),1,1);36function outdate = vecout(x)outdate = x:1:x+5;37%37b = input(enter the first side: );c = input(enter the second side: );alpha = input(enter the angle between them: );a = sqrt(b2+c2-2*b*c*cosd(alpha); %切记这里用sindfprintf(the third side is %.3fn,a)38略39%39mat = 90.5792 27.8498 97.0593; 12.6987 54.6882 95.7167; 91.3376 95.7507 48.5376; 63.2359 96.4889 80.0280 9.7540 15.7613 14.1886;save floatnums.dat mat -ascii;load floatnums.dat;floatnums = round(floatnums)save intnums.dat floatnums -ascii40%40costssales = 1100 800; 1233 650; 111
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年新型流动人卫激光测距仪合作协议书
- 2025年石棉纤维及其制品合作协议书
- 2025年专业设计服务合作协议书
- 2025年船专用码头项目发展计划
- 网络安全协议与应用测试卷
- 2025年丁二酸二甲酯项目合作计划书
- 互联网餐饮服务平台合作合同
- 会议室租赁使用协议书
- 酒店业智能服务及信息化管理平台解决方案设计
- 行业从业经历及成果展示证明(5篇)
- 大学生创业计划书word文档(三篇)
- 土工织物防护施工
- 生产性服务业集聚对城市产业结构优化的影响共3篇
- 施工单位考察记录表
- YY/T 1244-2014体外诊断试剂用纯化水
- GB/T 4130-2017声学水听器低频校准方法
- GB/T 26192-2010双向拉伸聚丙烯可涂覆合成纸薄膜
- GB/T 2546.1-2006塑料聚丙烯(PP)模塑和挤出材料第1部分:命名系统和分类基础
- GB/T 20257.4-2007国家基本比例尺地图图式第4部分:1∶2500001∶5000001∶1000000地形图图式
- 《Matlab程序设计》教学大纲
- 填石路基沉降差记录表
评论
0/150
提交评论