Fast computation of an equation.
Show older comments
Given two matrices:


We want a the fastest way to compute the vector \phi.... (j=1 to m).
Is there a way to use parallel computation, any trick?
8 Comments
darova
on 9 Sep 2019
What does it mean
?
Walter Roberson
on 9 Sep 2019
As
then
is a vector and
would be the ith element of vector 
If you arrange Y and Z as 2D array
so that varying i in
is traveling along rows, then from R2019a onwards,
sum((x-Y).*(Z-x), 2)
Bruno Luong
on 9 Sep 2019
+1 on Walter's solution. You probably want to write
"then from R2016b onwards".
I probably organize data in transpose way, but this does not have huge impact.
Not sure if the computation is to do once or multiple times with Y/Z fix or x fix.
David Ernesto Caro
on 9 Sep 2019
Edited: David Ernesto Caro
on 9 Sep 2019
Walter Roberson
on 9 Sep 2019
Bruno is right, I should have said R2016b onwards.
Walter Roberson
on 9 Sep 2019
I see that you extended by a dimension. The code remains the same provided that you arrange the
so that the k run along the third dimension, so
being MATLAB's x(1,i,k) . The result would be m (length of j) by 1 by s (length of k), which you might want to squeeze() to a 2D array.
David Ernesto Caro
on 9 Sep 2019
Bruno Luong
on 10 Sep 2019
Edited: Bruno Luong
on 10 Sep 2019
what are typically m,n and s?
If you have X as matrix the best method might be different, see my answer bellow.
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!