CSE 251 PROJECT 1

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (7 votes)

1 Project Description
You are to write a program that requests values of a and b (as doubles) and computes a numerical estimate of the integral equation in
Equation (1):
Z b
a
sin(πx)
πx
dx (1)
The function we are computing the integral over is the normalized sinc
function listed in Equation (2):
f(x) = sin(πx)
πx
(2)
See the page on Wikipedia for more details on this function. It is an
important function in signal processing.
1
You will compute an estimate of the integral using the rectangle
method presented in Equation (3):
I =
Z b
a
f(x)dx ∼
Xn
i=1
f(a + (i −
1
2
)∆)∆ (3)
where
∆ = b − a
n
. (4)
For a better approximation, you can also see the Trapezoidal Method
from Wikipedia page for more details.
The above method works by breaking the interval into n equal size
regions of width ∆ and estimating the integral over the region as a
rectangle where the value of the function at the midpoint of the region
is the height and ∆ is the width of the region. This is, of course, a
numerical approximation. As n grows larger, the approximation gets
better and the result approaches the exact value of the integral as
n → ∞.
If I compute the estimate with n = 12, I will get a slightly better
estimate than if I used n = 11. Your program should compute the
result for every value starting at 10 and increasing by 1 until a stopping
condition is met. There are two possible stopping conditions:
1. Stop when n reaches 100, 000.
2. Stop when the decrease in error becomes less than 1 × 10−10
.
You can represent 1 × 10−10 in a C program as 1e-10.
Stop when either condition is reached.
The sinc function has a removable singularity at x = 0 where it is
understood that the value is the limit value of 1. So, in your program,
assume:
f(0) = limx→0
sin(πx)
πx
= 1 (5)
This is important! Otherwise your program may fail due to a divide
by zero.
If the user enters values such that a b, present an appropriate error
message and ask the user to enter both values again. All counters
should be implemented using integer variables (the int type). Do all
math other than counters using double precision floating point (the
double type).
2
2 Example
Suppose I enter the values: a = −1 and b = 1. The program begins
with n = 10, which means:
∆ = 1 − −1
n
= 0.2 . (6)
It then computes the value of:
I =
Xn
i=1
f(a + (i −
1
2
)∆)∆ (7)
my example program computed a value of 1.182328209. It then computed the same equation with n = 11. This gave a value of 1.181744890.
The decrease in the error from the first computation to the second is
1.181744890 − 1.182328209 = 5.833186 × 10−4
. Next, it tries n = 12,
which decreases the error by 4.430462 × 10−4
. The following is the
output of my example program for the first 12 values computed:
Enter a value for a: -1
Enter a value for b: 1
Integral evaluation
10: 1.182328209
11: 1.181744890 5.833186e-004
12: 1.181301844 4.430462e-004
13: 1.180957417 3.444270e-004
14: 1.180684353 2.730641e-004
15: 1.180464206 2.201472e-004
16: 1.180284129 1.800768e-004
17: 1.180134952 1.491767e-004
18: 1.180009987 1.249652e-004
19: 1.179904262 1.057250e-004
20: 1.179814020 9.024236e-005
21: 1.179736377 7.764251e-005
I highly recommend that you output the values as they are computed. It will make it easier to tell if the program is working. I
also outputted the decrease in error from the previous iteration. The
change in the error continues to decrease as the approximation approaches the result. Eventually, when n = 1883 in this example, the
decrease in the error goes below 1 × 10−10 and we are done:
1874: 1.178979839 1.013800e-010
3
1875: 1.178979839 1.012121e-010
1876: 1.178979839 1.010594e-010
1877: 1.178979839 1.008906e-010
1878: 1.178979839 1.007312e-010
1879: 1.178979839 1.005740e-010
1880: 1.178979839 1.004128e-010
1881: 1.178979839 1.002500e-010
1882: 1.178979839 1.000922e-010
1883: 1.178979838 9.992607e-011
The integral result is 1.178979838
3 Details
In your program source code, include the following comment block
before the main function in your program, filling in your name and
the n and estimates for the given a, b values.
/*
∗ CSE 251 Project 1
∗ By: ¡your name here¿

∗ Complete the following table:

∗ a b n estimate
∗ −1 1 1883 1.178979838
∗ 0 10
∗ −1000 1000
∗ 10 15
∗ 0.1 0.2
∗ /
Name your program proj1.c and turn in on the Handin system.
4 Grading Criteria
The project will be graded as follows:
• Up to ten points will be deducted for badly formatted/documented
code
• Ten points will be deducted for each incorrect answer computed
4
for the above a and b values (Watch out for a = ?1000 and b
= 1000 – this one is very easy to get wrong. Be sure to think
about the answer you get, and whether or not it makes sense
mathematically).
• Up to 30 points will be deducted for logic errors in code.
5