CPSC 244 Project 6: Integration and Root Finding - Prof. James F. Nystrom, Study Guides, Projects, Research of Computer Science

A computer science project for cpsc 244 students in spring 2009. The project involves completing programming tasks related to chapter 6 material, including integrating functions using the trapezoid rule and simpson's rule, and finding square and cube roots using newton's method.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/07/2009

koofers-user-p2h
koofers-user-p2h 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPSC 244 Project 6
Spring 2009
7 April 2009
Programming with Functions
ASSIGNED: 7 April 2009
DUE: 21 April 2009 (by the end of class.)
VALUE: 54 points
Overview: In this project you will complete programming problems related to Chapter 6
material. For ALL programs
Use double precision reals by using REAL(KIND=8) when declaring variables. Also, print
out all real variables with six digits of precision.
Test the input to ensure that the values are appropriate for the problem you are
solving. For example, for integration problems, you should at minimum require that
b > a. (Note: You may be required to check for other conditions given the specific
circumstances of the problem.)
Tasks:
1. (6 points each) The normal distribution is described by the function
1
σ2πe
1
2(xµ
σ)2
,
where σis the standard deviation, and µis the mean. If we set z= (xµ) and let
σ= 1 we get a function (which we will integrate)
y(z) = 1
2πe
1
2z2(1)
which when integrated from −∞ to should equal 1.
(a) Integrate Eqn. (1) using the trapezoid rule (as discussed in class). Use an internal
function to calculate needed values of y(z). Input values for a,b, and the number
of iterations n. Name this program Chap6_T1a.f90.
(b) Integrate the function y(x) = 1/x using the trapezoid rule. Use an internal func-
tion to calculate needed values of y(x). Input values for a,b, and the number of
iterations n. Also, compare your answer to the exact value of the integral (using
the intrinsic LOG(x) function). Name this program Chap6_T1b.f90.
1
pf2

Partial preview of the text

Download CPSC 244 Project 6: Integration and Root Finding - Prof. James F. Nystrom and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CPSC 244 Project 6

Spring 2009

7 April 2009

Programming with Functions

ASSIGNED: 7 April 2009 DUE: 21 April 2009 (by the end of class.) VALUE: 54 points

Overview: In this project you will complete programming problems related to Chapter 6 material. For ALL programs

  • Use double precision reals by using REAL(KIND=8) when declaring variables. Also, print out all real variables with six digits of precision.
  • Test the input to ensure that the values are appropriate for the problem you are solving. For example, for integration problems, you should at minimum require that b > a. (Note: You may be required to check for other conditions given the specific circumstances of the problem.)

Tasks:

  1. (6 points each) The normal distribution is described by the function

1 σ

2 π

e−^

1 2 ( x−μ σ )

2 ,

where σ is the standard deviation, and μ is the mean. If we set z = (x − μ)/σ and let σ = 1 we get a function (which we will integrate)

y(z) =

2 π

e−^

(^12) z 2 (1)

which when integrated from −∞ to ∞ should equal 1.

(a) Integrate Eqn. (1) using the trapezoid rule (as discussed in class). Use an internal function to calculate needed values of y(z). Input values for a, b, and the number of iterations n. Name this program Chap6_T1a.f90. (b) Integrate the function y(x) = 1/x using the trapezoid rule. Use an internal func- tion to calculate needed values of y(x). Input values for a, b, and the number of iterations n. Also, compare your answer to the exact value of the integral (using the intrinsic LOG(x) function). Name this program Chap6_T1b.f90.

  1. (6 points each) Simpson’s Rule is a more accurate integration technique than the trapezoid rule. (See, for example, the discussion in Problem 31 on p. 415 of the text). Here, we require than the number of intervals n be an even number, and with h = (b − a)/n, the formula is ∫ (^) b

a

f (x)dx ≃

h 3

[f (x 0 ) + 4f (x 1 ) + 2f (x 2 ) + 4f (x 3 ) + · · · + 2(xn− 1 ) + f (xn)].

(a) Integrate Eqn. (1) using the Simpson’s rule. Use an internal function to calculate needed values of y(z). Input values for a, b, and the number of iterations n. Name this program Chap6_T2a.f90. (b) Integrate the function y(x) = 1/x using the Simpson’s rule. Use an internal function to calculate needed values of y(x). Input values for a, b, and the number of iterations n. Also, compare your answer to the exact value of the integral (using the intrinsic LOG(x) function). Name this program Chap6_T2b.f90.

  1. (6 points each) Root finding techniques are often used to find various roots of real numbers. Here we use Newton’s Method to find square and cube roots. Determine each root to a tolerance of 1.E-7.

(a) Request that the user input a real number√ R and then use Newton’s Method to find R. Program the function F and the derivative F P rime as module subprograms and import them into your main program using a USE statement. Name this program Chap6_T3a.f90, and name the module SRoot. (b) Request that the user input a real number R and then use Newton’s Method to find √ (^3) R. Program the function F and the derivative F P rime as module subprograms

and import them into your main program using a USE statement. Name this program Chap6_T3b.f90, and name the module CRoot.

  1. (6 points) §6.1 Exercises # 12.
  2. (6 points each) §6.6 Exercises # 12, 13.

Submit the following:

  1. A stapled set of legible solutions which includes a printout of any programs. Your program should have some comments which - at minimum - includes your name, date the program was written, and the problem which is being solved.
  2. Place a copy of each program and module you write into a folder called CPSC Your Name. After all the programs have been placed in this folder, right-click on the folder and Send To a Compressed (zipped) folder. Then Email your zipped folder as an attachment to [email protected] with the Subject: Chap6 P6.