matlab编程与工程应用 课后答案-第2章_第1页
matlab编程与工程应用 课后答案-第2章_第2页
matlab编程与工程应用 课后答案-第2章_第3页
matlab编程与工程应用 课后答案-第2章_第4页
matlab编程与工程应用 课后答案-第2章_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论