資源描述:
《實(shí)驗(yàn)二matlab數(shù)值計(jì)算 (2)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、實(shí)驗(yàn)二MATLAB數(shù)值計(jì)算1.實(shí)驗(yàn)?zāi)康模?)掌握MATLAB變量的使用(2)掌握MATLAB數(shù)組的創(chuàng)建,(3)掌握MATLAB數(shù)組和矩陣的運(yùn)算。(4)熟悉MATLAB多項(xiàng)式的運(yùn)用2.實(shí)驗(yàn)儀器(1)Matlab6.5應(yīng)用軟件安裝版一套(3)PC機(jī)一臺(tái)3.實(shí)驗(yàn)原理矩陣運(yùn)算和數(shù)組運(yùn)算在MATLAB中屬于兩種不同類型的運(yùn)算,數(shù)組的運(yùn)算是從數(shù)組元素出發(fā),針對(duì)每個(gè)元素進(jìn)行運(yùn)算,矩陣的運(yùn)算是從矩陣的整體出發(fā),依照線性代數(shù)的運(yùn)算規(guī)則進(jìn)行。4.實(shí)驗(yàn)步驟(1)使用冒號(hào)生成法和定數(shù)線性采樣法生成一維數(shù)組。(2)使用MATLAB提供的庫函數(shù)reshape,將一維數(shù)組轉(zhuǎn)換為二維和
2、三維數(shù)組。(3)使用逐個(gè)元素輸入法生成給定變量,并對(duì)變量進(jìn)行指定的算術(shù)運(yùn)算、關(guān)系運(yùn)算、邏輯運(yùn)算。(4)使用MATLAB繪制指定函數(shù)的曲線圖,將所有輸入的指令保存為M文件。5.實(shí)驗(yàn)報(bào)告內(nèi)容(1)在[0,2*pi]上產(chǎn)生50個(gè)等距采樣數(shù)據(jù)的一維數(shù)組,用兩種不同的指令實(shí)現(xiàn)。a=0:2*pi/49:2*pi%b=linspace(0,2*pi,50)a=Columns1through400.12820.25650.3847Columns5through80.51290.64110.76940.8976Columns9through121.02581.15411.
3、28231.4105Columns13through161.53871.66701.79521.9234Columns17through202.05172.17992.30812.4363Columns21through242.56462.69282.82102.9493Columns25through283.07753.20573.33393.4622Columns29through323.59043.71863.84683.9751Columns33through364.10334.23154.35984.4880Columns37through40
4、4.61624.74444.87275.0009Columns41through445.12915.25745.38565.5138Columns45through485.64205.77035.89856.0267Columns49through506.15506.2832>>(2)將一維數(shù)組A=1:18,轉(zhuǎn)換為2×9數(shù)組和2×3×3數(shù)組。>>a=1:18a=Columns1through71234567Columns8through14891011121314Columns15through1815161718>>c=reshape(1:18,2,9
5、)c=Columns1through71357911132468101214Columns8through915171618>>d=reshape(1:18,2,3,3)d(:,:,1)=135246d(:,:,2)=791181012d(:,:,3)=131517141618(3)A=[0234;1350],B=[1053;1505],計(jì)算矩陣A轉(zhuǎn)置與B乘積,數(shù)組A、B乘積,計(jì)算A&B,A
6、B,~A,A==B,A>B。a=[0234;1350]%M文件b=[1053;1505]d=a'*bc=a.*bm=(a&b)n=(a
7、b)p=(a==b)k=(a
8、>b)a=02341350b=10531505d=150551510218251534402012c=00151211500m=00111100n=11111111p=00001000k=01010010(4)繪制y=0.5-t*t*sin(t),t=[0,pi]并標(biāo)注峰值和峰值時(shí)間,添加標(biāo)題y=0.5-t*t*sint,將所有輸入的指令保存為M文件a=0.5b=1/3t=0:0.01:piy=a*exp(b*t)-t.*t.*sin(t)[y_max,t_max]=max(y)t_text=['t=',num2str(t(t_max))]y_text
9、=['y=',num2str(y_max)]max_text=char('maximum',t_text,y_text)tit=['y=0.5*exp(',num2str(b),'t)-t*t*sin(t)']holdonplot(t,y,'b')plot(t(t_max),y_max,'r.')text(t(t_max)+0.3,y_max+0.05,max_text)title(tit),xlabel('t'),ylabel('y'),holdoff