Question
Using language F# . Full and complete answer in order to get full credit please. Do not copy- paste from a diferent site. Thank you.
Using language F# . Full and complete answer in order to get full credit please. Do not copy- paste from a diferent site. Thank you.
1)Given vectors u = (u1, u2,..., un) and v = (v1, v2,..., vn), the inner product of u and v is defined to be u1*v1 + u2*v2 + ... + un*vn. Write a curried F# function inner that takes two vectors represented as int lists and returns their inner product:
> inner [1;2;3] [4;5;6];; val it : int = 32
(Assume that the two lists have the same length.)
2)Given an m-by-n matrix A and an n-by-p matrix B, the product of A and B is an m-by-p matrix whose entry in position (i,j) is the inner product of row iof A with column j of B. For example,
/ 0 1 \ / 1 2 3 \ * | 3 2 | = / 9 11 \ \ 4 5 6 / \ 1 2 / \ 21 26 /
Write an uncurried F# function to do matrix multiplication:
> multiply ([[1;2;3];[4;5;6]], [[0;1];[3;2];[1;2]]);; val it : int list list = [[9; 11]; [21; 26]]
Assume that the dimensions of the matrices are appropriate.
Hint: Use transpose (from Homework 2), inner, and List.map.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started