0% found this document useful (0 votes)
45 views

Mid 2-1

The document contains a midterm exam for a numerical computing course. It consists of 5 questions testing concepts like Stirling's interpolation formula, numerical differentiation using the three-point midpoint formula, numerical integration using trapezoidal and Simpson's rules, Lagrange interpolation, and Euler's method.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Mid 2-1

The document contains a midterm exam for a numerical computing course. It consists of 5 questions testing concepts like Stirling's interpolation formula, numerical differentiation using the three-point midpoint formula, numerical integration using trapezoidal and Simpson's rules, Lagrange interpolation, and Euler's method.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

National University of Computer & Emerging Sciences, Karachi

FAST, School of Computing,


Spring, 2023
Mid Term-II
5 April, 2023, 10:00 am – 11:00am
th

Course Code: CS 2008 Course Name: Numerical Computing


Instructor Names: Ms. Amber Shaikh, Mr. Usama Antuley, Mr Shahid Ashraf and
Mr. Moheez Rahim
Student Roll No: Section :
Instructions:

• Solve all questions and return the question paper.


• Read each question completely before answering it.
• This paper consists of 2 pages and 5 Questions.
• All the required formulas are on attached paper.

Time: 60 minutes. Total Marks:30


Qno1 – CLO 2 2+2+1 Marks
Use stirling’s interpolation formula to find f(1.62) from the following table:
x 1.2 1.4 1.6 1.8 2.0 2.2
f(x) 5.64642 6.44218 7.17356 7.83327 8.41471 8.88851

Qno2– CLO 2 5 Marks

Suppose an engineer is working on a project that involves the design of a new turbine engine.
One of the key parameters that he needs to optimize is the rate of change of the engine's
temperature with respect to time. He hires you to do this job.
You have collected data on the temperature of the engine at different time points, and you want
to estimate the rate of change of the temperature using numerical differentiation with the Three-
Point Midpoint Formula. The temperature data is given by:
Time(hours) 0 1 2 3 4
Temprature(°𝑪) 20 50 80 110 140
You want to estimate the rate of change of the temperature at t = 2 hours using the Three-
Point Midpoint Formula, with a step size of h = 1 hour.

Qno3 – CLO 2 4+4+2 Marks

Assuming that you are a computer scientist currently developing a computer graphics
application that requires the computation of the area beneath the curve of the function 𝒚 =
𝒙𝟐 + 𝟐𝒙, within the integration interval of [0, 5], you are asked to estimate the area manually
before implementing any solutions. The estimation should be done by utilizing the Composite
Trapezoidal and Composite Simpson's rule furthermore, actual errors of each method
should also be calculated. Additionally, provide your comments on the comparison of actual
error of both methods. (let n = 4 subintervals)
1
Qno4 – CLO 2 4 Marks

Solve 𝑦 ′ = 1 − 𝑦 & 𝑦(0) = 0 𝑖𝑛 𝑡ℎ𝑒 𝑟𝑎𝑛𝑔𝑒 0 ≤ 𝑥 ≤ 0.5 using Euler’s method. (Let h=0.1)

Qno5 – CLO 3 2+2+1+1 Marks


3 2
a) Using Poly1d function, write a code to print the polynomial 3𝑥 + 4𝑥 + 𝑥 − 1
b) Identify the missing part/error(s)

def abc_poly(x, y):


n = len(x)
p = np.poly1d(0.0)
for i in range(n):
L = np.poly1d(y[i])
for j in range(n):
if j != i:
L *= np.poly1d([1.0, -x[j]]) / (x[i] - x[j])
p += L
return p
p = abc_poly(x, y)
print(p)

c) Which interpolating method is implemented in part (b). Just give its name.
d) Briefly write the purpose of the following command (ONE LINE ANSWER)
from scipy.interpolate import lagrange
________________________________________________________
Three-point Midpoint Formula
𝟏 𝒉𝟐
𝒇′ (𝒙𝟎 ) = (𝒇(𝒙𝟎 + 𝒉) − 𝒇(𝒙𝟎 − 𝒉)) + 𝒇′′′ (𝜻𝟏 ) ∶ 𝜻 𝒍𝒊𝒆𝒔 𝒃𝒆𝒕𝒘𝒆𝒆𝒏 𝒙𝟎 + 𝒉 𝒂𝒏𝒅 𝒙𝟎 − 𝒉
𝟐𝒉 𝟔
Simpson’s Rule

Trapezoidal Rule

Stirling’s Formula
𝒔𝒉
𝑷𝒏 (𝒙) = 𝒇(𝒙𝟎 ) + (𝒇[𝒙−𝟏 , 𝒙𝟎 ] + 𝒇[𝒙𝟎 , 𝒙𝟏 ]) + 𝒔𝟐 𝒉𝟐 𝒇[𝒙−𝟏 , 𝒙𝟎 , 𝒙𝟏 ]
𝟐
𝒔(𝒔𝟐 − 𝟏)𝒉𝟑
+ (𝒇[𝒙−𝟐 , 𝒙−𝟏 , 𝒙𝟎 , 𝒙𝟏 ] + 𝒇[𝒙−𝟏 , 𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ]) + 𝒔𝟐 (𝒔𝟐 − 𝟏)𝒉𝟒 𝒇[𝒙−𝟐 , 𝒙−𝟏 , 𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ]
𝟐
Euler’s Method:
𝒉𝟐
𝒚(𝒕𝒊+𝟏 ) = 𝒚(𝒕𝒊 ) + 𝒉𝒚′(𝒕𝒊 ) + 𝒚′′(𝝃𝒊 )
𝟐

You might also like