-2

This is my first asked question here, so I will do my best to make you understand my need. I'm trying to do a function which should resolve any polynomial equation in scheme language, but I am a beginner so I can't do it properly... I've tried to detect all the unknow and make different function for the substraction, the multiply, the addition and the division but I am stuck at this. I can't make a function who while said the nature of the calcul... So please, help me guys please.

Sorry forgot to write it :

(define (addition? L1)
  (if (memq '+' L1))
      #T
      (else (error))
      )

(define (count L1 x n)
  (cond [(null? L1) n]
        [(eq? (car L1) x)
         (count (cdr L1) x (+ n 1))]
        [else
         (count (cdr L1) x n)]))

(define (polynome L1)
  (compter L1))

`

2 Answers2

3

You solve this as you would solve any problem:

  1. Make a data representation of your objects. Make accessors, constructors so that using the model is more precise.
  2. Use the knowledge on how to do the transformation manually by making an algorithm that does this using the data representation. Start with the simple cases and reuse those to make the more complex ones. Divide and conquer. Solving two simpler problems than one big is always better.
  3. Test to see if it works. If it doesn't refine or go to step 2.

To recap. you need to know how to solve polynomial equations in order to solve this. You'll need to know how to program in the target programming language. You need to know how to divide a complex problem into smaller simpler problems.

If you don't know Scheme I suggest you start do simpler problems first.

Sylwester
  • 47,942
  • 4
  • 47
  • 79
2

It isn't clear whether you are looking for a symbolic or a numeric approach. If you are looking for a symbolic approach, then perhaps you can find some inspiration in the source of racket-cas.

https://github.com/soegaard/racket-cas/blob/master/racket-cas/racket-cas.rkt

Note that if we are talking about polynomials of one real variable and the coeffecients are real, there is only a general solution formula if the degree is smaller than 5.

For general, numeric root finding see bracket:

https://github.com/soegaard/bracket/blob/master/numeric/root-finding.rkt

soegaard
  • 30,661
  • 4
  • 57
  • 106