[go: up one dir, main page]

0% found this document useful (0 votes)
6 views5 pages

Problem Set C

The document contains a problem set focused on numerical integration, root-finding methods, linear systems, and statistical analysis using C programming. It includes tasks such as calculating definite integrals using various numerical methods, approximating probability density functions, solving equations with different methods, and analyzing datasets. Additionally, it references several computational methods and textbooks for further study.

Uploaded by

CHANANDELARBONG
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Problem Set C

The document contains a problem set focused on numerical integration, root-finding methods, linear systems, and statistical analysis using C programming. It includes tasks such as calculating definite integrals using various numerical methods, approximating probability density functions, solving equations with different methods, and analyzing datasets. Additionally, it references several computational methods and textbooks for further study.

Uploaded by

CHANANDELARBONG
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Problem Set

1. Calculate the value of the definite integral


Z 2
1
dx
1 x
correct to five decimal places using the following numerical integration methods:

• Trapezoidal Rule,
• Simpson’s One-Third Rule,
• Simpson’s Three-Eighths Rule,
• Weddle’s Rule.

Also, compute the error of approximation for each method by comparing the results
with the exact value of the integral.

2. Consider a probability density function (PDF) defined as:


1 2
f (x) = √ e−x /2 .

Write a C program to approximate the integral:
Z 2
f (x) dx
−2

using the trapezoidal rule with different values of h = 0.1, 0.01, 0.001. Compare the
accuracy of the results with the known probability from the standard normal table.

3. Given the following conditions:

f (0) = 0
f (1) + f (2) = 10
f (3) + f (4) + f (5) = 65

find the value of f (4), assuming that the function f (x) is of the form

f (x) = a + bx + cx2 .

1
4. Find the smallest positive real root of the equation

xex − 2 = 0,

correct to four significant figures, using the method of false position (also known
as the regula falsi method).

5. Using the Newton–Raphson method, find the root of the equation


x+1
sin x − = 0,
x−1
correct to five significant figures. (Hints. An approximate value of the root, based on
the graphs of y = sin x and y = x+1 x−1
, is known to be −0.4.)

6. Find the positive root of the equation

xx + 5x − 1000 = 0,

correct to four significant digits.

7. Consider the equation


x5 − 3x4 + 2x3 − x2 + x = 3.

(a) Solve the equation using the Bisection method.


(b) Solve the equation using the Newton–Raphson method.

Also, determine how many real solutions the equation has.

8. Solve the equation


x = cos x
using the Bisection method and the Newton–Raphson method. Also, determine
how many real solutions the equation has.

Next, solve the equation


sin x = cos x
using the Bisection method and the Newton–Raphson method. Again, deter-
mine how many real solutions the equation has.

9. Consider the linear system:


x + 31 y = 1.33,
3x + y = 4.

Find the solutions assuming the following approximations of 31 :


1
3
= 0.3, 0.33, 0.333, 0.3333.

2
For each approximation, compute the condition number
λmax
κ= ,
λmin
where λ denotes the eigenvalues of the matrix
 1
1 3
.
3 1

10. Consider the matrix  


1 112
1
 222 
A = 1
 332 .
 .. .... 
. . . 
1 T T2

a) Find the inverse of D = A′ A, when T = 5.


b) Find the eigenvalues of D for T = 50, 100, 200.
c) Find the determinant of D for T = 50, 100, 200.
λmax
d) Compute the condition number κ = for T = 50, 100, 200, where λ denotes
λmin
the eigenvalues of D.

11. Write a C program to numerically approximate the first derivative of the function

f (x) = e−x · sin(x2 ) + ln(1 + x2 )

at a given value of x, using the central difference formula:


f (x + h) − f (x − h)
f ′ (x) ≈ ,
2h
where h = 0.001.
Evaluate the numerical derivative for different values of h to examine the effect of step
size on accuracy. Use:
h = 10−2 , 10−4 , 10−6
Compare the outputs and comment on the numerical stability and convergence of the
derivative approximation.
Hints:

a) Define the function f (x) in C using the math library.


b) Prompt the user to enter a value of x.
c) Approximate the first derivative f ′ (x) using the central difference method.
d) Display the result with at least 6 decimal places of precision.

3
12. Consider the system of linear equations:
2x + 3y − z = 5,
4x + y + 2z = 9,
−6x − 2y + 3z = −17.

Write a C program that performs the following tasks:


a) Represent the system in matrix form AX = B, where:
   
2 3 −1 5
A= 4 1 2 , B =  9 .
−6 −2 3 −17
 
x
b) Solve for the vector X = y  using:

z
• Gaussian elimination,
• Matrix inversion (i.e., compute X = A−1 B if A−1 exists).
c) Output the values of x, y, and z correct to at least four decimal places.
13. Given the OLS estimator β̂ = (X ′ X)−1 X ′ Y and estimated residual variance:
1
σ̂ 2 = (Y − X β̂)′ (Y − X β̂),
n−k
write a C program to compute β̂ and the variance-covariance matrix:
Var(β̂) = σ̂ 2 (X ′ X)−1 .
where    
1 4 2.2
1 5 2.8
X=
1
, Y =
3.6 ,

6
1 7 4.5
14. Consider a logistic model:
1
P (y = 1|x) =
1+ e−(β0 +β1 x)
Given a small dataset of binary outcomes and a single predictor, write a C program
that:
a) Initializes β0 , β1 to 0.
b) Iteratively updates the parameters using the Newton–Raphson algorithm:
−1
β (t+1) = β (t) − H(β (t) ) ∇ℓ(β (t) ),


where ∇ℓ is the gradient and H is the Hessian.

4
c) Stops when the change in parameters is below a tolerance level (e.g., 10−6 ).

15. Suppose you are given the following dataset, which represents the number of customer
service calls received per minute over a 30-minute period:

Data: 1, 2, 2, 1, 3, 2, 0, 4, 1, 3, 2, 1, 2, 3, 1, 0, 1, 2, 4, 3, 2, 3, 2, 1, 0, 1, 2, 2, 3, 1

a) Store the data in an array in C.


b) Count the frequency of each unique value of the random variable X (i.e., number
of calls per minute).
c) Estimate the empirical PMF using the formula:

frequency of xi
P̂ (X = xi ) = .
30

d) Display a table showing each unique value xi and its estimated probability P̂ (X =
xi ) with at least 4 decimal places.
e) Plot the PMF as a text-based histogram.
f) Compute the empirical mean and variance:
X X
x̄ = xi P̂ (X = xi ), Var(X) = (xi − x̄)2 P̂ (X = xi ).

References
1. S. D. Conte and C. de Boor: Elementary Numerical Analysis: An Algorithmic Ap-
proach

2. D. K. Faddeev and V. H. Faddeeva: Computational Methods in Linear Algebra.

3. G. E. Forsythe and G. B. Moler: Computer Solution of Linear Algebraic Systems.

4. W. H. Press, S. A. Teukolsky, W. T. Vetterling, B. P. Flannery: Numerical Recipes in


C.

You might also like