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

Week 11 July 2023

The document contains solutions to 10 questions on topics including interpolation, differential equations, integration, and recursion. Key points covered include: 1) Interpolation estimates functions at intermediate points between given data points. 2) Solving differential equations using Runge-Kutta method requires the equation, step size, and initial y-value as inputs. 3) Increasing the number of segments when using methods like trapezoidal rule increases the accuracy of numerical integration approximations.

Uploaded by

stephen neal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Week 11 July 2023

The document contains solutions to 10 questions on topics including interpolation, differential equations, integration, and recursion. Key points covered include: 1) Interpolation estimates functions at intermediate points between given data points. 2) Solving differential equations using Runge-Kutta method requires the equation, step size, and initial y-value as inputs. 3) Increasing the number of segments when using methods like trapezoidal rule increases the accuracy of numerical integration approximations.

Uploaded by

stephen neal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Week 11 Assignment Solution

1. Interpolation provides a mean for estimating functions


a) At the beginning points
b) At the ending points
c) At the intermediate points
d) None of the mentioned

Solution: (c) At the intermediate points


Explanation: Interpolation provides a mean for estimating the function at the intermediate points.
2. To solve a differential equation using Runge-Kutta method, necessary inputs from user to the
algorithm is/are
a) the differential equation dy/dx in the form x and y
b) the step size based on which the iterations are executed.
c) the initial value of y.
d) all the above

Solution: (d) The differential equation, step size and the initial value of y are required to solve differential
equation using Runge-Kutta method.

3. A Lagrange polynomial passes through three data points as given below


𝑥 5 10 15
𝑓(𝑥) 15.35 9.63 3.74
The polynomial is determined as 𝑓(𝑥) = 𝐿0 (𝑥). (15.35) + 𝐿1 (𝑥). (9.63) + 𝐿2 (𝑥). (3.74)
The value of 𝑓(𝑥) at 𝑥 = 7 is

a) 12.78
b) 13.08
c) 14.12
d) 11.36

Solution: (b)
2
𝑥 − 𝑥𝑗 (7 − 10)(7 − 15) 24
𝐿0 (𝑥) = ∏ = = = 0.48
𝑥0 − 𝑥𝑗 (5 − 10)(5 − 15) 50
𝑗=0
𝑗≠0
2
𝑥 − 𝑥𝑗 (7 − 5)(7 − 15) −16
𝐿1 (𝑥) = ∏ = = = 0.64
𝑥1 − 𝑥𝑗 (10 − 5)(10 − 15) −25
𝑗=0
𝑗≠1

2
𝑥 − 𝑥𝑗 (7 − 5)(7 − 10) −6
𝐿2 (𝑥) = ∏ = = = −0.12
𝑥1 − 𝑥𝑗 (15 − 5)(15 − 10) 50
𝑗=0
𝑗≠2
So 𝑓(7) = 0.48 ∗ 15.35 + 0.64 ∗ 9.63 − 0.12 ∗ 3.74 = 13.08
3.2
4. The value of ∫0 𝑥𝑒 𝑥 𝑑𝑥 by using one segment trapezoidal rule is
a) 172.7
b) 125.6
c) 136.2
d) 142.8

Solution: (b)
𝑏
𝑓(𝑏) − 𝑓(𝑎)
∫ 𝑓(𝑥)𝑑𝑥 = (𝑏 − 𝑎)
𝑎 2
Week 11 Assignment Solution
3.2
Here, 𝑎 = 0, 𝑏 = 3.2, 𝑓(𝑎) = 0 and 𝑓(𝑏) = 78.5. Hence, ∫0 𝑥𝑒 𝑥 𝑑𝑥 = 125.6

5. Accuracy of the trapezoidal rule increases when


a) integration is carried out for sufficiently large range
b) instead of trapezoid, we take rectangular approximation function
c) number of segments are increased
d) integration is performedfor only integer range

Solution: (c)Approximation increases with the increase of the number of segments between the lower and upper
limit.

6. Solve the ordinary differential equation below using Runge-Kutta4th order method.
Step size h=0.2.
𝑑𝑦
5 + 𝑥𝑦 3 = cos(𝑥) , 𝑦(0) = 3
𝑑𝑥
The value of y(0.2) is (upto two decimal points)

a) 2.86
b) 2.93
c) 3.13
d) 3.08
Solution: (b)

7. Match the following


A. Newton Method 1. Integration
B. Lagrange Polynomial 2. Root finding
C. Trapezoidal Method 3. Differential Equation
D. RungeKutta Method 4. Interpolation

a) A-2, B-4, C-1, D-3


b) A-3, B-1, C-2, D-4
c) A-1, B-4, C-3, D-2
d) A-2, B-3, C-4, D-1

Solution: (a)
3
8. The value of ∫1 ex (ln 𝑥) dx calculated using the Trapezoidal rule with five subintervals is (* range
is given in output rather than single value to avoid approximation error)

a) 12.56 to 12.92
b) 13.12 to 13.66
c) 14.24 to 14.58
d) 15.13 to 15.45

Solution: (c) The 14.24 to 14.58


From the formula of trapezoidal rule we get, the following
Δx/2=1/5:
3
∫1 ex (ln 𝑥) =(1/5)(0+2.72892440558099+7.11180421388169+14.2316766420315+25.7295115705906+22
.066217688311)=14.3736269040792
Week 11 Assignment Solution

9. Consider the same recursive C function that takes two arguments

unsignedintfunc(unsigned int n, unsigned int r)


{
if (n > 0) return (n%r + func (n/r, r ));
else return 0;
}
What is the return value of the function foo when it is called as func(513, 2)?

a) 9
b) 8
c) 5
d) 2

Solution: (d) 2
func(513, 2) will return 1 + func(256, 2). All subsequent recursive calls (including func(256, 2)) will return
0 + func(n/2, 2) except the last call func(1, 2) . The last call func(1, 2) returns 1. So, the value returned by
func(513, 2) is 1 + 0 + 0…. + 0 + 1=2.
10. What is the output?
#include <stdio.h>
int fun(int n)
{
if (n == 4)
return n;
else return 2*fun(n+1);
}
int main()
{
printf("%d ", fun(2));
return 0;
}

a) 4
b) 8
c) 16
d) Error

Solution: (c) 16

You might also like