Matlab程序設(shè)計實驗報告.doc_第1頁
Matlab程序設(shè)計實驗報告.doc_第2頁
Matlab程序設(shè)計實驗報告.doc_第3頁
Matlab程序設(shè)計實驗報告.doc_第4頁
Matlab程序設(shè)計實驗報告.doc_第5頁
已閱讀5頁,還剩5頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

實驗七 Matlab程序設(shè)計實驗?zāi)康模?、 掌握建立和執(zhí)行M文件的方法;2、 掌握實現(xiàn)選擇結(jié)構(gòu)的方法;3、 掌握實現(xiàn)循環(huán)結(jié)構(gòu)的方法。實驗內(nèi)容:1. 編寫用5次多項式擬合函數(shù)y=sin(x), x0, 2p的腳本M文件,要求繪圖觀察擬合的效果。function shiyan1x=0:0.5:2*piy=sin(x)p=polyfit(x,y,5)x1=0:0.2:2*piy1=polyval(p,x1)plot(x,y,b,x1,y1,*rx = Columns 1 through 9 0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000 Columns 10 through 13 4.5000 5.0000 5.5000 6.0000y = Columns 1 through 9 0 0.4794 0.8415 0.9975 0.9093 0.5985 0.1411 -0.3508 -0.7568 Columns 10 through 13 -0.9775 -0.9589 -0.7055 -0.2794p = -0.0056 0.0881 -0.3967 0.2671 0.8902 0.0029x1 = Columns 1 through 10 0 0.2000 0.4000 0.6000 0.8000 1.0000 1.2000 1.4000 1.6000 1.8000 Columns 11 through 20 2.0000 2.2000 2.4000 2.6000 2.8000 3.0000 3.2000 3.4000 3.6000 3.8000 Columns 21 through 30 4.0000 4.2000 4.4000 4.6000 4.8000 5.0000 5.2000 5.4000 5.6000 5.8000 Columns 31 through 32 6.0000 6.2000y1 = Columns 1 through 10 0.0029 0.1886 0.3786 0.5585 0.7172 0.8461 0.9391 0.9926 1.0048 0.9761 Columns 11 through 20 0.9083 0.8048 0.6701 0.5098 0.3301 0.1381 -0.0590 -0.2538 -0.4389 -0.6073 Columns 21 through 30 -0.7524 -0.8685 -0.9505 -0.9949 -0.9991 -0.9626 -0.8863 -0.7732 -0.6288 -0.4606 Columns 31 through 32 -0.2792 -0.09782. 從鍵盤輸入一個4位整數(shù),按如下規(guī)則加密后輸出。加密規(guī)則:每位數(shù)字都加上7,然后用和除以10的余數(shù)取代該數(shù)字;再把第一位與第三位交換,第二位與第四位交換。function shiyan2n=input(please input four integers:)n=n+7n=n%10a=n(1,1)n(1,1)=n(1,3)n(1,3)=ab=n(1,2)n(1,2)=n(1,4)n(1,4)=bplease input four integers:1 2 3 4n = 1 2 3 4n = 8 9 10 11n = 8 9 10 11a = 8n = 10 9 10 11n = 10 9 8 11b = 9n = 10 11 8 11n = 10 11 8 93. 輸入一個百分制成績,要求輸出成績等級A、B、C、D、E,其中90100分為A,8089分為B,7079分為C,6069分為D,60分以下為E。function shiyan3clear;clc;n=input(please input a number:)n=ceil(n/10)switch n case 10,9 disp(A) case 8 disp(B) case 7 disp(C) case 6 disp(D) case 5,4,3,2,1 disp(E) otherwise disp(default)endplease input a number:89n = 89n = 9A4. 硅谷公司員工的工資計算方法如下:(1) 工作時數(shù)超過120小時者,超過部分加發(fā)15%;(2) 工作時數(shù)低于60小時者,扣發(fā)700元;(3) 其余按每小時84元計發(fā)。試編程按輸入的工號和該號員工的工時數(shù),計算應(yīng)發(fā)工資。function shiyan4clear;clc;x=0;m=input(please input your number:)n=input(please input your working hours:)if n120 x=n*84+(n-120)*84*1.15;else x=n*84;endxplease input your number:38m = 38please input your working hours:80n = 80x = 67205. 設(shè)計程序,完成兩位數(shù)的加、減、乘、除四則運算。即:輸入兩個兩位隨機整數(shù),再輸入一個運算符號,做相應(yīng)的運算,并顯示相應(yīng)的結(jié)果。function shiyan5clear;clc;m=input(please input a number:)n=input(please input another number:)x=input(please input a symbol:,s)switch x case + q=m+n; case - q=m_n; case * q=m*n; case / q=m/n;endqplease input a number:12m = 12please input another number:1n = 1please input a symbol:+x =+q = 136. 建立56矩陣,要求輸出矩陣的第n行元素。當(dāng)n值超過矩陣的行數(shù)時,自動轉(zhuǎn)為輸出矩陣的最后一行元素,并給出出錯信息。function shiyan6clear;clc;a=1 2 3 4 5 6;2 3 4 5 6 7;3 4 5 6 7 8;4 5 6 7 8 9;24 45 34 76 23 67;n=input(please input a number:)if n5 b=a(5,:); disp(error);endbplease input a number:4n = 4b = 4 5 6 7 8 9please input a number:8

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論