{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hand2ex1

# hand2ex1 - i = N X i =1-1 i 1 i x-1 i write a code that...

This preview shows page 1. Sign up to view the full content.

Extra Exercises Handout Two October 5, 2011 Question One Write a fortran code to compute the sum of the squares of the first n integers.Use a single ‘ DO ’ loop to do this along with a ‘ REAL ’ data type to hold the summation. Note that you can read in a value from the keyboard, during the execution of a fortran program, with the ‘ READ ’ command as follows. Given you have declared ‘ num1 ’ to be and ‘ INTEGER ’ type in the specification part of your code. You can read an integer value into ‘ num1 ’ using READ*,num1 Question Two The Taylor Polynomial P N ( x ) for f ( x ) = ln( x ) expanded about x 0 = 1 is, P N ( x ) =
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: i = N X i =1 (-1) i +1 i ( x-1) i write a code that prints out the value of P N ( x ) for N ∈ { 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 } . Use a pair of nested ‘ DO ’ loops for this purpose. In your code also print out the error in the approximation. Note to do this you can use the Fortran function ‘ ALOG(num) ’ which returns the natural log of the value ‘ num ’. For example if you stored the result of the approximation P N ( num ) in the ‘ REAL ’ variable ‘ tot ’ then PRINT*,ALOG(num)-tot would give you a measure of the error. 1...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online