Write an ML function cross which given two lists computes th

Write an ML function cross which, given two lists, computes the list of their cross-products.

Namely, given the inputs [1,2,3] and [4,5,6], it computes [(1,4), (1,5), (1,6), (2,4), (2,5), (2,6), (3,4), (3,5), (3,6)].

fun cross a b = ...

Solution

function res=cross(a,b)
res=0
for i=1:size(a)+1
for j=1:size(b)+1
res=res+(a(i)*b(j))
end
end
end
cross([1,2,3],[4,5,6])

Write an ML function cross which, given two lists, computes the list of their cross-products. Namely, given the inputs [1,2,3] and [4,5,6], it computes [(1,4),

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site