【问题标题】:Scheme Lisp The determinant of a 3 × 3 matrixScheme Lisp 3 × 3 矩阵的行列式
【发布时间】:2019-02-02 18:40:55
【问题描述】:

我的代码不工作,它给了我一个错误提示:det: arity mismatch; 预期的参数数量与给定的数量不匹配 预期:4 给定:9 论据...:

这是我的代码:

(define (det3x3 a b c
                d e f
                g h i)
  (+ (* a ( * e i (* h f)))(* b (* d i (* g f)))(* c (* d h (* e g)))))
(display "(det 0 5 -6 8 -11 4 5 1 1) = ")(det 0 5 -6
                                              8 -11 4
                                              5 1 1)

【问题讨论】:

  • 我建议看看函数det

标签: scheme lisp racket


【解决方案1】:

行列式 = a(ei - fh) - b(di - fg) + c(dh - eg)

(define (det3x3 a b c
                d e f
                g h i)
  (+ (- (* a (- (* e i) (* f h)))
        (* b (- (* d i) (* f g))))
        (* c (- (* d h) (* e g)))))

e,g:

> (det3x3 0 5 -6
          8 -11 4
          5 1 1)
-318 

【讨论】:

    【解决方案2】:

    您在调用display 的行中调用函数det。将此更改为det3x3det 必须定义为 4 元函数。我不确定您使用的是什么版本的 Scheme;那一定是别的东西。

    【讨论】:

    • 我正在使用 DrRacket
    猜你喜欢
    • 1970-01-01
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多