Docsity

MA-334 Computer Programming Exam 3: Binomial Series and Matrix Permutations, Exams of Mathematics

Toggle sidebar
bg1
MA-334 Computer Programming - Exam 3
April 30, 2009
Please be sure to show all work. No credit can be given if your answers are not substantiated.
1. The Binomial Series is a series that allows us to represent (1 + x)kas an in…nite series for any real
number kif jxj<1. For k=1
2the sum simpli…es to the following formula:
(1 + x)1=2= 1 1
2x+13
24x2135
246x3+ + (1)k135 (2k1)
246 (2k)xk+
Write a Python function invRoot(xvl,nmax) to compute and return the sum for an input xvl up to
term nmax.
2. Run the accompanying Python program. Please keep track of every variable and all output in the
program, and be sure to express numbers like they would be on a computer and to show relevant work.
3. In the program from #2, the variable nordr is determined from the speci…c list coef, and the number
of iterations of the loop with variable kntr is speci…cally linked to the list eksz. With this it mind,
modify the program in #2 to:
Write an appropriate introductory statement for the user.
Contain appropriate comment statements.
Set the variable nordr automatically based on the length of the list coef (so that if a di¤erent coef is
declared, nordr will be automatically set accordingly).
Make the loop with variable kntr work for any length of the list of x-values (the list eksz).
4. A permutation is a rearrangement of a list (e.g., [1,2,3,4,5] is a permutation of [1,3,2,5,4]). In
linear algebra, permutations are very important, but we are often only interested in swapping two rows.
Write a Python program to rows of an mby nmatrix A. The data may be declared in the program
rather than input with an input statement, but the program should be designed to work with any size
matrix (using the len() function). For example, if A=2
4
1 5
09
3 8
3
5and the rows to swap are 2 and
3, then the output should be something like
Swapping rows 2 and 3 of the matrix A gives PA=[[1,5],[3,8],[0,-9]].
5. In class we derived Euler’s Method for …nding approximate values of the solution yof the initial value
problem
dy
dt =f(t; y); y (t0) = y0:
There are several other methods that are more sophisticated and give better results on average. One
such method is the Midpoint Method:
yi+1 =yi+hfti+h
2; yi+h
2f(ti; yi)
where yi+1 y(ti+1)and ti+1 =ti+h. Use this method to approximate y(3) for the initial value
problem
y0= 1 + (ty)2; y (2) = 1
with h= 0:5.
1

Partial preview of the text

Download MA-334 Computer Programming Exam 3: Binomial Series and Matrix Permutations and more Exams Mathematics in PDF only on Docsity!

MA-334 Computer Programming - Exam 3

April 30, 2009 Please be sure to show all work. No credit can be given if your answers are not substantiated.

  1. The Binomial Series is a series that allows us to represent (1 + x)k^ as an inÖnite series for any real

number k if jxj < 1. For k =

the sum simpliÖes to the following formula:

(1 + x)^1 =^2 = 1

x +

x^2

x^3 +    + (1)k^

1  3  5      (2k 1) 2  4  6      (2k)

xk^ +   

Write a Python function invRoot(xvl,nmax) to compute and return the sum for an input xvl up to term nmax.

  1. Run the accompanying Python program. Please keep track of every variable and all output in the program, and be sure to express numbers like they would be on a computer and to show relevant work.
  2. In the program from #2, the variable nordr is determined from the speciÖc list coef, and the number of iterations of the loop with variable kntr is speciÖcally linked to the list eksz. With this it mind, modify the program in #2 to:

 Write an appropriate introductory statement for the user.

 Contain appropriate comment statements.

 Set the variable nordr automatically based on the length of the list coef (so that if a di§erent coef is declared, nordr will be automatically set accordingly).

 Make the loop with variable kntr work for any length of the list of x-values (the list eksz).

  1. A permutation is a rearrangement of a list (e.g., [1,2,3,4,5] is a permutation of [1,3,2,5,4]). In linear algebra, permutations are very important, but we are often only interested in swapping two rows. Write a Python program to rows of an m by n matrix A. The data may be declared in the program rather than input with an input statement, but the program should be designed to work with any size

matrix (using the len() function). For example, if A =

(^5) and the rows to swap are 2 and

3, then the output should be something like Swapping rows 2 and 3 of the matrix A gives PA=[[1,5],[3,8],[0,-9]].

  1. In class we derived Eulerís Method for Önding approximate values of the solution y of the initial value problem dy dt

= f (t; y) ; y (t 0 ) = y 0 :

There are several other methods that are more sophisticated and give better results on average. One such method is the Midpoint Method:

yi+1 = yi + h

f

ti +

h 2

; yi +

h 2

f (ti; yi)

where yi+1  y (ti+1) and ti+1 = ti + h. Use this method to approximate y (3) for the initial value problem y^0 = 1 + (t y)^2 ; y (2) = 1 with h = 0: 5.