Matlab编程与工程应用(第二版)习题解答.docx_第1页
Matlab编程与工程应用(第二版)习题解答.docx_第2页
Matlab编程与工程应用(第二版)习题解答.docx_第3页
Matlab编程与工程应用(第二版)习题解答.docx_第4页
Matlab编程与工程应用(第二版)习题解答.docx_第5页
免费预览已结束,剩余25页可下载查看

下载本文档

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

文档简介

Matlab编程与工程应用(第二版)习题解答第一章:MATLAB简介1. myage = 25; myage = myage - 1; myage = myage + 2;2. myage = 25; myage = myage - 1; myage = myage + 2;3. namelengthmaxans =634. format bank 1/3ans = 0.335. format rat 5/6 + 2/7ans = 47/42 6. 25 19 4.3333 9 97. pounds = 100; kilos = 2.2 * poundskilos = 220.00008. R1 = 20; R2 = 30; R3 = 40; RT = (R11 + R21 + R31)1RT =9.23089. ftemp = 90; ctemp = (ftemp - 32) * 5 / 9ctemp = 32.222210. 略11 sind(90)ans = 112. sita = 2 * pi / 3; r = 2; x = r * cos(sita)x = -1.0000 y = r * sin(sita)y =1.732113 t = 100;V = 50; wcf = 35.7 + 0.6 * t - 35.7 + 0.16 * V + 0.43 * t * 0.16 * Vwcf = 41214. Fix(3.5) = 3;Floor(3.5) = 3;Fix(3.4) = 3; Fix(-3.4) = -3;Fix(3.2) = 3; Floor(3.2) = 3;Fix(-3.2) = -3; Floor(-3.2) = -4;Fix(-3.2) = -3; Ceil(-3.2) = -3;15.Sqrt(19)3 1.2Tan(pi)16. Intmin(int32); intmax(int32); intmin(int64);intmax(int64);17.Realmin(double); Realmax(double);18. DblNum = 33.8; int32Num = int32(DblNum)int32Num = 3419. A1 = rand;A2 = 20*rand;A3 = 30 * rand + 20;A4 = round(rand * 10);A5 = round(rand * 11); / A6 = round(rand * 50) + 50; A4 = randi(10); A5 = randi(11); A6 = randi(50) + 50;20. 略21.Double(A) CharNum = xyz; CharNum = char(CharNum - 2)CharNum =vwx23. vec = 3 : 1 : 6vec = 3 4 5 6 vec2 = 1.0000:0.5000:3.0000vec2 = 1.0000 1.5000 2.0000 2.5000 3.0000 vec3 = 5 : -1 :2vec3 = 5 4 3 224. vec1 = linspace(4,8,3)vec1 = 4 6 8 vec2 = linspace(-3,-15,5)vec2 = -3 -6 -9 -12 -15 vec3 = linspace(9,5,3)vec3 = 9 7 525 vec = 1 : 1 : 10vec = 1 2 3 4 5 6 7 8 9 10 vec = linspace(1,10,10)vec = 1 2 3 4 5 6 7 8 9 10 vec2 = 2:5:12vec2 = 2 7 12 vec = linspace(2,12,3)vec = 2 7 1226. myend = randi(4) + 8; vec1 = 1 : 3 : myendvec1 = 1 4 7 1027. vec = -1:0.2:1vec = -1.0000 -0.8000 -0.6000 -0.4000 -0.2000 0 0.2000 0.4000 0.6000 0.80001.000028. vec = 0 : 1 : 15; n = 1 : 2 : numel(vec) - 1; vec2 = vec(n)vec2 = 0 2 4 6 8 10 12 1429.function a b = PI_CONT(x)%UNTITLED Summary of this function goes here% Detailed explanation goes here n =1 : 1 : fix(numel(x) / 2); a = x(n); n = 1+fix(numel(x)/2) : 1 : numel(x); b = x(n);endrem(numel(vec),2)30rand(2,3)10*rand(2,3)5 + round(15 * rand(2,3)randint(2,3,5 15)31. rows = randi(5); cols = randi(5); y = zeros(rows,cols);32. mat = 7 8 9 10 12 10 8 6; A1 = mat(1,3) A2 = mat(2,:) A3 = mat(:,1:2)33. mymat = 2 3 4;5 6 7 mymat1 = fliplr(mymat) mymat2 = flipud(mymat) mymat3 = rot90(mymat)34. mymatzero = zeros(4,2) mymatzero(2,:) = 3,635. x = linspace(-pi,pi,20); y = sin(x);36. randmat = randint(3,5,-5 5) sign(randmat)37. randmat = randint(4,6,-5 5); randmat2 = abs(randmat)38. randmat = rand(3,5) randmat(3,:) = 39. vec = 1 : 1:1000; vec(end) vec(numel(vec) a b = size(vec); vec(a * b)40.同上41. mat = zeros(3,5); mat(:,:,1) = zeros(3,5); mat(:,:,2) = zeros(3,5);42. myc = clock today = myc(1:3) now = myc(4:6) now = fix(now)第二章 MATLAB程序设计概述1. ri = 2; % Radius internalro = 4; % Radius outerV = 4 * pi / 3 * (ro 3 - ri 3) % calculate volume2.% Calculate Atomic Weight H2O2Weight_O = 15.9994;Weight_H = 1.0079;AtomicWeight = Weight_O * 2 + Weight_H * 2 % Calculate H2O2 Atomic Weight3.fprintf(Length of The character string is : %dn,length(input(Please input character string :n,s);4. NewNumber = input(please input a Number :n);fprintf(Number with 2 decimal is :%0.2fn,NewNumber);5. vec = input(Enter a matrix: )Enter a matrix: 1:1:10;1:1:106. fprintf(OUTPUT : %fn,12345.6789)OUTPUT : 12345.678900 fprintf(OUTPUT : %10.4fn,12345.6789)OUTPUT : 12345.6789 fprintf(OUTPUT : %10.2fn,12345.6789)OUTPUT : 12345.68 fprintf(OUTPUT : %6.4fn,12345.6789)OUTPUT : 12345.6789 fprintf(OUTPUT : %2.4fn,12345.6789)OUTPUT : 12345.67897. fprintf(OUTPUT : %dn,12345)OUTPUT : 12345 fprintf(OUTPUT : %5dn,12345)OUTPUT : 12345 fprintf(OUTPUT : %8dn,12345)OUTPUT : 12345 fprintf(OUTPUT : %3dn,12345)OUTPUT : 123458. x = 12.34; y = 4.56; fprintf(x is %.3fn,x)x is 12.340 fprintf(x is %0.0fn,x)x is 12 fprintf(y is %0.1fn,y)y is 4.6 fprintf(y is %0.1f !n,y)y is 4.6 !9.% Calculate Area of the squarenessfprintf(The Area of The Squareness is %.2f,(input(Please input the Length of the Squareness n) * (input(Please input the Width of the Squareness n);10.NewName = input(What is your name? ,s);fprintf(Wow,your name is %s!n,NewName);11.NewString = input(Enter your string : ,s);fprintf(Your String was : %sn,NewString);12.WaterSpeed = input(Enter the folw in m3/s : );WaterSpeedft = 0.028 WaterSpeed;fprintf(A flow rate of %.3f meters per sec n,WaterSpeed);fprintf(is equivalent to %.3f feet per secn,WaterSpeedft);13.IncomeY = input(Input your income every year?);FoodCostY= IncomeY * 8 / 100 IncomeY*10 / 100;FoodCostM = 12FoodCostY;fprintf(Food Cost in every year is %.2f - %.2fn,FoodCostY(1),FoodCostY(2);fprintf(Food Cost in every Month is %.2f - %.2fn,FoodCostM(1),FoodCostM(2);14.Weight = input(Please input the Weight of the plan n)Area = input(Please input the area of the plan wing n)fprintf(Charge of Plan Win is %.2f n,Weight / Area)15.x = 10;y = 10;plot(x,y,g+);16.clfx = -2 : 0.1 : 2;y = exp(x);plot(x,y,g);xlabel(X);ylabel(Y);legend(Exp(x);Title(Exp Example);17.clfx = 1 : 5 : 100;y = sqrt(x);plot(x,y,go);hold on;bar(x,y);18.clfy = randint(1,100,0 100);x = 1 : 1 : length(y);plot(x,y,ro);hold on plot(x,y,g+);figure(2);plot(x,y,k);figure(3);bar(x,y)19.clfx = linspace(0,pi,10);y = sin(x);plot(x,y,r);figure(2);x = linspace(0,pi,100);y = sin(x);plot(x,y,b);20.load TimeTemp.datx = TimeTemp(:,1);y = TimeTemp(:,2);plot(x,y);Xlabel(Height);Ylabel(Temperature);Title(Height - Temperature);legend(TEMP)21. randint(3,6,50 100); save RandInt.bat ans -ascii; randint(2,6,50 100) save RandInt.bat randint -ascii append load RandInt.bat RandInt22. load testtan.bat tan(testtan)23. load hightemp.dat hightemp(:,1) = hightemp(:,1) .+ 1900 save y2ktemp.dat hightemp ascii24.function fn = fn( x )%Calculate y as a function of xfn = x3 - 4 * x2 + sin(x);end25.function mwh = mwh_to_gj(x)%convers from MWh to GJ mwh = 3.6 * x;end26.function output_args = miletometer( x )%Conver mile to meter Mile = input(mile per hours number :); meter = Mile * 5280 * 0.3048 / 3600; output_args = meter; fprintf(Meter of the mile is : % .2f,meter);end27.function Tn = Interest( p,i,n )%UNTITLED4 Summary of this function goes here Tn = p * (1 + i) * n;end28.略29.function V = SpeedConv(pi,ps)%UNTITLED4 Summary of this function goes here V = 1.016 * sqrt(pi - ps)end30. function THR =Cal_rate(A)%UNTITLED4 Summary of this function goes hereTHR = (220 - A) * 0.6;end31.function nJ =STL_calc(n)%UNTITLED4 Summary of this function goes herenJ = sqrt(2 * pi * n) * (n / exp(1)n;end32.function output_args = costn( n )%UNTITLED5 Summary of this function goes hereoutput_args = 5 * n 2 - 44 * n + 11;endn = input(Enter the number of units :);Cn = costn(n);fprintf(The cost for 100 units will be $%.2fn,Cn);33.略(仿造32题)34.function V = oblong( length )%UNTITLED8 Summary of this function goes hereV = 1/12*sqrt(2)*length3;endfprintf(The volume of oblong is : %.2fn ,oblong(input(Enter the length of the oblong:n)35.function y = pickone( x )%pickone(x) returns a random element from vector x n = length(x); y = x(randi(n);end36.function y = vecout( x )%UNTITLED11 Summary of this function goes herey = x : 1 : x+5;end37.b = input(Enter the first side :);c = input(Enter the second side :)afa = input(Enter the angle between them :)y = sqrt(b2 + c2 - 2*b*c*cos(afa *(pi/180);fprintf(The third side is %.3fn,y);38.略39.load floatnums.datfloatnums = round(floatnums);floatnums = floatnums;save intnums.dat floatnums -ascii;40.load costssales.datn = length(costssales(:,1);fprintf(There were %d quarters in the file ,n);n = 1 : 1 : n;costs = costssales(:,1);sales = costssales(:,1);plot(n,costs,ko);hold on plot(n,sales,b*);legend(COSTS,SALES);xlabel(COST);ylabel(SALE);title(COST-SALE);costssales = costssalescostssales = flipud(costssales);save newfile.dat costssales -ascii;第三章 选择语句2. if (input(please Enter a x :n,s) = x) disp(sorry the char not x);end3. function y = Test3(x)if (x = 12) y = 1;else y = x + 1;end;4. disp(The program will calculate the volume of a pyramid);a = input(Enter the length of the base :);c = input(Is that i or c?,s);if( c = c) a = a/2.54;end;b = input(Enter the width of the base :,s);c = input(Is that i or c?);if( c = c) b = b/2.54;end;d = input(Enter the length of the base :,s);c = input(Is that i or c?);if( c = c) d = d/2.54;end;fprintf(The Volume of the Pyramid is %.3f cubic inches.,a * b * d / 3);5.if(input(Are you an engineer?(Y/N),s) = Y) disp(You are the best!);else disp(oh soga);end;6.Fenzi = input(Please input enter the FENZI: );Fenmu = input(Please input enter the FENMU: );if(Fenmu = 0) disp(Sorry The Fenmu can not be zero!);else fprintf(The result is %.2f.n,Fenzi/Fenmu);end;7.function Result = Test3_Func( a,b )%TEST3_FUNC Summary of this function goes here% Detailed explanation goes hereResult = sqrt(1 - b2/a);EndFunction:a = input(Please Enter the a : );b = input(Please Enter the b : );if (a = 0) disp(Error 0001);else fprintf(The Result is %.2f n,Test3_Func(a,b);end;8.a = input(Please Enter the Shousuo : );b = input(Please Enter the Shuzhang : );if (a120 & b A2) disp(UP!);elseif (A1 A2) disp(Down!); else disp(Keep!); en10.a = input(Enter the PH number : );if (a 7) disp(Jian);else disp(Zhong);end;11.function Result = Test3_Func( a,b )%TEST3_FUNC Summary of this function goes here% Detailed explanation goes hereif (a 1) disp(supersonic speed);elseif(Mahe 1) disp(subsonic speed);else disp(transonic speed);end;16.X = input(Enter the temp in degrees C : n);switch (input(Do you want F or K?,s) case F fprintf(The temp in degrees F is %.1f,(9/5)*X + 32); case K fprintf(The temp in degrees K is %.1f,X + 273.15); otherwise disp(Enter Error!);end;17.%function y = Test3(x)X = randi(100);if rem(X,2) = 0 fprintf(%d n,X);else fprintf(%d n,X); end18.function y = Test3(x)switch rem(x,4) case 0 y = true; otherwise y =false;end;19.function y = Test3(innum)if innum = int32(innum) y = true;else y =false;end;20.function y = Test3(a,b,c)if a2 = b2 + c2 y = true;else y =false;end;21.Re = input(Enter the Re Value :n);if Re 2300 & Re = 4000 disp(Transition region);else disp(Turbulent region);end;22.d1 = input(Enter d1 : n);d2 = input(Enter d2 : n);if d1 = 0 | d2 = 0 disp(Error!);else fprintf(%.2f,Test3_Func(d1,d2);end;function y = Test3_Func(a,b)y = a * b / 2;23.V = input(Enter the speed of the wing: );if V = 73 disp(typhoon);else disp(revolving storm );end;24.V = input(Enter the speed of the wing :);if V 74 & V 95 & V 110 & V 130 & V 155 disp(5 : 18);else disp(Error);end25.略26.H = input(Enter the hight of the cloude :);if H 0 disp(Low);elseif H = 6500 & H for i = 1.5:0.2:3.1i = iend2. function output = Test3_Func(x)x = x - (rem(x,2) = 0);output = 0;for i = 1 : 2 : x output = output + i;end;3.function output = Test3_Func(x)x = x - (rem(x,2) = 0);output = 1;for i = 1 : 2 : x output = output * i;end;4.5. for i = 32 : 1 : 255char(i)end;6. vec = 5.5 11 3.45; for i = 1 : length(vec)fprintf(Element %d is %.2f .n,i,vec(i);end;7.n = randi(4) + 1;sum = 0;for i = 1 : n sum = sum + input(Enter the value);end;fprintf(Sum = %.1fn,sum);8disp(Please enter the threshold below which samples will be considered to be invalid :);Value1 = input(Considered to be invalid :n);Value2 = input(Please enter the number of data samples to be entered :n);Sum = 0;num = 0;for i = 1:Value2 data = input(Please enter a data sample :); if data Value1 Sum = Sum + data; num = num + 1; endendif num = 0 disp(Data Error !);else fprintf(The average of the %d valid data samples is %.2f volts.,num,Sum/num);end9.load MaxTemp.mata b = size(MaxTemp);for i = 1 : a; Matix1 = zeros(size(MaxTemp); Matix1(i,:) = MaxTemp(i,:) end10.sum = 0;for i = 1 : length(pipe) sum = sum + (pipe(i,1) 2.3); sum = sum + (pipe(i,2) 10.4);endfprintf(There were %d rejects.n,sum);11.略12.略13.x = randint(1,5,-10,10);x2 = 0;for i = 1 : length(x) x1(1,i) = x(1,i) - 3; if x1(1,i) 0 x2 = x2 + 1; end; x3(1,i) = abs(x1(1,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论