-2

I need a procedure that returns the value of a cubic polynomial, ie :

f(x) = x3 + ax2 + bx + c

I should be able to do this with a procedure that takes three arguments and Newton-Raphson's method but I am at a loss on how.

(define f (cubic a b c) ...)

How can I do this?

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • 1
    Please note that "Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results." What have you tried so far? What didn't work about it? – Joshua Taylor Oct 10 '13 at 13:22
  • Newtown's method is useful for (but not guarnteed) to find roots of a function. Finding the value at any particular x is a different beast. – WorBlux Oct 10 '13 at 15:41
  • You have misunderstood either the problem or the solution. There's no point in trying to use Newton-Raphson to compute the *value* of a polynomial for a given input. – molbdnilo Oct 11 '13 at 12:12

1 Answers1

2

Well you want your function to return a function so

(define cubic
   (lambda (a b c) ;; lambda #1
      (lambda (x) ;; lambda #2
        ???))) ;; x^3 a * x^2 + b * x + c

This is called a closure, lambda 2 is returned when lambda 1 is called and can remember and access the parameters from lambda #1's call.

Then

(define f (cubic a b c))

defines f to be a function taking in x and plugging it into lambda #2's body.

daniel gratzer
  • 52,833
  • 11
  • 94
  • 134