資源描述:
《第06章_MATLAB數(shù)值計算_例題源程序匯總》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、....第6章MATLAB數(shù)值計算例6.1求矩陣A的每行及每列的最大和最小元素,并求整個矩陣的最大和最小元素。A=[13,-56,78;25,63,-235;78,25,563;1,0,-1];max(A,[],2)%求每行最大元素min(A,[],2)%求每行最小元素max(A)%求每列最大元素min(A)%求每列最小元素max(max(A))%求整個矩陣的最大元素。也可使用命令:max(A(:))min(min(A))%求整個矩陣的最小元素。也可使用命令:min(A(:))例6.2求矩陣A的每行元素的乘積和全部元素的乘積。A=
2、[1,2,3,4;5,6,7,8;9,10,11,12];S=prod(A,2)prod(S)%求A的全部元素的乘積。也可以使用命令prod(A(:))例6.3求向量X=(1!,2!,3!,…,10!)。X=cumprod(1:10)例6.4對二維矩陣x,從不同維方向求出其標(biāo)準(zhǔn)方差。x=[4,5,6;1,4,8]%產(chǎn)生一個二維矩陣xy1=std(x,0,1)y2=std(x,1,1)y3=std(x,0,2)y4=std(x,1,2)例6.5生成滿足正態(tài)分布的10000×5隨機矩陣,然后求各列元素的均值和標(biāo)準(zhǔn)方差,再求這5列隨機數(shù)
3、據(jù)的相關(guān)系數(shù)矩陣。X=randn(10000,5);M=mean(X)D=std(X)R=corrcoef(X)word格式編輯....例6.6對下列矩陣做各種排序。A=[1,-8,5;4,12,6;13,7,-13];sort(A)%對A的每列按升序排序-sort(-A,2)%對A的每行按降序排序[X,I]=sort(A)%對A按列排序,并將每個元素所在行號送矩陣I例6.7給出概率積分的數(shù)據(jù)表如表6.1所示,用不同的插值方法計算f(0.472)。表6.1概率積分?jǐn)?shù)據(jù)表x0.460.470.480.49f(x)0.48465550
4、.49375420.50274980.5116683x=0.46:0.01:0.49;%給出x,f(x)f=[0.4846555,0.4937542,0.5027498,0.5116683];formatlonginterp1(x,f,0.472)%用默認方法,即線性插值方法計算f(x)interp1(x,f,0.472,'nearest')%用最近點插值方法計算f(x)interp1(x,f,0.472,'spline')%用3次樣條插值方法計算f(x)interp1(x,f,0.472,'cubic')%用3次多項式插值方法計
5、算f(x)formatshort例6.8某檢測參數(shù)f隨時間t的采樣結(jié)果如表6.2,用數(shù)據(jù)插值法計算t=2,7,12,17,22,17,32,37,42,47,52,57時的f值。表6.2檢測參數(shù)f隨時間t的采樣結(jié)果t051015202530f3.10252.256879.51835.92968.84136.25237.9t35404550556065f6152.76725.36848.36403.56824.77328.57857.6T=0:5:65;X=2:5:57;word格式編輯....F=[3.2015,2.2560,87
6、9.5,1835.9,2968.8,4136.2,5237.9,6152.7,...6725.3,6848.3,6403.5,6824.7,7328.5,7857.6];F1=interp1(T,F,X)%用線性插值方法插值F1=interp1(T,F,X,'nearest')%用最近點插值方法插值F1=interp1(T,F,X,'spline')%用3次樣條插值方法插值F1=interp1(T,F,X,'cubic')%用3次多項式插值方法插值例6.9設(shè)z=x2+y2,對z函數(shù)在[0,1]×[0,2]區(qū)域內(nèi)進行插值。x=0:0
7、.1:1;y=0:0.2:2;[X,Y]=meshgrid(x,y);%產(chǎn)生自變量網(wǎng)格坐標(biāo)Z=X.^2+Y.^2;%求對應(yīng)的函數(shù)值interp2(x,y,Z,0.5,0.5)%在(0.5,0.5)點插值interp2(x,y,Z,[0.50.6],0.4)%在(0.5,0.4)點和(0.6,0.4)點插值interp2(x,y,Z,[0.50.6],[0.40.5])%在(0.5,0.4)點和(0.6,0.5)點插值%下一命令在(0.5,0.4),(0.6,0.4),(0.5,0.5)和(0.6,0.5)各點插值interp2(x
8、,y,Z,[0.50.6]',[0.40.5])例6.10某實驗對一根長10米的鋼軌進行熱源的溫度傳播測試。用x表示測量點(米),用h表示測量時間(秒),用T表示測得各點的溫度(℃),測量結(jié)果如表6.2所示。表6.3鋼軌各點溫度測量值Txh02.5