"SICP Exercise" 66 Exercise 2.37

Source: Internet
Author: User



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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.