YILDIZ TECHNICAL UNIVERSITY
MECHANICAL FACULTY / MECHATRONICS ENGINEERING DEPARTMENT
Student Name: Student number: Signature:
Course: MKT3841 Numerical Methods Date/Time: 21.05.2019 / 13:00 Duration: 90 minutes
Exam Type: Final Exam Course Instructor: [Link]. Cüneyt Yılmaz
Question 1) [25 points] Apply the finite difference method in the following differential equation to
obtain a simultaneous equation system in the matrix form 𝑨. 𝒚 = 𝑩 where 𝒚 = [𝒚𝟏 , 𝒚𝟐 , ⋯ , 𝒚𝒏 ].
𝑑2 𝑦 𝑑𝑦
𝑑𝑡 2
=2 𝑑𝑡
+ 2 𝑦 + 𝑒 −𝑡 , with 𝑦(0) = 0 , 𝑦’(1) = −1/(12𝑒) and 𝑡 = 0.25.
𝑡(𝑛)−𝑡(0) 1.00−0
Solution 1) ` 𝑛= +1= +1=5
ℎ 0.25
−1
𝑦1 = 0 𝑎𝑛𝑑 𝑦4 ′ =
12𝑒
1
𝑦𝑖′ = ( ) ( 𝑦𝑖+1 − 𝑦𝑖−1 ) = 2 ( 𝑦𝑖+1 − 𝑦𝑖−1 )
2ℎ
1
𝑦𝑖 ′′ = ( ) ( 𝑦𝑖−1 − 2 𝑦𝑖 + 𝑦𝑖+1 ) = 16 ( 𝑦𝑖−1 − 2 𝑦𝑖 + 𝑦𝑖+1 )
ℎ2
16 ( 𝑦𝑖−1 − 2 𝑦𝑖 + 𝑦𝑖+1 ) − 2 ∙ 2 ( 𝑦𝑖+1 − 𝑦𝑖−1 ) − 2 𝑦𝑖 = 𝑒−𝑡𝑖
20 𝑦𝑖−1 − 34 𝑦𝑖 + 12 𝑦𝑖+1 = 𝑒−𝑡𝑖
i=1: 𝒕𝟏 = 𝟎. 𝟎𝟎 , 𝒚𝟏 = 𝟎
i=2: 𝒕𝟐 = 𝟎. 𝟐𝟓 , 𝟐𝟎 𝒚𝟏 − 𝟑𝟒 𝒚𝟐 + 𝟏𝟐 𝒚𝟑 = 𝑒−𝟎.𝟐𝟓
i=3: 𝒕𝟑 = 𝟎. 𝟓𝟎 , 𝟐𝟎 𝒚𝟐 − 𝟑𝟒 𝒚𝟑 + 𝟏𝟐 𝒚𝟒 = 𝑒−𝟎.𝟓𝟎
i=4: 𝒕𝟒 = 𝟎. 𝟕𝟓 , 𝟐𝟎 𝒚𝟑 − 𝟑𝟒 𝒚𝟒 + 𝟏𝟐 𝒚𝟓 = 𝑒−𝟎.𝟕𝟓
i=5: 𝒕𝟓 = 𝟏. 𝟎𝟎 , 20 𝑦4 − 34 𝑦5 + 12 𝑦6 = 𝑒−𝟏.𝟎𝟎
−1 −1
𝑦5 ′ = 2 ( 𝑦6 − 𝑦4 ) = 12𝑒 → 𝑦6 = 12𝑒 + 𝑦4
−1 1
20 𝑦4 − 34 𝑦5 + 12 (12𝑒 + 𝑦4 ) = 𝑒 → 𝟑𝟐 𝒚𝟒 − 𝟑𝟒 𝒚𝟓 = 𝟐/𝒆
𝟏 𝟎 𝟎 𝟎 𝟎 𝒚𝟏 𝟎
𝒚 𝑒−𝟎.𝟐𝟓
𝟐𝟎 −𝟑𝟒 𝟏𝟐 𝟎 𝟎 𝟐
𝟎 𝟐𝟎 −𝟑𝟒 𝟏𝟐 𝟎 𝒚 𝟑 = 𝑒−𝟎.𝟓𝟎
𝟎 𝟎 𝟐𝟎 −𝟑𝟒 𝟏𝟐 𝒚𝟒 𝑒−𝟎.𝟕𝟓
[𝟎 𝟎 𝟎 𝟑𝟐 −𝟑𝟒] [ 𝒚𝟓 ] [ 𝟐/𝒆 ]
Question 2) [25 points] Determine the coefficients of the polynomial 𝑦 = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2 that
passes through the (𝑥, 𝑦) points (1, 6), (3, 18) and (5, 38). Rewrite the system in the matrix form as
𝑨 ∙ 𝑿 = 𝑩 , and solve { 𝑎0 , 𝑎1 , 𝑎2 }𝑇 by using Doolittle’s LU Decomposition method.
Solution 2) 𝑦 = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2
𝑥 = 1 𝑎𝑛𝑑 𝑦 = 6 → 6 = 𝑎0 + 𝑎1 + 𝑎2 1 1 1 a0 6
𝑥 = 3 𝑎𝑛𝑑 𝑦 = 18 → 18 = 𝑎0 + 3 𝑎1 + 9 𝑎2 [1 3 9 ] ∙ [a1 ] = [18]
𝑥 = 5 𝑎𝑛𝑑 𝑦 = 38 → 38 = 𝑎0 + 5 𝑎1 + 25 𝑎2 1 5 25 a2 38
1 1 1 a0 6
𝑨 = [1 3 9] , 𝐗 = [ a1 ] , 𝐁 = [18]
1 5 25 a2 38
𝑨=𝑳∙𝑼
First, we use Gauss elimination:
row2 – (1) x row1 → row2 , 𝐿21 = 1 and,
1 1 1
row3 – (1) x row1 → row3 , 𝐿31 = 1 → 𝑨′ = [0 2 8 ]
0 4 24
1 1 1 1 0 0
row3 – (2) x row2 → row3 , 𝐿32 = 2 → 𝑼 = [0 2 8] and 𝑳 = [1 1 0]
0 0 8 1 2 1
𝑨∙𝑿=𝑩
𝑳 ∙ (𝑼 ∙ 𝑿) = 𝑩
1 0 0 y1 6
𝒀=𝑼∙𝑿 y
→ 𝑳 ∙ 𝒀 = 𝑩 → [1 1 0] ∙ [ 2 ] = [18]
1 2 1 y3 38
6
𝑦1 = 6 , 𝑦2 = 18 − 6 = 12 , 𝑦3 = 38 − 6 − 2 ∙ 12 = 8 → 𝐘 = [12]
8
1 1 1 a0 6
𝑼∙𝑿=𝒀 → [0 2 8] ∙ [a1 ] = [12] →
0 0 8 a2 8
𝐚𝟎 𝟑
8 12−8∙(1) 6−1−2
𝑎2 = 8 = 1 , 𝑎1 = = 2 , 𝑎0 = =3 → 𝐚
[ 𝟏 ] = [𝟐 ]
2 1
𝐚𝟐 𝟏
Question 3) [25 points] The data below is obtained from a gas sensor calibration.
v (Volts) 2.0 4.0 5.0 7.0
f (ppm) 16.0 41.0 70.0 150.0
Determine the parameters a and b so that f(v) = [Link].v fits the calibration data in the least-squares
sense. What is the ppm concentration of a sampled gas when the sensor gives 6 volts?
∑ 𝑦 ∙( 𝑥 −𝑥̅ )
Work with at least 3 decimal points. Hint: y=a+bx , 𝑏 = ∑ 𝑥𝑖∙( 𝑥𝑖−𝑥̅ )
𝑖 𝑖
Solution 3)
We convert f(x)=[Link] to z=c+bx shape, and use the curve fitting equations of a straight line:
𝑙𝑛[𝑓(𝑥)] = 𝑙𝑛(𝑎. 𝑒 𝑏𝑥 ) → 𝑙𝑛[𝑓(𝑥)] = 𝑙𝑛(𝑎) + 𝑙𝑛(𝑒 𝑏𝑥 ) → 𝑙𝑛[𝑓(𝑥)] = 𝑙𝑛(𝑎) + 𝑏. 𝑥 .
So, the new table is:
xi fi(x) zi=ln[f(x)] xi2 xi zi
2.00 16.00 2.773 4.000 5.545
4.00 41.00 3.714 16.000 14.854
5.00 70.00 4.249 25.000 21.242
7.00 150.00 5.011 49.000 35.074
Σ 12.00 15.745 94 76.716
Mean 4.50 3.936
∑ 𝑧𝑖 ∙ ( 𝑥𝑖 − 𝑥̅ ) ∑ 𝑥𝑖 𝑧𝑖 − 𝑥̅ ∑ 𝑧𝑖 76.716 − 4.00 ∙ 15.745
𝑏= = = → 𝒃 = 𝟎. 𝟒𝟓𝟏
∑ 𝑥𝑖 ∙ ( 𝑥𝑖 − 𝑥̅ ) ∑ 𝑥𝑖 2 − 𝑥̅ ∑ 𝑥𝑖 94.00 − 4.00 ∙ 12.00
𝑧̅ = 𝑐 + 𝑏 ∙ 𝑥̅ → 𝑐 = 𝑧̅ − 𝑏 ∙ 𝑥̅ = 3.936 − 0.451 ∙ 4.000 → 𝑐 = 1.907
𝑐 1.907
𝑐 = ln(𝑎) → 𝑎 = 𝑒 = 𝑒 → 𝑎 = 6.733
Thus, f(x) = [Link].x → f(x) =6.733.e0.451.x
f(6) =6.733.e0.451.(6.00) = 100.763 ppm
Error Analysis:
xi fi 𝒇̅𝒊 𝜺𝒊 = 𝒇𝒊 − 𝒇̅𝒊 %𝜺𝒊 = 𝟏𝟎𝟎 ∙ |𝜺𝒊 /𝒇𝒊 | %
2.00 16.00 16.592 0.592 3.698%
4.00 41.00 40.888 -0.112 -0.273%
5.00 70.00 64.187 -5.813 -8.304%
7.00 150.00 158.181 8.181 5.454%
Question 4) [25 points] Determine the closest point of the curve 𝑦 = 𝑥 2 − 𝑥 + 3 to the point
(𝑥𝑜 , 𝑦𝑜 ) = (0 , 2) by using Golden Bracketing method (𝑅 = 0.618034).
Search x between 0.250 and 0.450 . Let ε=0.05 to stop the bracketing.
Solution 4) The distance equation between the curve and the point:
𝑑 = √(𝑥 − 𝑥𝑜 )2 + (𝑦 − 𝑦𝑜 )2 = √(𝑥 − 𝑥𝑜 )2 + (𝑥 2 − 𝑥 + 3 − 𝑦𝑜 )2
(𝑥𝑜 , 𝑦𝑜 ) = (0,2) → 𝑑 = √(𝑥 − 0)2 + (𝑥 2 − 𝑥 + 3 − 2)2
∴ 𝑓(𝑥) = √𝑥 2 + (𝑥 2 − 𝑥 + 1)2 𝑡𝑜 𝑏𝑒 𝑜𝑝𝑡𝑖𝑚𝑖𝑧𝑒𝑑.
i ai bi h ai'=bi-Rxh bi'=ai+Rxh f(ai') f(bi') xi=(ai+bi)/2
0 0.2500 0.4500 0.2000 0.3264 0.3736 0.8457 0.8522 0.3500
1 0.2500 0.3736 0.1236 0.2972 0.3264 0.8451 0.8457 0.3118
2 0.2500 0.3264 0.0764 0.2792 0.2972 0.8461 0.8451 0.2882
3 0.2792 0.3264 0.0472 0.2972 0.3084 0.8451 0.8450 0.3028 h<ε
𝑦(𝑥) = 𝑥 2 − 𝑥 + 3 → 𝑦(0.3028) = (0.3028)2 − (0.3028) + 3 = 2.7889
Thus, the closest point of the function to (𝑥𝑜 , 𝑦𝑜 ) is ( 0.3028 , 2.7889 )