版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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)6fpri
2、ntf('不指定宽度: %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个字符宽度
3、,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个字符宽度:123458
4、x = 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
5、9;,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:''%s''n',string) %输出单引号是应采用''格式12v = input('enter the flow in m3/s:
6、');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,incomeye
7、ar*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 =
8、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')titl
9、e('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;
10、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 g
11、j = 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 out
12、date = 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);f
13、printf('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 =
14、 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('t
15、he 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; 1111 100
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 合成膜电位器工安全应急强化考核试卷含答案
- 啤酒糖化工安全行为模拟考核试卷含答案
- 热敏电阻红外探测器制造工操作能力强化考核试卷含答案
- 井下作业机司机安全宣教模拟考核试卷含答案
- 火工品装配工QC管理知识考核试卷含答案
- 野炊作文好开头
- 和老板请假条格式
- 2025年微信生态合作协议书
- 2026年近零碳排放园区改造项目评估报告
- 2026年燃料电池项目公司成立分析报告
- 2026年年长租公寓市场分析
- 生态环境监测数据分析报告
- 金融机构衍生品交易操作规范
- 医院检查、检验结果互认制度
- 2025年医院物价科工作总结及2026年工作计划
- 2025年下半年四川成都温江兴蓉西城市运营集团有限公司第二次招聘人力资源部副部长等岗位5人考试参考试题及答案解析
- 2025-2026学年上学期成都小学数学四年级期末典型卷1
- 八年级历史上册小论文观点及范文
- 2026年江西应用技术职业学院单招职业适应性测试必刷测试卷必考题
- 浙江省杭州市萧山区2024-2025学年六年级上学期语文期末试卷(含答案)
- 统编版语文二年级上册知识点
评论
0/150
提交评论