基于matlab的科學(xué)計(jì)算實(shí)驗(yàn).doc_第1頁
基于matlab的科學(xué)計(jì)算實(shí)驗(yàn).doc_第2頁
基于matlab的科學(xué)計(jì)算實(shí)驗(yàn).doc_第3頁
基于matlab的科學(xué)計(jì)算實(shí)驗(yàn).doc_第4頁
基于matlab的科學(xué)計(jì)算實(shí)驗(yàn).doc_第5頁
已閱讀5頁,還剩18頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

科學(xué)計(jì)算與數(shù)據(jù)處理實(shí)驗(yàn)報(bào)告學(xué)號(hào)S311060149姓名張園實(shí)驗(yàn)名稱基于MATLAB的科學(xué)計(jì)算實(shí)驗(yàn)實(shí)驗(yàn)?zāi)康?、 掌握MATLAB中數(shù)組的創(chuàng)建和操作方法2、 掌握MATLAB中常用的數(shù)值計(jì)算方法3、 掌握MATLAB中常用的符號(hào)計(jì)算方法實(shí)驗(yàn)方案一、 一維數(shù)組創(chuàng)建實(shí)驗(yàn):(1)直接輸入法: test=1 2 3 4 test=1;2;3;4(2)步長生成法: test=1:0.5:10(3)定數(shù)線性采樣法: test = linspace(1,12,5)(4)定數(shù)對(duì)數(shù)采樣法: logspace(2,6,4)二、 高維數(shù)組創(chuàng)建實(shí)驗(yàn):(1)直接輸入法: A=1 2 3;4 5 6;7 8 9(2)使用下標(biāo): clear,A(2,3,2)=1(3)使用低維數(shù)組:clear,A=eye(3,4);A(:,:,2)=eye(3,4)*2;A(:,:,3)=eye(3,4)*3;A(:,:,4)=eye(3,4)*4(4)使用創(chuàng)建函數(shù)(cat、repmat、reshape)創(chuàng)建高維數(shù)組: cat(3,1,2,3;4,5,6,eye(2,3)*2,ones(2,3) repmat(1,2;3,4,1,2,3) reshape(1:20,2,5,2)三、標(biāo)準(zhǔn)數(shù)組創(chuàng)建實(shí)驗(yàn):(1)全0矩陣: zeros(3)(2)全1矩陣: ones(5)(3)單位矩陣: eye(4)(4)magic矩陣: magic(4)(5)隨機(jī)矩陣: randn(4)四、矩陣變換實(shí)驗(yàn):令Data=1,2,3,4;5,6,7,8;9,10,11,12,分別使用diag、fliplr、flipud、rot90、tril、triu函數(shù)計(jì)算Data的對(duì)角、轉(zhuǎn)置、翻轉(zhuǎn)、旋轉(zhuǎn)、三角矩陣,具體命令如下: Data=1,2,3,4;5,6,7,8;9,10,11,12 diag(Data)(Data) fliplr(Data) flipud(Data) rot90(Data) tril(Data) triu(Data)五、字符串?dāng)?shù)組創(chuàng)建與操作實(shí)驗(yàn):(1)創(chuàng)建字符串?dāng)?shù)組: arr=str2mat(I,am,a,student)(2)去掉字符串末尾的空格deblank::建立字符串,用abs函數(shù)驗(yàn)證空格的存在;用deblank去掉空格,用abs已經(jīng)去掉空格 x=a n ;y=abs(x) z=deblank(x);w=abs(z)(3) 刪除字符串開頭和結(jié)尾的空格strtrim str1= I am a student ; str2=I am a student ; x=strtrim(str1) y=strtrim(str2) (4) 執(zhí)行簡單的字符串替代strrep、 str1=I am a student.; str2=student; str3=teacher; str=strrep(str1,str2,str3)(5)規(guī)范格式strread; strread(0.231,%5.3f)(6) 函數(shù)strtok找出由特定字符指定的字符串內(nèi)的標(biāo)記; ar=I am a student strtok(ar,s)六、 架構(gòu)數(shù)組的創(chuàng)建與操作實(shí)驗(yàn):(1) 直接創(chuàng)建法: clear x; x.real = 1 2 3 4 5; x.imag = ones(4)(2) 命令(struct)創(chuàng)建法 s = struct(name,x,y,id,3,4,w,3,4)(3) Fieldnames函數(shù): fieldnames(s)(4) Getfield函數(shù): str(1,1).name = x; str(1,1).ID = 5; str(2,1).name = y; str(2,1).ID = 3; result = getfield(str, 2,1, name)(5) Setfield函數(shù): str(1,1).name = x; str(1,1).ID = 5; str(2,1).name = y; str(2,1).ID = 3; str= setfield(str,2,1,name,a); str(2,1).name七、 基本運(yùn)算符號(hào)實(shí)驗(yàn):(1)矩陣加: a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a+b(2)矩陣減: a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a-b(3)矩陣乘 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a*b(4)數(shù)組乘 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a.*b(5)矩陣乘方 a=1,2,3;4,5,6;7,8,9; a2(6)數(shù)組乘方 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a.b(7)矩陣左除 a=1,2,3;4,5,6;7,8,9; b=2;4;6;ab(8)矩陣右除 a=ones(3); b=1,1,1; a/b(9)數(shù)組左除 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a.b(10)數(shù)組右除 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a./b(11)克羅內(nèi)克張量積 a=1,0,1;1,1,1;1,0,1; b=0,0,1;1,0,1;0,0,1;kron(a,b)(12)邏輯與 a=1,0,1;1,1,1;1,0,1; b=0,0,1;1,0,1;0,0,1;a&b(13)邏輯或 a=1,0,1;1,1,1;1,0,1; b=0,0,1;1,0,1;0,0,1;a|b(14)邏輯非 a=1,0,1;1,1,1;1,0,1; a(15)邏輯異或 a=1,0,1;1,1,1;1,0,1; b=0,0,1;1,0,1;0,0,1;xor(a,b)八、 矩陣分析實(shí)驗(yàn):(1)范數(shù)(norm): a=1,2,3;4,5,6;7,8,9; norm(a,1) norm(a,2)(2)條件數(shù)(cond): cond(a)(3)行列式(det): det(a)(4)秩(rank): rank(a)(5)特征值(eig): eig(a) V,D=eig(a)(6)化零矩陣(null) Z=null(a)(7)Cholesky分解(chol) a=pascal(3) a=pascal(3);chol(a)(8)LU分解(lu) a=1,2,3;4,5,6;7,8,9; L1,U1=lu(a)(9)正交分解(qr) a=1,2,3;4,5,6;7,8,9; U,S=qr(a)(10)奇異值分解(svd): a=1,2,3;4,5,6;7,8,9; U,S,V=svd(a)九、 數(shù)值計(jì)算實(shí)驗(yàn):(1) 導(dǎo)數(shù)(diff): a=x3+4*x2-x+20 diff(a)(2) 梯度(gradient) a=1,2,3;4,5,6;7,8,9; fx,fy=gradient(a)(3) 多項(xiàng)式求根(roots)、 p=1,3,2,5;px=poly2str(p,x);r=roots(p)/ p是多項(xiàng)式的MATLAB描述方法,我們可用poly2str(p,x)函數(shù),來顯示多項(xiàng)式的形式,px =x3 +3 x2 +2 x +5(4) 零點(diǎn)(fzero、fsolve): a=(x)x2+3*x+2; x=fzero(a,0) x=fsolve(x2+3*x+2,0)(5) 極值(fminbnd、fminsearch、fminunc)、1; f=(x) x2-4*x+5; fminbnd(f,0,1)2; fun=inline(x(1)2-3*x(1)*x(2)+2*x(2)2);x0=1,1; fminsearch(fun,x0)3; fun=inline(x(1)2-3*x(1)*x(2)+2*x(2)2);x0=1,1; fminunc(fun,x0)(6) 積分(quadl)用內(nèi)聯(lián)函數(shù)定義被積函數(shù): fun=inline(-x.*x,x); y=quadl(fun,0,1)十、 符號(hào)計(jì)算實(shí)驗(yàn):(1)將化簡:先用syms定義符號(hào)變量,再用simplify函數(shù)進(jìn)行化簡,具體命令如下: simplify(cos(x)+sqrt(-sin(x)2)(2)求的解:用solve函數(shù)求解,命令如下: x=solve(x+2)x=2,x)實(shí)驗(yàn)記錄一、(1) test=1 2 3 4test = 1 2 3 4 test=1;2;3;4test = 1 2 3 4(2) test=1:0.5:10test = Columns 1 through 4 1.0000 1.5000 2.0000 2.5000 Columns 5 through 8 3.0000 3.5000 4.0000 4.5000 Columns 9 through 12 5.0000 5.5000 6.0000 6.5000 Columns 13 through 16 7.0000 7.5000 8.0000 8.5000 Columns 17 through 19 9.0000 9.5000 10.0000(3) test = linspace(1,12,5)test = Columns 1 through 4 1.0000 3.7500 6.5000 9.2500 Column 5 12.0000(4) logspace(2,6,4)ans = 1.0e+006 * 0.0001 0.0022 0.0464 1.0000二、(1) 直接輸入法 A=1 2 3;4 5 6;7 8 9A = 1 2 3 4 5 6 7 8 9(2)使用下標(biāo) clear,A(2,3,2)=1A(:,:,1) = 0 0 0 0 0 0A(:,:,2) = 0 0 0 0 0 1 (3)使用低維數(shù)組 clear,A=eye(3,4);A(:,:,2)=eye(3,4)*2;A(:,:,3)=eye(3,4)*3;A(:,:,4)=eye(3,4)*4A(:,:,1) = 1 0 0 0 0 1 0 0 0 0 1 0A(:,:,2) = 2 0 0 0 0 2 0 0 0 0 2 0A(:,:,3) = 3 0 0 0 0 3 0 0 0 0 3 0A(:,:,4) = 4 0 0 0 0 4 0 0 0 0 4 0(4)使用創(chuàng)建函數(shù)(cat、repmat、reshape)創(chuàng)建高維數(shù)組。1, cat(3,1,2,3;4,5,6,eye(2,3)*2,ones(2,3)ans(:,:,1) = 1 2 3 4 5 6ans(:,:,2) = 2 0 0 0 2 0ans(:,:,3) = 1 1 1 1 1 12, repmat(1,2;3,4,1,2,3)ans(:,:,1) = 1 2 1 2 3 4 3 4ans(:,:,2) = 1 2 1 2 3 4 3 4ans(:,:,3) = 1 2 1 2 3 4 3 43, reshape(1:20,2,5,2)ans(:,:,1) = 1 3 5 7 9 2 4 6 8 10ans(:,:,2) = 11 13 15 17 19 12 14 16 18 20三、(1) zeros(3)ans = 0 0 0 0 0 0 0 0 0(2) ones(5)ans = 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(3) eye(4)ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1(4) magic(4)ans = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1(5) randn(4)ans = 1.0668 0.2944 -0.6918 -1.4410 0.0593 -1.3362 0.8580 0.5711 -0.0956 0.7143 1.2540 -0.3999 -0.8323 1.6236 -1.5937 0.6900四、(1) Data=1,2,3,4;5,6,7,8;9,10,11,12Data = 1 2 3 4 5 6 7 8 9 10 11 12 diag(Data)ans = 1 6 11(2) (Data)ans = 1 5 9 2 6 10 3 7 11 4 8 12(3) fliplr(Data)ans = 4 3 2 1 8 7 6 5 12 11 10 9(4) flipud(Data)ans = 9 10 11 12 5 6 7 8 1 2 3 4(5) rot90(Data)ans = 4 8 12 3 7 11 2 6 10 1 5 9(6) tril(Data)ans = 1 0 0 0 5 6 0 0 9 10 11 0(7) triu(Data)ans = 1 2 3 4 0 6 7 8 0 0 11 12五、(1) arr=str2mat(I,am,a,student)arr =I am a student(2) x=a n ;y=abs(x)y = 97 32 110 32 z=deblank(x);w=abs(z)w = 97 32 110(3) str1= I am a student ; str2=I am a student ; x=strtrim(str1)x =I am a student y=strtrim(str2)y =I am a student(4) str1=I am a student.; str2=student; str3=teacher; str=strrep(str1,str2,str3)str =I am a teacher.(5) strread(0.231,%5.3f)ans = 0.2310(6) ar=I am a studentar =I am a student strtok(ar,s)ans =I am a六;(1)直接法 clear x; x.real = 1 2 3 4 5; x.imag = ones(4)x = real: 1 2 3 4 5imag: 4x4 double(2)struct函數(shù) s = struct(name,x,y,id,3,4,w,3,4)s = 1x2 struct array with fields: name id w(3) fieldnames功能演示 fieldnames(s)ans = name id w(4) getfield功能演示 str(1,1).name = x; str(1,1).ID = 5; str(2,1).name = y; str(2,1).ID = 3; result = getfield(str, 2,1, name)result =y(5) setfield功能演示 str(1,1).name = x; str(1,1).ID = 5; str(2,1).name = y; str(2,1).ID = 3; str= setfield(str,2,1,name,a); str(2,1).nameans =a七:(1) 矩陣加 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a+bans = 4 8 12 5 7 9 9 12 15(2)矩陣減 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a-bans = -2 -4 -6 3 3 3 5 4 3(3)矩陣乘 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a*bans = 11 22 33 29 58 8747 94 141(4)數(shù)組乘 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a.*bans = 3 12 27 4 10 1814 32 54(5)矩陣乘方 a=1,2,3;4,5,6;7,8,9; a2ans = 30 36 42 66 81 96 102 126 150(6)數(shù)組乘方 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a.bans = 1 64 19683 4 25 216 49 4096 531441(7)矩陣左除 a=1,2,3;4,5,6;7,8,9; b=2;4;6;abWarning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.203039e-018.ans = -0.4667 0.9335 0.1999(8)矩陣右除 a=ones(3); b=1,1,1; a/bans = 1 1 1(9)數(shù)組左除 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a.bans = 3.0000 3.0000 3.0000 0.2500 0.4000 0.5000 0.2857 0.5000 0.6667(10)數(shù)組右除 a=1,2,3;4,5,6;7,8,9; b=3,6,9;1,2,3;2,4,6; a./bans = 0.3333 0.3333 0.3333 4.0000 2.5000 2.0000 3.5000 2.0000 1.5000(11)克羅內(nèi)克張量積 a=1,0,1;1,1,1;1,0,1; b=0,0,1;1,0,1;0,0,1;kron(a,b)ans = 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 0 1(12)邏輯與 a=1,0,1;1,1,1;1,0,1; b=0,0,1;1,0,1;0,0,1;a&bans = 0 0 1 1 0 1 0 0 1(13)邏輯或 a=1,0,1;1,1,1;1,0,1; b=0,0,1;1,0,1;0,0,1;a|bans = 1 0 1 1 1 1 1 0 1(14)邏輯非 a=1,0,1;1,1,1;1,0,1; aans = 0 1 0 0 0 0 0 1 0(15)邏輯異或 a=1,0,1;1,1,1;1,0,1; b=0,0,1;1,0,1;0,0,1;xor(a,b)ans = 1 0 0 0 1 0 1 0 0八、(1)范數(shù)(norm)用來度量矩陣或者向量在某種意義下的長度 a=1,2,3;4,5,6;7,8,9; norm(a,1)ans = 18 norm(a,2)ans = 16.8481(2)條件數(shù)(cond)可以描述矩陣為良性矩陣還是病態(tài)矩陣的一個(gè)參數(shù) cond(a)ans = 5.0524e+016(3)行列式(det) det(a)ans = 0(4)秩(rank) rank(a)ans = 2(5)特征值(eig) eig(a)ans = 16.1168 -1.1168 -0.0000 V,D=eig(a)V = -0.2320 -0.7858 0.4082 -0.5253 -0.0868 -0.8165 -0.8187 0.6123 0.4082D = 16.1168 0 0 0 -1.1168 0 0 0 -0.0000(6)化零矩陣(null) Z=null(a)Z = -0.4082 0.8165 -0.4082(7)Cholesky分解(chol)把對(duì)稱正定矩陣表示成上三角矩陣的轉(zhuǎn)置與其本身的乘積 a=pascal(3) /pascal矩陣a = 1 1 1 1 2 3 1 3 6 a=pascal(3);chol(a)ans = 1 1 1 0 1 2 0 0 1(8)LU分解(lu) a=1,2,3;4,5,6;7,8,9; L1,U1=lu(a)L1 = 0.1429 1.0000 0 0.5714 0.5000 1.0000 1.0000 0 0U1 = 7.0000 8.0000 9.0000 0 0.8571 1.7143 0 0 -0.0000(9)正交分解(qr) a=1,2,3;4,5,6;7,8,9; U,S=qr(a)U = -0.1231 0.9045 0.4082 -0.4924 0.3015 -0.8165 -0.8616 -0.3015 0.4082S = -8.1240 -9.6011 -11.0782 0 0.9045 1.8091 0 0 -0.0000(10)奇異值分解(svd) a=1,2,3;4,5,6;7,8,9; U,S,V=svd(a)U = -0.2148 0.8872 0.4082 -0.5206 0.2496 -0.8165 -0.8263 -0.3879 0.4082S = 16.8481 0 0 0 1.0684 0 0 0 0.0000V = -0.4797 -0.7767 -0.4082 -0.5724 -0.0757 0.8165 -0.6651 0.6253 -0.4082九(1)導(dǎo)數(shù) a=x3+4*x2-x+20a =x3+4*x2-x+20 diff(a) ans = 3*x2+8*x-1 diff(a,2) ans = 6*x+8(2)梯度 a=1,2,3;4,5,6;7,8,9; fx,fy=gradient(a)fx = 1 1 1 1 1 1 1 1 1fy = 3 3 3 3 3 3 3 3 3(3)多項(xiàng)式求根 p=1,3,2,5;px=poly2str(p,x);r=roots(p)/ p是多項(xiàng)式的MATLAB描述方法,我們可用poly2str(p,x)函數(shù),來顯示多項(xiàng)式的形式,px =x3 +3 x2 +2 x +5r = -2303/793 -205/4278 + 851/649i -205/4278 - 851/649i(4)零點(diǎn) a=(x)x2+3*x+2; x=fzero(a,0)x = -1 x=fsolve(x2+3*x+2,0)Optimization terminated: first-order optimality is less than options.TolFun.x = -1(5)極值1; f=(x) x2-4*x+5; fminbnd(f,0,1)ans =0.99992; fun=inline(x(1)2-3*x(1)*x(2)+2*x(2)2);x0=1,1; fminsearch(fun,x0)Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: -448408571070688420000000000000000000000000000000000000000000

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論