• 沒有找到結果。

Introduction to Matlab

N/A
N/A
Protected

Academic year: 2022

Share "Introduction to Matlab"

Copied!
2
0
0

加載中.... (立即查看全文)

全文

(1)

Introduction to Matlab

Name: Student ID number:

Guidelines for the test:

ˆ 使用工具僅限matlab(Help),禁止使用任何 (網路及書面)資源.

ˆ 共五題,第一題為簡答題,第二題為改錯(debug),後三題為 programming。

ˆ 後三題注意事項:

1. 全部程式請先放入一資料夾 (以學號為名),壓縮後,再存入助教的隨身碟中。

2. 檔名請用 prob3a.mprob3b.mprob4a.mprob4b.mprob5.m

3. 除了電子檔外,另外請將程式碼貼在文字檔內(or MS Word檔), 以每張兩頁雙面印出 (請找助教協助)

4. 4(b)請將畫出的圖印出 (請找助教協助)

試題:

1. 小明打算用Matlab 計算一個矩陣的特徵值 (eigenvalue), 但是他不知道要使用哪一個函數, 請問

(a) (5 pts)小明在命令視窗(Command Window)中,要使用哪個指令尋找與eigenvalue 相關的函數與指令

Ans: ,

(b) (5 pts)小明使用上述方式查到應該要使用 eig這個函數,請問在命令視窗(Command Window) 中,要使用哪個指令查詢eig 這個函數的使用方式:

Ans: ,

2. (10 pts) 小明打算寫一個小程式計算一元二次方程式ax2+ bx + c = 0的根,計算公式為 x±= −b ±√

b2− 4ac

2a ,

他把程式存成123.m 後寄給助教, 結果因為錯誤太多被退回重寫。 請幫小明找到錯誤並改正 (圈出錯誤處改正),以下為123.m的內容

clear all

disp('This program solves for the roots of aquadratic');

disp('equation of the form A*Xˆ2 + B*X + C = 0. ');

a=input('Enter the coefficient A: ');

b=input('Enter the coefficient B: ');

c=input('Enter the coefficient C: ');

Discriminant = bˆ2 − 4ac;

x+ = ( −b + sqrt(discriminant) ) / ( 2 * a ) x− = ( −b − sqrt(discriminant) ) / ( 2 * a )

Page 1

(2)

3. 小明打算寫一個小程式畫f (x) = x2[0, 1]的圖形, 但是當小明為了讓圖形美觀而選用非常 多點時, 花費的時間非常的多.麻煩以下列兩種方式幫小明的程式加速:(由於公用電腦室電腦 效能不一,測試時建議將N pt 改為1e4)

(a) (10 pts)保留迴圈 (for loop)加速計算 (b) (10 pts) 將程式以向量化計算加速

clear all

N pt=1e5;

dx=(1−0)/N pt;

x=linspace(0,1,N pt+1);

for ii=1:N pt+1 y(ii)=x(ii)ˆ2;

end

plot(x,y);

4. (30 pts) 老師在計算學期成績時發現, 原始分數全班最高分為94, 大部分的學生分數都在 50分以上。 所以他打算把最高分調整成99,50分調整成60,介於50分與94分間者線性調 整。 原始分數低於30分者調整成30,高於或等於30分且未達50分間者加5分。 最後的分數 計算公式如下(x為原始分數, y為調整後之學期成績):

y =



60 + 39·94x−50−50, x≥ 50, x + 5, 50 > x≥ 30,

30, x < 30.

(a) 試寫出一個程式,讀取原始分數,計算調整後之學期成績。

(b) 試寫出一個程式畫出計算公式函數圖形(x-軸為原始分數,y-軸為調整後之學期成績)。 標 題為學號-學期成績計算公式”,顯示範圍為[0, 100]× [0, 100](請將圖印出)

5. (30 pts) 請寫出一個程式,能計算一組數字(個數可以讓使用者決定) 的算術平均數(即平均 值)、 幾何平均數、 均方根平均數、 以及調和平均數。

Geometric mean (幾何平均數) = nx1x2. . . xn Root mean square(均方根平均數)=

vu ut 1

N

N i=1

x2i

Harmonic Mean(調和平均數) = 1 N

x1 +x1

2 +· · · + x1N

Page 2

參考文獻

相關文件

 一般我們如過是透過分享器或集線器來連接電腦 的話,只需要壓制平行線即可(平行線:兩端接 頭皆為EIA/TIA 568B),

Prove that S is compact if and only if S is uniformly closed, pointwise bounded, and equicontinuous.. (If S is not equicontinuous, then S contains a sequence which has no

The Seed project, REEL to REAL (R2R): Learning English and Developing 21st Century Skills through Film-making in Key Stage 2, aims to explore ways to use film-making as a means

Recycling Techniques are Available to Address Specific Pavement Distress and/or Pavement Structural Requirement.. Introduction to Asphalt Introduction

 The nanostructure with anisotropic transmission characteristics on ITO films induced by fs laser can be used for the alignment layer , polarizer and conducting layer in LCD cell.

Hence, we have shown the S-duality at the Poisson level for a D3-brane in R-R and NS-NS backgrounds.... Hence, we have shown the S-duality at the Poisson level for a D3-brane in R-R

One can always get the column names of a table using the command str( ), but there are two easier commands, colnames( ) and rownames( ) that list the column names and row names of

Won the Programming Contest held by IM dept., CYUT, 2008Projects (請依需要填入 請依需要填入 請依需要填入 請依需要填入, 或以另外附件方式列上 或以另外附件方式列上