I have a series of mathematical operations that I need to perform. The input to the function is n.
the first two operations are amounts. using n. The result should be stored as a variable that will be used in subsequent functions.
ex.
main func(n)
func1 (n)
returns a1
func2 (n)
returns b1
func4
uses b1 to compute c1
etc....
I created all the sepearted functions, but you need to use the main function, which simply takes n, and a way to store variables globally for use in subsequent functions (without changing them). these are the first 2 functions.
(define (main n)
(define (a1func n)
(let* ((a1 0))
(let* ((i (- n 1)))
(if (= n 1) 0
(+(/ 1 i) (a1func(- n 1)))))))
(define (a2func n)
(let ((a2 0))
(let ((i (- n 1)))
(if (= n 1) 0
(+(/ 1 (expt i 2)) (a2func(- n 1)))))))
(define b1
(if (= n 1) 0
(/(+ n 1)(* 3(- n 1)))))
(define b2
(if (= n 1) 0
(/(* 2 (+ n 3 (expt n 2))) (*(- n 1)(* 9 n)))))
(define c1 (- b1 (/ 1 a1)))
(define c2 (+ (- b2 (/ (+ n 2) (* a1 n))) (/ a2 (expt a1 2))))
(define e1 (/ c1 a1))
(define e2 (/ c2 (+ (expt a1 2) a2)))
(list e1 e2))
source
share