Can I somehow optimize this formula? I evaluate it many times and it takes much time…
w – 1xN double
phis – NxN double
x – Nx2 double
sum(w(ones([size(x, 1) 1]),:) .* phis, 2)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re taking the scalar product of each row of
phiswithw. You can do this easily using linear algebra.This matrix multiplication saves you calls to
sum,ones, andsize, which should make your code a lot faster. Furthermore, linear algebra operations are often very fast in Matlab, since that’s what the program is historically optimized for.