Advertisement
cardel

Ejemplo3FDP01Feb

Feb 1st, 2021
3,370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.85 KB | None | 0 0
  1. ;.
  2.  
  3. ;;Autor: Carlos A Delgado
  4. ;;Fecha: 01 de Feb de 2021
  5. ;;Contrato: funcion: numero,numero -> numero
  6. ;;Descripción: Esta función implementa una función a trozos
  7. ;;Ejemplos
  8. ;; x = 0 y = 0  8
  9. ;; x = 4 y = 0  16
  10. ;; x = -7 y = 0 #i1.150163316895603+1.150163316895603i
  11. ;; x = 0 y = -4   4
  12. ;; x = 0 y = 8  0
  13. (define (funcion x y)
  14.   (cond
  15.     [(not (and (number? x) (number? y))) (error "los argumentos deben ser números")]
  16.     [(and (= x 0) (= y 0)) 8]
  17.     [(and (> x 0) (= y 0)) (+ (sqr x)  (* 2 y))]
  18.     [(and (< x 0) (= y 0)) (+ (sqr y) (expt x 1/4))]
  19.     [(and (= x 0) (< y 0)) (sqrt (+ (sqr x) (sqr y)))]
  20.     [else (expt (/ (sqr x) (+ (sqr x) (sqr y) )) 1/3)]
  21.     ))
  22. (check-expect (funcion 0 0) 8)
  23. (check-expect (funcion 4 0) 16)
  24. (check-within (funcion -7 0) 1.15+1.15i 0.01)
  25. (check-expect (funcion 0 -4) 4)
  26. (check-expect (funcion 0 8) 0)
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement