Matlab编程与工程应用(第二版)习题解答第一章:MATLAB简介1.myage=25;myage=myage-1;myage=myage+2;2.myage=25;myage=myage-1;myage=myage+2;3.namelengthmaxans=634.formatbank1/3ans=0.335.formatrat5/6+2/7ans=47/426.25194.3333997.pounds=100;kilos=2.2*poundskilos=220.00008.R1=20;R2=30;R3=40;RT=(R1\1+R2\1+R3\1)\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.0000y=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’)Double(‘a’);所以大写在前,小写在后;22.CharNum='xyz';CharNum=char(CharNum-2)CharNum=vwx23.vec=[3:1:6]vec=3456vec2=[1.0000:0.5000:3.0000]vec2=1.00001.50002.00002.50003.0000vec3=[5:-1:2]vec3=543224.vec1=linspace(4,8,3)vec1=468vec2=linspace(-3,-15,5)vec2=-3-6-9-12-15vec3=linspace(9,5,3)vec3=97525.vec=[1:1:10]vec=12345678910vec=linspace(1,10,10)vec=12345678910vec2=[2:5:12]vec2=2712vec=linspace(2,12,3)vec=271226.myend=randi(4)+8;vec1=[1:3:myend]vec1=1471027.vec=[-1:0.2:1]'vec=-1.0000-0.8000-0.6000-0.4000-0.200000.20000.40000.60000.80001.000028.vec=[0:1:15];n=[1:2:numel(vec)-1];vec2=vec(n)vec2=0246810121429.function[ab]=PI_CONT(x)%UNTITLEDSummaryofthisfunctiongoeshere%Detailedexplanationgoesheren=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)30.rand(2,3)10*rand(2,3)5+round(15*rand(2,3))randint(2,3,[515])31.rows=randi(5);cols=randi(5);y=zeros(rows,cols);32.mat=[78910121086];A1=mat(1,3)A2=mat(2,:)A3=mat(:,1:2)33.mymat=[234;567]mymat1=fliplr(mymat)mymat2=flipud(mymat)mymat3=rot90(mymat)34.mymatzero=zeros(4,2)mymatzero(2,:)=[3,6]35.x=linspace(-pi,pi,20);y=sin(x);36.randmat=randint(3,5,[-55])sign(randmat)37.randmat=randint(4,6,[-55]);randmat2=abs(randmat)38.randmat=rand(3,5)randmat(3,:)=[]39.vec=1:1:1000;vec(end)vec(numel(vec))[ab]=size(vec);vec(a*b)40.同上41.mat=zeros(3,5);mat(:,:,1)=zeros(3,5);mat(:,:,2)=zeros(3,5);42.myc=clocktoday=myc(1:3)now=myc(4:6)now=fix(now)第二章MATLAB程序设计概述1.ri=2;%Radiusinternalro=4;%RadiusouterV=4*pi/3*(ro^3-ri^3)%calculatevolume2.%CalculateAtomicWeightH2O2Weight_O=15.9994;Weight_H=1.0079;AtomicWeight=Weight_O*2+Weight_H*2%CalculateH2O2AtomicWeight3.fprintf('LengthofThecharacterstringis:%d\n',…length(input('Pleaseinputcharacterstring:\n','s')));4.NewNumber=input('pleaseinputaNumber:\n');fprintf('Numberwith2decimalis:%0.2f\n',NewNumber);5.vec=input('Enteramatrix:')Enteramatrix:[1:1:10;1:1:10]6.fprintf('OUTPUT:%f\n',12345.6789)OUTPUT:12345.678900fprintf('OUTPUT:%10.4f\n',12345.6789)OUTPUT:12345.6789fprintf('OUTPUT:%10.2f\n',12345.6789)OUTPUT:12345.68fprintf('OUTPUT:%6.4f\n',12345.6789)OUTPUT:12345.6789fprintf('OUTPUT:%2.4f\n',12345.6789)OUTPUT:12345.67897.fprintf('OUTPUT:%d\n',12345)OUTPUT:12345fprintf('OUTPUT:%5d\n',12345)OUTPUT:12345fprintf('OUTPUT:%8d\n',12345)OUTPUT:12345fprintf('OUTPUT:%3d\n',12345)OUTPUT:123458.x=12.34;y=4.56;fprintf('xis%.3f\n',x)xis12.340fprintf('xis%0.0f\n',x)xis12fprintf('yis%0.1f\n',y)yis4.6fprintf('yis%0.1f!\n',y)yis4.6!9.%CalculateAreaofthesquarenessfprintf('TheAreaofTheSquarenessis%.2f',…(input('PleaseinputtheLengthoftheSquareness\n'))…*(input('PleaseinputtheWidthoftheSquareness\n')));10.NewName=input('Whatisyourname?','s');fprintf('Wow,yournameis%s!\n',NewName);11.NewString=input('Enteryourstring:','s');fprintf('YourStringwas:''%s''\n',NewString);12.WaterSpeed=input('Enterthefolwinm^3/s:');WaterSpeedft=0.028\WaterSpeed;fprintf('Aflowrateof%.3fmeterspersec\n',WaterSpeed);fprintf('isequivalentto%.3ffeetpersec\n',WaterSpeedft);13.IncomeY=input('Inputyourincomeeveryyear?');FoodCostY=[IncomeY*8/100IncomeY*10/100];FoodCostM=12\FoodCostY;fprintf('FoodCostineveryyearis%.2f-%.2f\n',FoodCostY(1),FoodCostY(2));fprintf('FoodCostineveryMonthis%.2f-%.2f\n',FoodCostM(1),FoodCostM(2));14.Weight=input('PleaseinputtheWeightoftheplan\n')Area=input('Pleaseinputtheareaoftheplanwing\n')fprintf('ChargeofPlanWinis%.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('ExpExample');17.clfx=1:5:100;y=sqrt(x);plot(x,y,'go');holdon;bar(x,y);18.clfy=randint(1,100,[0100]);x=1:1:length(y);plot(x,y,'ro');holdonplot(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.loadTimeTemp.datx=TimeTemp(:,1)';y=TimeTemp(:,2)';plot(x,y);Xlabel('Height');Ylabel('Temperature');Title('Height-Tempe