Practice 2.37
This spent maths me for too long, and at first I looked at m in the title as W. Then the two parameters of the dot-product given in the question I think one is the vector and the other is the matrix. It's not going to work out until you see the "Return sum ..." in which W has only one I and no J. Well, then start to do the problem according to the requirements of the topic.
Now that you've found your own mistakes, you know what dot-product is for, it can be used to find a column in a matrix and a product of a vector. So it is not difficult to define the Matrix-*-vector .
(Define (matrix-*-vector m v)
(The map (the Lambda (col)
(dot-product Col v))
m))
Let's use the data in the topic to test it.
(Matrix-*-vector ' ((1 2 3 4) (4 5 6 6) (6 7 8 9)))
; Value: (30 56 80)
Next we look at transpose, the reason why put Matrix-*-matrix in the last is because its definition needs transpose.
(Define (Transpose mat)
(Accumulate-n cons ' () mat))
It looks like this line of code, but its functionality is powerful.
(Transpose ' ((1 2 3 4) (4 5 6 6) (6 7 89))
; Value: ((1 4 6) (2 5 7) (3 6 8) (4 69))
If there are any accumulate changes here, you can go back and look at the answer to the practice 2.33 . and Accumulate-n is just a accumulate shell, in the transformation of Accumulate-n will slowly become accumulate.
In linear algebra we have learned that the value of the first row of the first column of the product of MN of the two matrix is equal to the dot product of the first column of M and the first row of N , and the value of the second row of the first column ofmn equals the first column of M and The dot product of the second line of n ...
(Define (matrix-*-matrix m N)
(Let (cols (transpose N)))
(Map (Lambda (col-of-m)
(matrix-*-vector colscol-of-m))
m)))
"SICP Exercise" 66 Exercise 2.37