SHARE
TWEET

Scheme Vieta

a guest Dec 25th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Progam based on Vieta theorem. It find quadrial equation roots.
  2.  
  3. ; equal operation for two real-is numbers
  4. ;  is same as checking guess = x
  5.  
  6. (define (real-is-equal? guess x)
  7.      (< (abs (- (guess x)) 0.001))
  8. )
  9.  
  10. ; check x1 and x2 for:
  11. ;  1) x1 + x2 = -p
  12. ;  2) x1 * x2 = q
  13. (define (is-equation-roots? x1 x2 p q)
  14.     (and
  15.         (real-is-equal? (+ x1 x2) (- p))
  16.         (real-is-equal? (* x1 x2) q)
  17.     )  
  18. )
  19.  
  20. (define (root-step x1 x2 dx1 dx2 p q)
  21.     (+ x1 x2)  
  22. )
  23.  
  24. (define (roots p q x-begin x-end)
  25.     (let ((x1 0.0) (x2 0.0))
  26.         (set! (x1 x-begin)) ; Error here
  27.         (set! (x2 x-begin)) ; and here
  28.         ; TODO: find loop here  
  29.     )  
  30. )
  31.  
  32. ; TODO: reading b and c from stdin
  33. ; (let ((p 0.0) (q 0.0) (x-begin 0.0) (x-end 0.0)))
  34.  
  35. (roots -2 2 0 0)
  36.  
  37.  
  38. Запуск:
  39. r2d2@r2d2:~/proj/scheme/2_local_var$ mit-scheme --load vieta.scm
  40. MIT/GNU Scheme running under GNU/Linux
  41. Type `^C' (control-C) followed by `H' to obtain information about interrupts.
  42.  
  43. Copyright (C) 2011 Massachusetts Institute of Technology
  44. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  45.  
  46. Image saved on Saturday December 3, 2016 at 9:44:07 AM
  47.   Release 9.1.1 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || Edwin 3.116
  48. ;Loading "vieta.scm"...
  49. ;Variable required in this context: (x1 x-b)
  50. ;To continue, call RESTART with an option number:
  51. ; (RESTART 1) => Return to read-eval-print level 1.
  52.  
  53. 2 error>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top