課程名稱︰計算機程式
課程性質︰化學工程學系必修
課程教師︰諶(ㄔㄣˊ)玉真
開課學院:工學院
開課系所︰化學工程學系
考試日期(年月日)︰101/12/13
考試時限(分鐘):110mins (1:20~3:10)
是否需發放獎勵金:是
(如未明確表示,則不予發放)
試題 :
1.Write a fortran program that contains three functions slope, intercept, and
correlation.Function slope will calculate slope m. Function intercept will
calculate intercept b and Function correlation will calculate correlation
coefficient r of the least-squares line that can best fits an input data set.
The input data point(x,y) will be passed to the function in two input arrays,
X and Y.The equations describing the slope, intercept and correlation coeffic
-icent of the least-squares line are
y=mx+b
m=((Σxy)-(Σx)yavg)/((Σx^2)-(Σx)xavg) ( xavg is the average of x )
( yavg is the average of y )
b=yavg-m*xavg
r=(n(Σx^2)-(Σx)(Σy))/(((nΣx^2)-(Σx)^2)*(n(Σy^2)-(Σy)^2))^0.5
test your result for the following 20-point input data set(data01.txt)
No. x y No. x y
1 -4.91 -8.18 11 -0.94 0.21
2 -3.84 -7.49 12 0.59 1.73
3 -2.41 -7.11 13 0.69 3.96
4 -2.62 6.15 14 3.04 4.26
5 -3.78 -5.62 15 1.01 5.75
6 -0.52 -3.30 16 3.60 6.67
7 -1.83 -2.05 17 4.53 7.70
8 -2.01 -2.83 18 5.13 7.31
9 0.28 -1.16 19 4.43 9.05
10 1.08 0.52 20 4.12 10.95
2.The value of the exponential e^x can be calculated by evaluating the follow
-ing infinite series:
e^x=Σ(x^n)/(n!)
Write a Fortran external function MYEXP to calculate e^x using hte first 12
terms of the infinite series.
Use function MYEXP in a main program to calculate
cosh(x)=(e^x + e^-x )/2
Compare the result of your function with the result of the intrinsic functi
-on COSH(x) of x=-1 to 1 in increments of 0.1
3.Write a program that asks the user to enter value for a and b, the reads a
values of F(s) and θ(s) from a data file. Use the trapezoidal method to ap
-proximate the following integral
b
W=∫F(s)cos(θ(s))ds
a
Here,a=20,b=50 and n=11. ds=(b-a)/n (考試中助教說a.b.n 都直接定義)
s F(s) θ(s) (radian)
a+0*ds 0.0 0.60
a+1*ds 4.3 0.87
a+2*ds 7.8 1.02
a+3*ds 9.9 0.99
a+4*ds 12.5 1.20
a+5*ds 16.3 0.98
a+6*ds 18.4 0.86
a+7*ds 21.7 0.43
a+8*ds 25.4 0.23
a+9*ds 22.3 0.14
a+10*ds 20.9 0.15
b=a+11*ds 18.7 0.08
Hint:use do loop and declare arrays for F and θ(data03.txt)
4.A point in a rank-2 array is said to be a relative maximum if it is higher
than any of the eight points surrounding it. For example, the element at po
-sition (2,2)in the following array is a relative maximum, since it is large
-er than any of the surrounding points
┌ ┐
│11 7 -2│
│ 7 14 3│
│ 2 -3 5│
└ ┘
Write a program to read a matrix A from an input file (data04.txt) to scan
for all relative maxima within the matrix. THe first line in the input file
contains the number of rows and the numbers of columns in the matrix, and
the following lines contain the values in the matrix. Use allocatable arrays.
The program should only consider the interior points within th matrix, since
any point along and edge of the matrix cannot be completely surrounded by poi
-nts lower than itself.-
data03.txt and data01.txt和表一樣
data04.txt檔中
8 10
2. -1. -2. 1. 3. -5. 2. 1. -3. -7.
-2. 0. -2.5 5. -2. 2. 1. 0. 5. 4.
-3. -3. -3. 3. 0. 0. -1. -2. 1. 4.
-4.5 -4. -7. 6. 1. -3. 0. 5. 0. -8.
-3.5 -3. -5. 0. 4. 17. 11. 5. 3.5 2.
-9. -6. -5. -3. 1. 2. 0. 0.5 -5. -1.
-7. -4. -5. -3. 2. 4. 3. -1. 9. 2.
-6. -5. -5. -2. 0. 1. 2. 5. 4. 1.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.243.16