




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
同濟(jì)大學(xué)matlab課程練習(xí)題答案同濟(jì)大學(xué)matlab課程練習(xí)題答案/NUMPAGES94同濟(jì)大學(xué)matlab課程練習(xí)題答案同濟(jì)大學(xué)matlab課程練習(xí)題答案 同濟(jì)大學(xué)matlab課程練習(xí)題答案 關(guān)曉飛第一章初識(shí)matlab題目1x1=input('x1=');x2=input('x2=');x3=input('x3=');x4=input('x4=');x5=input('x5=');x6=input('x6=');x7=input('x7=');a=x1/x5;b=[x3/(x2-x1)]^0.85;c=1-0.36*(x4/x2)^(-0.56);d=2.62*c^1.5;e=(x4/x2)^1.16;f=[(1-d*e)/(x6*x7)]^0.5;y=174.42*a*b*f題目2略題目3>>helplookforlookforSearchallMATLABfilesforkeyword.lookforXYZlooksforthestringXYZinthefirstcommentline(theH1line)oftheHELPtextinallMATLABfilesfoundonMATLABPATH(includingprivatedirectories).Forallfilesinwhichamatchoccurs,lookfordisplaystheH1line.Forexample,"lookforinverse"findsatleastadozenmatches,includingtheH1linescontaining"inversehyperboliccosine""two-dimensionalinverseFFT",and"pseudoinverse".Contrastthiswith"whichinverse"or"whatinverse",whichrunmorequickly,butwhichprobablyfailtofindanythingbecauseMATLABdoesnotordinarilyhaveafunction"inverse".lookforXYZ-allsearchestheentirefirstcommentblockofeachMATLABfile.Insummary,WHATliststhefunctionsinagivendirectory,WHICHfindsthedirectorycontainingagivenfunctionorfile,andlookforfindsallfunctionsinalldirectoriesthatmighthavesomethingtodowithagivenkeyword.題目4n=input('n=');sum(1:n)prod(1:n)題目5>>linspace(0,360,9)ans=04590135180225270315360題目7n=input('n=')formatbankn第二章矩陣的建立題目1.spiral產(chǎn)生螺旋矩陣?yán)?gt;>spiral(3)ans=
789
612
543題目2.(1)[12;34]+10-2ians=
11.0000-2.0000i
12.0000-2.0000i
13.0000-2.0000i
14.0000-2.0000i(2)[12;34].*[0.10.2;0.30.4]ans=
0.1000
0.4000
0.9000
1.6000(3)[12;34].\[2010;92]ans=
20.0000
5.0000
3.0000
0.5000(4)exp([12;34])
%自然對(duì)數(shù)的1、2、3、4乘方ans=
2.7183
7.3891
20.0855
54.5982(5)[12;34].^2ans=
1
4
9
16(6)sum([12;34])
ans=
4
6(7)prod([12;34])
%每一列的所有行相加
ans=
3
8(8)[a,b]=min([1020;3040])
%a代表每一列的最小值,b代表該值所在的行數(shù)a=
10
20
b=
1
1(9)abs([12;34]-pi)
%絕對(duì)值
ans=
2.1416
1.1416
0.1416
0.8584(10)linspace(3,4,5)
%生成3到4均勻的5個(gè)數(shù)
ans=
3.0000
3.2500
3.5000
3.7500
4.0000(11)A=[12;34];sort(A(:,2))
%提取第2列
ans=
2
4
題目3.A=[1,2,3,4;4,3,2,1;2,3,4,1;3,2,4,1]
A=
1
2
3
4
4
3
2
1
2
3
4
1
3
2
4
1
A(5,6)=5
A=
1
2
3
4
0
0
4
3
2
1
0
0
2
3
4
1
0
0
3
2
4
1
0
0
0
0
0
0
0
5題目4示例:A=[3-1;-13]
A=
3
-1
-1
3
[X,D]=eig(A)X=
-0.7071
-0.7071
-0.7071
0.7071
D=
2
0
0
4題目5A=
3
-1
-1
3
2^Aans=
10
-6
-6
10
2.^Aans=
8.0000
0.5000
0.5000
8.0000題目6(1)A=magic(6)
A=
35
1
6
26
19
24
3
32
7
21
23
25
31
9
2
22
27
20
8
28
33
17
10
15
30
5
34
12
14
16
4
36
29
13
18
11
c=A(2,1)c=
3(2)t=2:2:6;B=A(t,:);BB=
3
32
7
21
23
25
8
28
33
17
10
15
4
36
29
13
18
11(3)A(:,[end,2:end-1,1])
ans=
24
1
6
26
19
35
25
32
7
21
23
3
20
9
2
22
27
31
15
28
33
17
10
8
16
5
34
12
14
30
11
36
29
13
18
4(4)A(:,[13456])ans=
35
6
26
19
24
3
7
21
23
25
31
2
22
27
20
8
33
17
10
15
30
34
12
14
16
4
29
13
18
11題目7ones(4,5)
ans=
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
rand(3,4)ans=
0.8147
0.9134
0.2785
0.9649
0.9058
0.6324
0.5469
0.1576
0.1270
0.0975
0.9575
0.9706>>eye(3)ans=
1
0
0
0
1
0
0
0
1題目8A=[0:99];A=reshape(A,10,10)
A=
0
10
20
30
40
50
60
70
80
90
1
11
21
31
41
51
61
71
81
91
2
12
22
32
42
52
62
72
82
92
3
13
23
33
43
53
63
73
83
93
4
14
24
34
44
54
64
74
84
94
5
15
25
35
45
55
65
75
85
95
6
16
26
36
46
56
66
76
86
96
7
17
27
37
47
57
67
77
87
97
8
18
28
38
48
58
68
78
88
98
9
19
29
39
49
59
69
79
89
99A=magic(3)題目9A=
8
1
6
3
5
7
4
9
2
A(2,:)=A(2,:)*2
A=
8
1
6
6
10
14
4
9
2
A(1,:)=A(1,:)+A(3,:)*(-2)
A=
0
-17
2
6
10
14
4
9
2題目10A=[1,3,5;5,8,3;6,1,6];B=[3,6;9,5;8,2];C=[3,3,9;4,0,6];D=[2:6];[A,B]ans=
1
3
5
3
6
5
8
3
9
5
6
1
6
8
2[A;C]ans=
1
3
5
5
8
3
6
1
6
3
3
9
4
0
6
[A,B;D]ans=
1
3
5
3
6
5
8
3
9
5
6
1
6
8
2
2
3
4
5
6A=ones(6,7)
A=
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1題目11fori=1:6forj=1:7A(i,j)=i+j;endendA
A=
2
3
4
5
6
7
8
3
4
5
6
7
8
9
4
5
6
7
8
9
10
5
6
7
8
9
10
11
6
7
8
9
10
11
12
7
8
9
10
11
12
13%本題還有多種方法第三章符號(hào)計(jì)算題目1略題目2>>sym('0,3')ans=0.3>>sym(0.3)%符號(hào)工具箱得出更精確的解ans=3/10題目3>>symsxs>>f=x^5+3*x^4+4*x^3+2*x^2+3*x+6;g=(s-1)/(s+1);>>f(x)=compose(f,g,x,s)f(x)=(3*(s-1))/(s+1)+(2*(s-1)^2)/(s+1)^2+(4*(s-1)^3)/(s+1)^3+(3*(s-1)^4)/(s+1)^4+(s-1)^5/(s+1)^5+6>>simplify(f(x))ans=19-(72*s^4+120*s^3+136*s^2+72*s+16)/(s+1)^5題目4>>sum(sym(2).^[1:64])ans=題目5f=sym('cos(4*a)-4*cos(2*a)+3');simplify(f)ans=8*sin(a)^4題目6>>f=sym('(3*x+2/3)^10');expand(f)ans=59049*x^10+131220*x^9+131220*x^8+77760*x^7+30240*x^6+8064*x^5+(4480*x^4)/3+(5120*x^3)/27+(1280*x^2)/81+(5120*x)/6561+1024/59049所以系數(shù)最大的項(xiàng)是131220*x^9和131220*x^8題目7>>symsax>>factor(a*(sin(x))^2-(2*a^2-a+1)*sin(x)+2*a-1)ans=(sin(x)-2*a+1)*(a*sin(x)-1)第四章極限與導(dǎo)數(shù)
題目1(1)>>symsx;lim1=limit([cos(x)-exp(-x^2/2)]/x^4,x,0)
lim1=
-1/12(2)>>symsxt;lim2=limit((1+2*t/x)^3*x,x,inf)
lim2=
Inf+imag(t)*6*i(3)>>symsx;lim3=limit(1/x,x,0,'right')
Lim3=Inf(4)>>symsx;lim4=limit((2^x-log(2^x)-1)/(1-cos(x)),x,0)
Lim4=log(2)^2題目2>>symsx;lim=limit((exp(x)-1-x)/x^2,x,0)
lim=1/2題目3>>symsx;lim=limit(x^0.5-2^(-1/x),x,0,'right')lim=
0題目4>>symsx;lim=limit(atan(x)/(1+x^2),x,pi,'left')
lim=atan(pi)/(pi^2+1)題目5>>y=7*x^3-2*x+3;z=diff(y,2);x=1;eval(z)ans=
42題目6>>symsxy;z=exp(x)*sin(2*y)+log(x)*cos(2*y);f=diff(z,y)f=2*cos(2*y)*exp(x)-2*sin(2*y)*log(x)題目7>>
symsxyt;x=t^2*sin(t);y=2*t*cos(t);f=diff(y)/diff(x)f=(2*cos(t)-2*t*sin(t))/(t^2*cos(t)+2*t*sin(t))題目8>>symsx;lim=limit((3^x+9^x)^(1/x),x,inf)
lim=9題目9>>
symsx;lim=limit((1+x)^(1/x),x,0)lim=
exp(1)題目10>>symsx;y=[(x-1)*(x-2)/(x-3)/(x-4)]^0.5;f1=diff(y,1),f2=diff(y,2),f3=diff(y,3)f1=
((x-1)/((x-3)*(x-4))+(x-2)/((x-3)*(x-4))-((x-1)*(x-2))/((x-3)*(x-4)^2)-((x-1)*(x-2))/((x-3)^2*(x-4)))/(2*(((x-1)*(x-2))/((x-3)*(x-4)))^(1/2))
f2=
(2/((x-3)*(x-4))-(2*(x-1))/((x-3)*(x-4)^2)-(2*(x-1))/((x-3)^2*(x-4))-(2*(x-2))/((x-3)*(x-4)^2)-(2*(x-2))/((x-3)^2*(x-4))+(2*(x-1)*(x-2))/((x-3)*(x-4)^3)+(2*(x-1)*(x-2))/((x-3)^2*(x-4)^2)+(2*(x-1)*(x-2))/((x-3)^3*(x-4)))/(2*(((x-1)*(x-2))/((x-3)*(x-4)))^(1/2))-((x-1)/((x-3)*(x-4))+(x-2)/((x-3)*(x-4))-((x-1)*(x-2))/((x-3)*(x-4)^2)-((x-1)*(x-2))/((x-3)^2*(x-4)))^2/(4*(((x-1)*(x-2))/((x-3)*(x-4)))^(3/2))
f3=
(3*((x-1)/((x-3)*(x-4))+(x-2)/((x-3)*(x-4))-((x-1)*(x-2))/((x-3)*(x-4)^2)-((x-1)*(x-2))/((x-3)^2*(x-4)))^3)/(8*(((x-1)*(x-2))/((x-3)*(x-4)))^(5/2))-(6/((x-3)*(x-4)^2)+6/((x-3)^2*(x-4))-(6*(x-1))/((x-3)*(x-4)^3)-(6*(x-1))/((x-3)^2*(x-4)^2)-(6*(x-1))/((x-3)^3*(x-4))-(6*(x-2))/((x-3)*(x-4)^3)-(6*(x-2))/((x-3)^2*(x-4)^2)-(6*(x-2))/((x-3)^3*(x-4))+(6*(x-1)*(x-2))/((x-3)*(x-4)^4)+(6*(x-1)*(x-2))/((x-3)^2*(x-4)^3)+(6*(x-1)*(x-2))/((x-3)^3*(x-4)^2)+(6*(x-1)*(x-2))/((x-3)^4*(x-4)))/(2*(((x-1)*(x-2))/((x-3)*(x-4)))^(1/2))-(3*((x-1)/((x-3)*(x-4))+(x-2)/((x-3)*(x-4))-((x-1)*(x-2))/((x-3)*(x-4)^2)-((x-1)*(x-2))/((x-3)^2*(x-4)))*(2/((x-3)*(x-4))-(2*(x-1))/((x-3)*(x-4)^2)-(2*(x-1))/((x-3)^2*(x-4))-(2*(x-2))/((x-3)*(x-4)^2)-(2*(x-2))/((x-3)^2*(x-4))+(2*(x-1)*(x-2))/((x-3)*(x-4)^3)+(2*(x-1)*(x-2))/((x-3)^2*(x-4)^2)+(2*(x-1)*(x-2))/((x-3)^3*(x-4))))/(4*(((x-1)*(x-2))/((x-3)*(x-4)))^(3/2))題目11>>symsx;y=x*log(x);diff(y,10)
ans=40320/x^9題目12>>symsx;y=exp(-2*x);taylor(y,x,0,'order',6)
ans=
-(4*x^5)/15+(2*x^4)/3-(4*x^3)/3+2*x^2-2*x+1題目13>>symsx;y=x/sin(x);f=taylor(y,x,2,'order',5),ezplot(f)f=((2*(cos(2)^2/sin(2)^2+1/2))/sin(2)-cos(2)/sin(2)^2)*(x-2)^2-((cos(2)/(3*sin(2))+(cos(2)*(cos(2)^2/sin(2)^2+1/2))/sin(2))/sin(2)-(2*(cos(2)^2/(3*sin(2)^2)+(cos(2)*(cos(2)/(3*sin(2))+(cos(2)*(cos(2)^2/sin(2)^2+1/2))/sin(2)))/sin(2)+5/24))/sin(2))*(x-2)^4-((2*cos(2))/sin(2)^2-1/sin(2))*(x-2)-(x-2)^3*((2*(cos(2)/(3*sin(2))+(cos(2)*(cos(2)^2/sin(2)^2+1/2))/sin(2)))/sin(2)-(cos(2)^2/sin(2)^2+1/2)/sin(2))+2/sin(2)
題目14>>symsx1x2x3x4x5x6x7;a=x1/x5;b=[x3/(x2-x1)]^0.85;c=1-0.36*(x4/x2)^(-0.56);d=2.62*c^1.5;e=(x4/x2)^1.16;f=[(1-d*e)/(x6*x7)]^0.5;y=174.42*a*b*f;>>f1=diff(y,x1);f2=diff(y,x2);f3=diff(y,x3);f4=diff(y,x4);f5=diff(y,x5);f6=diff(y,x6);f7=diff(y,x7);x1=0.1;x2=0.3;x4=0.1;x5=1.5;x6=16;x7=0.75;>>eval(f1),eval(f2),eval(f3),eval(f4),eval(f5),eval(f6),eval(f7)ans=
ans=ans=
ans=
ans=
ans=
ans=第五章程序編制題目1略題目2functionf=fib(n)ifn==1|n==2%“|”是或者f=1;elsef=fib(n-1)+fib(n-2);end題目3functiona=countwords(s)d=length(s);n=1;x=0;whilen<dif(isletter(s(n))==0)&(isletter(s(n+1))==1)%前一個(gè)是空格,后一個(gè)是字母n=n+1;x=x+1;elsen=n+1;endendx%最基本的是數(shù)空格,用上面方法可以解決兩個(gè)單詞之間存在多個(gè)空格的問題,而實(shí)際上還是有漏洞,比如字母之間不能夾有其他符號(hào)數(shù)字,單詞要有意義等。(本題只考察數(shù)空格)題目4kilogram=input('kilogram:');kerra=input('kerra:');ounce=input('ounce:');if(kilogram>0)&(isempty(ounce)==1)&(isempty(kerra)==1)ounce=kilogram*1000/28.3495,kerra=kilogram*1000/0.2,endifounce>0&(isempty(kilogram)==1)&(isempty(kerra)==1)kilogram=ounce*28.3495/1000,kerra=ounce*5*28.3495endifkerra>0&(isempty(ounce)==1)&(isempty(kilogram)==1)ounce=kerra/(5*28.3495),kilogram=kerra/5000,end%每次輸入其中一個(gè),輸出另兩個(gè)的換算結(jié)果題目5y=input('enterayear:');m=input('enteramonth:');if(mod(y,400)==0)|((mod(y,4)==0)&(mod(y,100)~=0))switchm,case{1,3,5,7,8,10,12}nday=31;case{4,6,9,11}nday=30;otherwisenday=29;endelseswitchm,case{1,3,5,7,8,10,12}nday=31;case{4,6,9,11}nday=30;otherwisenday=28;endendnday=nday題目6s=input('','s');a=s(1:4);y=str2num(a);b=s(6:7);M=str2num(b);c=s(9:10);D=str2num(c);C=floor(y/100);%世紀(jì)數(shù)Y=mod(y,100);%年份后兩位w=mod((floor(C/4)-2*C+Y+floor(Y/4)+floor(13*(M+1)/5)+D-1),7)%Zeller公式該年的1,2月按13,14計(jì)算。題目7m=input('');ifm<=1500t=0.03*m;elseif(m>1500)&(m<=4500)t=45+0.1*(m-1500);elseif(m>4500)&(m<=9000)t=45+30+0.2*(m-4500);elseif(m>9000)&(m<=35000)t=45+300+900+0.25*(m-9000);elseif(m>35000)&(m<=80000)t=45+300+900+6000+0.35*(m-35000)elsem>80000t=45+300+900+6000+15750+0.45*(m-80000)endt第六章算法入門%習(xí)題一%查鍵盤字符對(duì)應(yīng)的ASCII碼clear,clc%清空變量和屏幕a=input('請(qǐng)輸入您的要加密的字符:\n','s');%輸入加密字符n=length(a);%計(jì)算字符長(zhǎng)度fori=1:n,if(a(i)>=65&&a(i)<=86)||(a(i)>=97&&a(i)<=118),%65和86是字符A與V對(duì)應(yīng)的ASCII碼,同理97和118是a與v對(duì)應(yīng)的ASCII碼b(i)=a(i)+4;elseifa(i)>=87&&a(i)<=90,%87和90是字符W與Z對(duì)應(yīng)的ASCII碼b(i)=a(i)-87+65;elseifa(i)>=118&&a(i)<=122,%118和122是字符w與z對(duì)應(yīng)的ASCII碼b(i)=a(i)-118+97;elseb(i)=a(i);endendb=char(b);%轉(zhuǎn)化為字符串fprintf('轉(zhuǎn)換后的字符為:%s\n',b)%習(xí)題二clc,clearalldisp('計(jì)算日期在當(dāng)年的天數(shù)');month=input('請(qǐng)輸入月份(1-12):');day=input('請(qǐng)輸入日期:');year=input('請(qǐng)輸入年份(yyyy):');%檢查是否為閏年ifmod(year,400)==0leap_day=1;%被400整除的是閏年elseifmod(year,100)==0leap_day=0;%被100整除的不是閏年elseifmod(year,4)==0leap_day=1;%每四年是閏年elseleap_day=0;%余下的不是閏年end%計(jì)算當(dāng)前天并加到當(dāng)年的上一個(gè)月day_of_year=day;forii=1:month-1%從一月加到當(dāng)年上一個(gè)月switch(ii)case{1,3,5,7,8,10,12},day_of_year=day_of_year+31;case{4,6,9,11},day_of_year=day_of_year+30;case2,day_of_year=day_of_year+28+leap_day;endendfprintf('日期%2d/%2d/%4d是這一年的第%d天.\n',month,day,year,day_of_year);%習(xí)題三functionxunhuan(m,n)%算法入門習(xí)題3%定理:一個(gè)分母為N的循環(huán)小數(shù)的循環(huán)節(jié)位數(shù)最多不超過N-1位。%思路:分別用x和y表示分子和分母,先求出整數(shù)部分x/y和余數(shù)部分xmody,%那么小數(shù)部分就是重復(fù)將余數(shù)部分乘以10再進(jìn)行整除運(yùn)算和求余運(yùn)算,直到出現(xiàn)循環(huán)或余數(shù)為0時(shí)結(jié)束。%我們不妨從余數(shù)入手,因?yàn)樾?shù)部分整除的結(jié)果是由上一次運(yùn)算的余數(shù)決定的,%如果某一次運(yùn)算產(chǎn)生的余數(shù)跟前面產(chǎn)生的余數(shù)相同,則說明循環(huán)開始。mn=1000;p=-ones(1,mn);q=zeros(1,mn);t=0;%初始化值r=m;%把被除數(shù)賦給rwhiler~=0&&p(r)==-1%循環(huán)條件當(dāng)r不為0且p[r]=-1時(shí)執(zhí)行循環(huán)體p(r)=t;%余數(shù)r第一次出現(xiàn)的位置r=10*r;%把被除數(shù)擴(kuò)大10倍,以至于取第一個(gè)小數(shù)t=t+1;%q(t)=floor(r/n);%計(jì)算小數(shù)點(diǎn)后t位的值:取整,即為m/n的小數(shù)從小數(shù)點(diǎn)開始逐個(gè)取出放到數(shù)組q中r=mod(r,n);%算完一位就去掉一位,即取余對(duì)nendfprintf('%d/%d=0.',m,n);%因?yàn)閙ifr~=0,%被除數(shù)不為0就執(zhí)行以下語句fori=1:p(r)%輸出循環(huán)小數(shù)中前面非循環(huán)的部分fprintf('%d',q(i));endfprintf('(');%輸出循環(huán)的小數(shù)放在括號(hào)中fori=(p(r)+1):tfprintf('%d',q(i));endfprintf(')\n');else%被除數(shù)為0的情況fori=1:t%輸出不循環(huán)的小數(shù)fprintf('%d',q(i));endfprintf('\n');end%習(xí)題四functionb=xuanzhuan(a)[m,n]=size(a);%求矩陣a的行列數(shù)b=zeros(m,n);%初始化fori=1:floor(m/2)%前m/2行左移一位forj=i:n-ib(i,j)=a(i,j+1);endendforj=1:floor(n/2)%前n/2列下移一位fori=j+1:m-j+1b(i,j)=a(i-1,j);endendfori=floor(m/2)+1:m%后m/2行右移一位forj=m-i+2:n-(m-i)b(i,j)=a(i,j-1);endendforj=floor(n/2)+1:n%后n/2列上移一位fori=n-j+1:m-(n-j)-1b(i,j)=a(i+1,j);endend%習(xí)題五n=input('pleaseinputyourn:')A=4*eye(n)s=-1*ones(1,n-1)B=diag(s,-1)C=diag(s,1)D=A+B+CE=inv(D)E(1,1)%習(xí)題六functionKapreka(n)%設(shè)M^2是雷劈數(shù),可以分割成x和y兩部分,且M=x+y,y為n位數(shù),則M^2=10^n*x+y(雷劈數(shù)定理)a=10.^[0:n];b=10.^[1:n]-1;fori=1:n[x,y]=meshgrid(1:b(i),1:b(i));idx=find((x+y).^2==x*a(i+1)+y);p=x(idx)*a(i+1)+y(idx)end方法二functiony=kapreka(n)fori=1:n;n=num2str(i);m=length(n);ifmod(m,2)==0;x=floor(i/(10^(m/2)));y=i-x*10^(m/2);if(x+y)^2==i;y=iendendend%習(xí)題七functionx=gys(a,b)c=mod(a,b);ifc==0x=b;elsex=gys(b,c);end%習(xí)題八functionhws(n)fori=1:na=[10^(i-1):(10^i-1)]';b=num2str(a);fork=1:fix(i/2)m=b(:,k)~=b(:,i-k+1);b(m,:)=[];endbend第七章集合和向量的基本運(yùn)算題目1n=input('thenumberofwords:'),ifn>=2A1=cell(n,1);o=0;fori=1:nA1{i,1}=input('oneofthewords:','s');endj=1;whilej<ns=A1{j,1};b=length(s);k=j+1;whilek<=nt=A1{k,1};d=length(t);u=setxor(s,t);if((b==d)&(length(u)==2))|(((b==d+1)|(d==b+1))&(length(u)<=1))[s,'',t],o=o+1;endk=k+1;endj=j+1;endifo==0;'none'endelse'wrong'end題目2y=[2,7,8]’;s=sqrt(dot(y,y)),1=[1,0,0]’;m=[0,1,0]’;n=[0,0,1]’;a=acos(dot(y,1)/s),b=acos(dot(y,m)/s),c=acos(dot(y,n)/s),k=(cos(a))^2+(cos(b))^2+(cos(c))^2題目3f=[2,-1,2,1]’;p=[2,-1,3]’;d=abs(dot(f,[p,1]))/norm(f(1:3))題目4A=[1,2,3];B=[-2,-4,-6];C=[3,6,9];rank([A;B]),rank([A;B;C])%matlab中rank()函數(shù)是求矩陣的秩,[A;B]構(gòu)成一個(gè)矩陣,當(dāng)這個(gè)矩陣的秩為1時(shí),A,B共線.所以A,B共線,A,B,C共面。題目5P=[2,4,5]’;Q=[2,-3,1]’;V=[3,7,-3]’;PQ=Q-P;c=dot(PQ,V)/(norm(PQ)*norm(V));O=Q-c*V,R=2*(O-P)+P題目6R=cell(1,13);B=cell(1,13);fori=1:13R{1,i}=input('cards','s');endB=cell(1,13);B{1,1}=R{1,2};B{1,2}=R{1,4};B{1,3}=R{1,6};B{1,4}=R{1,8};B{1,5}=R{1,10};B{1,6}=R{1,12};B{1,7}=R{1,1};B{1,8}=R{1,5};B{1,9}=R{1,9};B{1,10}=R{1,13};B{1,11}=R{1,7};B{1,12}=R{1,3};B{1,13}=R{1,11};B題目7A=cell(3,3);whilesum(sum(S>0))<81A{1,1}=S(1:3,1:3);A{1,2}=S(1:3,4:6);A{1,3}=S(1:3,7:9);A{2,1}=S(4:6,1:3);A{2,2}=S(4:6,4:6);A{2,3}=S(4:6,7:9);A{3,1}=S(7:9,1:3);A{3,2}=S(7:9,4:6);A{3,3}=S(7:9,7:9);fori=1:9forj=1:9X=[123456789];ifS(i,j)==0a=ceil(i/3);b=ceil(j/3);form=1:9%行不重復(fù)ifS(i,m)>0X(S(i,m))=0;endendforn=1:9%列不重復(fù)ifS(n,j)>0X(S(n,j))=0;endendB=A{a,b};forp=1:3%宮內(nèi)不重復(fù)forq=1:3ifB(p,q)>0X(B(p,q))=0;endendendendifsum(X>0)==1S(i,j)=sum(X);endendendendS%本題答案只用了書上的方法,且只能夠解出書上例題難度的題目。第八章圖形的繪制題目1x=linspace(0,4*pi,8000);y1=sin(x);y2=cos(x);y4=0;plot(x,y1,’k’);holdon;plot(x,y2,’k’);xlabel(‘x’);ylabel(‘y’);plot(x,y4,’k’);holdon;plot(x,y2,’k’);xlabel(‘x’);ylabel(‘y’);plot(x,y4,;’k’);plot(y4,x,’k’);title(‘y1=sin(x)y2=cos(x)’);x1=linspace(0,0.5*pi,1000);y3=sin(x1);fill([x1,pi/2],[y3,0],’r’)題目2Subplot(2,2,1);x=0:pi/60:2*pi,plot(x,sin(2*x));Subplot(2,2,2);y=0:pi/60:0.499*pi;plot(y,tan(y));Subplot(2,2,3);plot(x,log(x));Subplot(2,2,4);plot(x,exp(log(10)*x));題目3X=[213,387,220,280,280,180];Pie3(x)題目3X=[1:6];Y=[213,387,220,280,280,180]Bar(x,y),set(gca,’XTicklabel’,{‘計(jì)算機(jī)系’;’外語系’;’音樂系’;’美術(shù)系’;’中文系’;’理學(xué)院’}),Set(gca,’XTick’,[1:6]),xlabel(‘專業(yè)’),ylabel(‘人數(shù)’),title(‘各專業(yè)學(xué)生分布’)%這樣做出的柱狀圖就跟excel差不多題目4x=linspace(-3,3);y=linspace(-2,2);[X,Y]=meshgrid(x,y);f=X.^2+(abs(X).*exp(Y))./(X.^4+1);Mesh(X,Y,f)%注意矩陣維度要一樣題目5t=linspace(0,2*pi);x=sin(t);y=t.^2+exp(t);comet(x,y)題目6(a)theta=0:0.01:4*pi;polar(theta,rho);(b)theta=0:0.01:6*pi;rho=sin(theta)./theta;polar(theta,rho);(c)theta=0:0.01:2*pi;rho=1-(cos(7.*theta)).^3;polar(theta,rho);題目7functionqiu(R)axis('equal');%橫縱坐標(biāo)相等使其看起來更圓a=linspace(0,2*pi);b=linspace(0,2*pi);[A,B]=meshgrid(a,b);X=R.*cos(B).*cos(A);Y=R.*cos(B).*sin(A);Z=R.*sin(B);mesh(X,Y,Z)functionxuanzhuanqumian1(a,b,c)R=linspace(1,4);T=linspace(0,2*pi);[r,t]=meshgrid(R,T);z1=c.*sqrt(r.^2-1);z2=-c.*sqrt(r.^2-1);mesh(x,y,z1);holdon;mesh(x,y,z2);第九章線性方程組題目1A=[1,2,3,4;2,2,1,1;2,4,6,8;4,4,2,2];B=[1,2,3,4]';x=sym(null(A));題目2A=[2,-9,3,-2,6;10,-2,-7,4,0;8,4,6,-6,9;-5,-6,-6,2,3];B=[-2.9,2.7,4.5,-1.9]';x=sym(pinv(A)*B);y=pinv(A)*B;題目3A=[16,2,3,13;5,11,10,8;9,4,6,2;4,14,15,2];B=[1,3,4,8]';[rank(A),rank([AB])];所以方程組有唯一解。題目4A=[2,0,0,-1,0,0;3,0,0,0,0,-1;12,3,1,-3,-2,-4;0,1,0,0,0,-1;0,1,0,0,0,-1;0,1,0,0,-1,0;0,0,2,-3,0,0];N=null(sym(A));3*N題目5A=[101000000000;000000000101;000101-10-1000;00100-10-10000;1-10-100000000;000010100-100;00000000101-1;11-101-1-1-110-10;010-1110-101-1-10000000100-10;11-10100-101-1-1];b=[1,1,0,0,0,0,0,0,0,0,0,0,]';x=sym(A\b);Rab=x(1)+x(2)+x(5)+x(10)同理A=[101000000000;000000000101;000101-10-1000;00100-10-10000;1-10-100000000;000010100-100;00000000101-1;11-101-1-1-110-10;010-1110-101-1-10000000100-10;11-10100-101-1-1];b=[1,0,1,0,0,0,0,0,0,0,0,0,]';x=sym(A\b);Rab=x(1)+x(4)%本題的思路是設(shè)從a流入的電流為1(默認(rèn)每個(gè)電阻阻值為1),則從b流出的電流也為1,再用基爾霍夫定律求出各電流下x(i),然后算出Uab,因?yàn)榭傠娏魇?,則Rab在數(shù)值上等于Uab=x(1)+x(2)+x(5)+x(10))第十章多項(xiàng)式和非線性方程題目1p=[3,0,2,0,-1];q=[0,0,3,2,1];q0=[3,2,1];p+q,p-q,conv(p,q0),[q1,r1]=deconv(p,q0)題目2p=[1,2,1];r=roots(p),q=[3,7,2];s=roots(q);polyval(p,r);polyval(q,s)題目3p=[20:-1:11];p1=polyder(p);poly2sym(p1);q=0:0.2:2;polyval(p,0:0:2:q);題目4ezplot('5*x^4-sin(2*x)',[0,1]);holdon;line([0,1],[0,0]);%圖像法fsolve('5*x^4-sin(2*x)');fsolve('5*x^4-sin(2*x)',0.7);%數(shù)值法題目5(1)functionp=legendre1(n)ifn==0p=[1];elseifn==1p=[1,0];elsep=[(2*n-1).*[legendre1(n-1),0]-(n-1).*[0,0,legendre1(n-2)]]./n;end%畫圖x=linspace(-1,1,1000);y=polyval(p,x);clf;holdon;plot(x,y,'b-');(2)functionp=legendre2(n)p=[1];p1=[1,0,1];fori=1:np=conv(p,p1);endfori=1:np=polyder(p)./(2*i);end%畫圖x=linspace(-1,1,1000);y=polyval(p,x);clf;holdon;plot(x,y,'b-');題目6functiond=zhishu(n)%這個(gè)函數(shù)用來判斷該數(shù)是否是質(zhì)數(shù)d=0;ifn==2|n==3d=0;elseifn>3fori=2:floor(sqrt(n))ifmod(n,i)==0d=1;endendendfunctioni=oulapoly(p)%這個(gè)函數(shù)用來找第幾個(gè)數(shù)出現(xiàn)合數(shù)i=1;q=polyval(p,1);whilezhishu(q)==0i=i+1;q=polyval(p,i);endfunctionjianduan(p,q)clf;holdon;x1=roots(q);x1=sort(x1);n=length(x1);ifn>0fori=2:nx=linspace(x1(i-1),x1(i),1000);x=x(2:999);y=polyval(p,x)./polyval(q,x);m(i)=max(y);l(i)=min(y);plot(x,y,'b-');endx2=linspace(x1(1)-1,x1(1),1000);x2=x2(1:999);y2=polyval(p,x2)./polyval(q,x2);m(1)=max(y2);l(1)=min(y2);plot(x2,y2,'b-');x3=linspace(x1(n),x1(n)+1,1000);x3=x3(2:1000);y3=polyval(p,x3)./polyval(q,x3);m(n+1)=max(y3);l(n+1)=min(y3);plot(x3,y3,'b-');fori=1:nplot([x1(i),x1(i)],[min(l),max(m)],'r-');%畫出間斷線endendend第十一章積分與數(shù)值積分題目1symsx;f=1/((sin(x))^2*(cos(x))^2);int(f,x)題目2functionf1=f1(x)f1=exp(-x.^2);s1=quad('f1',1,2)題目3symsxy;f=x^2+y^2+1;int(int(f,x,x,x+1),y,0,1)題目4symsx;f=(1-sin(2*x))^(1/2);int(f,x,0,pi/2)題目5symsxab;f=x*exp(a*x)*cos(b*x);int(f,x)題目6symsx;f=cos(x)/x^(1/2);int(f,x,0,+inf)題目7symsx;f=x^2*log(x^2);int(f,x)題目8x=[0,2,4,6,8,10,12,14,16,18];y=[0,2.3,2.7,2.9,3.3,3.4,3.5,3.0,1.8,0];p=polyfit(x,y,10);%10的擬合程度非常好f=poly2sym(p);int(f,0,18)題目9functionpwxjf(f,a,b)s0=quad(f,a,b);fork=1:8clf;holdon;n=2^(k+1);x=linspace(a,b,n+1);y=feval(f,x);s=0;fori=1:2:n-1x1=x(i:i+2);y1=y(i:i+2);x2=linspace(x(i),x(i+2));f1=polyfit(x1,y1,2);y2=polyval(f1,x2);s=s+(b-a)/3/n*[y(i)+4*y(i+1)+y(i+2)];patch([x2,x(i+2),x(i)],[y2,0,0],'b');endtitle(num2str(abs((s-s0)/s0)),'fontsize',12);pause(1);end第十二章插值問題題目1x=[01/61/41/31/2]*pi;y=sqrt(4:-1:0)/2;y1=lagrange(x,y,pi/8)題目2將不同函數(shù)代入即可。(1)出現(xiàn)振蕩現(xiàn)象。(2)不出現(xiàn)振蕩現(xiàn)象。(3)不出現(xiàn)振蕩現(xiàn)象。題目3functiony1=interp1linear(x,y,x1)y1=x1;fori=1:length(x1)xx=x1(i);a=find(x<=xx);b=find(x>=xx);a1=a(end);b1=b(1);ifa1==b1y1(i)=y(a1);elsez=polyfit([x(a1),x(b1)],[y(a1),y(b1)],1);y1(i)=polyval(z,xx);endend題目4x=1:10;y=[244.0,221.0,208.0,211.5,216.0,219.0,208.0,213.5,220.5,232.7];xx=linspace(1,10);yy=interp1(x,y,xx,'linear');plot(x,y,'o',xx,yy,'r-')pp1=csape(x,[0y0],'second');yy1=ppval(pp1,xx);plot(xx,yy1,'r-');題目5x=[0.10.81.31.92.53.1];y=[1.21.62.72.01.30.5];lagrange(x,y,2),interp1(x,y,2,'linear'),interp1(x,y,2,'spline'),題目6(1)拉格朗日法x=[035791112131415];y=[01.21.72.02.12.01.81.21.01.6];xx=0:0.1:15;xx
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 借款合同范本中介版
- 云南購房合同范本
- 從化學(xué)校食堂承包合同范本
- 保潔公司人員合同范本
- pu線條安裝合同范本
- fob合同范本日文
- 包架子合同范本
- 公司代管合同范本
- 共同經(jīng)營(yíng)餐廳合同范本
- 三方合作民宿協(xié)議合同范本
- 智能財(cái)務(wù)共享在京東的應(yīng)用研究
- 衛(wèi)生和微生物基礎(chǔ)知識(shí)培訓(xùn)-
- 2023年鎮(zhèn)江市高等??茖W(xué)校單招綜合素質(zhì)題庫及答案解析
- XX攔河堰工程施工組織設(shè)計(jì)
- GB/T 9787-1988熱軋等邊角鋼尺寸、外形、重量及允許偏差
- GB/T 7031-2005機(jī)械振動(dòng)道路路面譜測(cè)量數(shù)據(jù)報(bào)告
- 馬工程教材《公共財(cái)政概論》PPT-第十二章 財(cái)政體制
- GB/T 23457-2009預(yù)鋪/濕鋪防水卷材
- GB/T 17614.1-2015工業(yè)過程控制系統(tǒng)用變送器第1部分:性能評(píng)定方法
- 財(cái)務(wù)工作督導(dǎo)檢查記錄表
- 輿情大數(shù)據(jù)監(jiān)測(cè)平臺(tái)建設(shè)方案
評(píng)論
0/150
提交評(píng)論