Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;.
- ;;Autor: Carlos A Delgado
- ;;Fecha: 01 de Feb de 2021
- ;;Contrato: funcion: numero,numero -> numero
- ;;Descripción: Esta función implementa una función a trozos
- ;;Ejemplos
- ;; x = 0 y = 0 8
- ;; x = 4 y = 0 16
- ;; x = -7 y = 0 #i1.150163316895603+1.150163316895603i
- ;; x = 0 y = -4 4
- ;; x = 0 y = 8 0
- (define (funcion x y)
- (cond
- [(not (and (number? x) (number? y))) (error "los argumentos deben ser números")]
- [(and (= x 0) (= y 0)) 8]
- [(and (> x 0) (= y 0)) (+ (sqr x) (* 2 y))]
- [(and (< x 0) (= y 0)) (+ (sqr y) (expt x 1/4))]
- [(and (= x 0) (< y 0)) (sqrt (+ (sqr x) (sqr y)))]
- [else (expt (/ (sqr x) (+ (sqr x) (sqr y) )) 1/3)]
- ))
- (check-expect (funcion 0 0) 8)
- (check-expect (funcion 4 0) 16)
- (check-within (funcion -7 0) 1.15+1.15i 0.01)
- (check-expect (funcion 0 -4) 4)
- (check-expect (funcion 0 8) 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement