Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.83 KB | None | 0 0
  1. #|Problem Set 1
  2. Argent University Introduction to Computer Science
  3.  
  4. 1.  The sine of an angle (specified in radians) can be computed by making use of the approximation sin x ~= x if x is sufficiently small, and the trigonometric identity to reduce the size of the argument of sin. (For purposes of this exercise an angle is considered "sufficiently small" if its magnitude is not greater than 0.1 radians.) These ideas are incorporated in the following procedures:|#
  5.  
  6. (define (cube x) (* x x x))
  7. (define (p x) (- (* 3 x) (* 4 (cube x))))
  8. (define (sine angle)
  9.    (if (not (> (abs angle) 0.1))
  10.       angle
  11.        (p (sine (/ angle 3.0)))))
  12.  
  13. #|How many times is the procedure p applied in the evaluation of |#(sine 12.15)#|?
  14.  
  15. 2. Newton's method for cube roots is based on the fact that if y is an approximation to x^(1/3), a better approximation is
  16. (x/y^2 + 2y)/3.
  17. Use this formula to implement a cube-root procedure analogous to the square root procedure.
  18.  
  19. 3. Implement the function "add", which is equivalent to:|#
  20. #|(define (add x y) (+ x y))|#.
  21. The only arithmetic procedures you may use are "zero?", "add1", and "sub1" (which are predefined).
  22.  
  23. 4. Compute #|(fib 64)|# with your Fibonnaci procedure. (You may need to optimize it in order to not run out of memory.).
  24.  
  25. 5. A function f is defined by the rule that f(n) = n if n<3 and f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n>=3. Write a procedure to compute f(n).  (It should be able to compute at least f(32) in a reasonable amount of time.)
  26.  
  27. 6. Consider the procedure below:
  28. #|(define (expt b n)
  29.   (if (= n 0)
  30.       1
  31.       (* b (expt b (- n 1)))))|#
  32. .
  33. Assuming that multiplications take constant time, this procedure takes an amount of time proportional to n.
  34. Write an equivalent procedure that runs in sub-linear time.
  35.  
  36. Bonus: Why is this problem set labeled "Argent University"?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement